Source for file adodb-sqlite.inc.php
Documentation is available at adodb-sqlite.inc.php
V4.97 22 Jan 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Latest version is available at http://adodb.sourceforge.net
SQLite info: http://www.hwaci.com/sw/sqlite/
1. Place this in adodb/drivers
2. Rename the file, remove the .txt prefix.
var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
case 'sysDate': return "'".date($this->fmtDate)."'";
case 'sysTimeStamp' : return "'".date($this->sysTimeStamp)."'";
$arr['version'] = sqlite_libversion();
$arr['description'] = 'SQLite ';
$arr['encoding'] = sqlite_libencoding();
$ret = $this->Execute("BEGIN TRANSACTION");
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$rs = $this->Execute("PRAGMA table_info('$tab')");
$ADODB_FETCH_MODE = $save;
while ($r = $rs->FetchRow()) {
$size = trim($type[1],')');
$fld->max_length = $size;
$fld->not_null = $r['notnull'];
$fld->default_value = $r['dflt_value'];
$ADODB_FETCH_MODE = $save;
function _init($parentDriver)
$parentDriver->hasTransactions = false;
$parentDriver->hasInsertID = true;
$fmt = $this->qstr($fmt);
return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
@sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1);
@sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2);
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
if (empty($argHostname) && $argDatabasename) $argHostname = $argDatabasename;
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
if (empty($argHostname) && $argDatabasename) $argHostname = $argDatabasename;
// returns query ID if successful, otherwise false
function _query($sql,$inputarr= false)
function &SelectLimit($sql,$nrows=- 1,$offset=- 1,$inputarr= false,$secs2cache= 0)
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
$rs = & $this->CacheExecute($secs2cache,$sql. "$limitStr$offsetStr",$inputarr);
$rs = & $this->Execute($sql. "$limitStr$offsetStr",$inputarr);
This algorithm is not very efficient, but works even if table locking
Will return false if unable to generate an ID after $MAXLOOPS attempts.
function GenID($seq= 'adodbseq',$start= 1)
// if you have to modify the parameter below, your database is overloaded,
// or you need to implement generation of id's yourself!
@($num = $this->GetOne("select id from $seq"));
$ok = $this->Execute("insert into $seq values($start)");
$this->Execute("update $seq set id=id+1 where id=$num");
if ($this->affected_rows() > 0) {
$fn($this->databaseType,'GENID',- 32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
return $this->Execute("insert into $seqname values($start)");
function &MetaIndexes($table, $primary = FALSE, $owner= false)
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$SQL= sprintf("SELECT name,sql FROM sqlite_master WHERE type='index' AND tbl_name='%s'", strtolower($table));
$ADODB_FETCH_MODE = $save;
while ($row = $rs->FetchRow()) {
if ($primary && preg_match("/primary/i",$row[1]) == 0) continue;
if (!isset ($indexes[$row[0]])) {
$indexes[$row[0]] = array(
* There must be a more elegant way of doing this,
* the index elements appear in the SQL statement
* in cols[1] between parentheses
* e.g CREATE UNIQUE INDEX ware_0 ON warehouse (org,warehouse)
$indexes[$row[0]]['columns'] = $cols;
$ADODB_FETCH_MODE = $save;
/*--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------*/
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
default: $this->fetchMode = SQLITE_BOTH; break;
$this->adodbFetchMode = $mode;
$fld->name = sqlite_field_name($this->_queryID, $fieldOffset);
return sqlite_seek($this->_queryID, $row);
function _fetch($ignore_fields= false)
|