Source for file EDB_SQLITE2.php
Documentation is available at EDB_SQLITE2.php
* Project: EDB_SQLITE2 :: SQLITE2 abstraction layer
* File: EDB/EDB_SQLITE2.php
* The EDB_SQLITE2 class is sqlite2 abstraction layer that used internally
* @subpackage EDB_ABSTRACT
* @author JoungKyun.Kim <http://oops.org>
* @copyright (c) 2018, JoungKyun.Kim
* @link http://pear.oops.org/package/EDB
* SQLite2 engine for EDB API
* This class support abstracttion DB layer for SQLite3 Engine
* db handler of EDB_SQLITE2 class
* The number of query parameter
// {{{ (object) EDB_SQLITE2::__construct ($path[, $mode = 0666])
* Instantiates an EDB_SQLITE2 object and opens an SQLite 3 database
* $db = new EDB_SQLITE2 ('sqlite2:///path/file.db');
* $db = new EDB_SQLITE2 ('sqlite2:///path/file.db', 0666)
* If you add prefix 'p~' before host, you can connect with persistent
* $db = new EDB_SQLTE2 ('sqlite2://p~/path/file.db');
* @param string $path sqlite2 database file
* @param integer $mode The mode of the file. Intended to be used to open
* the database in read-only mode. Presently, this
* parameter is ignored by the sqlite library. The
* default value for mode is the octal value 0666
* and this is the recommended value.
throw new myException ('sqlite extension is not loaded on PHP!', E_USER_ERROR);
$argv = is_array ($_argv[0]) ? $_argv[0] : $_argv;;
// for persistent connection
$this->db = $func ($o->path, $o->mode, $error);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_SQLITE2::get_charset (void)
* Get character set of current database
* This method is not allow on SQLite2 Engine
* @return string Current character set name
throw new myException ('Unsupported method on SQLITE2 engine', E_USER_ERROR);
// {{{ (bool) EDB_SQLITE2::set_charset ($charset)
* Set character set of current database
* This method is not allow on SQLite2 Engine, and always
* @return bool always returns true
* @param string $char name of character set that supported from database
// {{{ (string) EDB_SQLITE2::escape ($string)
* Escape special characters in a string for use in an SQL statement
* @param string The string that is to be escaped.
// {{{ (int) EDB_SQLITE2::query ($query, $param_type, $param1, $param2 ...)
* Performs a query on the database
* Executes an SQL query, returning number of affected rows
* @return integer The number of affected rows or false. If is not delete/insert/update
* query, always returns 0.
* @param string $query The query strings
* @param string $type (optional) Bind parameter type. See also
* {@link http://www.php.net/manual/en/sqlite3stmt.bindparam.php SQLite3Stmt::bindparam()}.
* i => integer SQLITE2_INTEGER
* d => double SQLITE2_FLOAT
* s => string SQLITE2_TEXT
* @param mixed $param1 (optional) Bind parameter 1
* @param mixed $param2,... (optional) Bind parameter 2 ..
$argv = is_array ($_argv[0]) ? $_argv[0] : $_argv;;
// store query in log variable
return $this->no_bind_query ($sql);
return $this->bind_query ($sql, $argv);
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (int) EDB_SQLITE2::lastId (void)
* 가장 마지막 입력 row ID를 반환한다.
// {{{ (bool) EDB_SQLITE2::seek ($offset)
* Adjusts the result pointer to an arbitrary row in the result
* @param integer Must be between zero and the total number of rows minus one
function seek ($offset) {
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (object) EDB_SQLITE2::fetch (void)
* Fetch a result row as an associative object
* @return object The object of fetched a result row or false
* @param boolean (optional) fetch 수행 후 result를 free한다.
* (기본값: false) EDB >= 2.0.3
function fetch ($free = false) {
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (array) EDB_SQLITE2::fetch_all ($free = true)
* Fetch all result rows as an associative object
* @return array The fetched result rows
* @param boolean (optional) free result set after fetch.
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (bool) EDB_SQLITE2::free_result (void)
* Frees stored result memory for the given statement handle
* @return boolean always returns true
if ( ! $this->free ) return true;
// {{{ (string) EDB_SQLITE2::field_name ($index)
* Get the name of the specified field in a result
* Given the ordinal column number, field_index, sqlite_field_name()
* returns the name of that field in the result set result.
* @param integer The numerical field offset. The index starts at 0.
* @see http://php.net/manual/en/function.sqlite-field-name.php sqlite_field_name()
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (string) EDB_SQLITE2::field_type ($index, $table)
* Get the type of the specified field in a result
* @param integer The numerical field offset. The index starts at 0.
* @param string name of table
* @see http://php.net/manual/en/function.sqlite-fetch-column-types.php sqlite_fetch_column_types()
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (int) EDB_SQLITE2::num_fields (void)
* Returns the number of fields in the result set.
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ (void) EDB_SQLITE2::trstart (void)
$this->db->query ('BEGIN TRANSACTION');
// {{{ (void) EDB_SQLITE2::trend ($v)
* @param bool false일경우 rollback을 수행한다.
function trend ($v = true) {
$sql = ($v === false) ? 'ROLLBACK' : 'COMMIT';
$this->db->query ($sql . ' TRANSACTION');
// {{{ (void) EDB_SQLITE2::close (void)
// {{{ private (int) EDB_SQLITE2::no_bind_query ($sql)
* Performs a query on the database
* @return integer The number of affected rows or false
* @param string The query strings
private function no_bind_query ($sql) {
} catch ( Exception $e ) {
throw new myException ($e->getMessage (), $e->getCode(), $e);
// {{{ private (int) EDB_SQLITE2::bind_query ($sql, $parameters)
* Performs a bind query on the database
* @return integer The number of affected rows or false
* @param string The query strings
* @param array (optional) Bind parameter type
private function bind_query ($sql, $params) {
if ( $this->pno != count ($params) || $this->check_param ($params) === false ) {
'Number of elements in query doesn\'t match number of bind variables',
$parano = strlen ($params[0]);
for ( $i= 0, $j= 1; $i< $parano; $i++ , $j++ ) {
switch ($params[0][$i]) {
$params[$j] = $params[$j]->data;
$params[$j] = $this->escape ($params[$j]);
return $this->no_bind_query ($query);
} catch ( Exception $e ) { }
* vim: set filetype=php noet sw=4 ts=4 fdm=marker:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
|