<?php
/*
-V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
+V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). 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://php.weblogs.com/
+ Latest version is available at http://adodb.sourceforge.net
SQLite info: http://www.hwaci.com/sw/sqlite/
2. Rename the file, remove the .txt prefix.
*/
+// security - hide paths
+if (!defined('ADODB_DIR')) die();
+
class ADODB_sqlite extends ADOConnection {
var $databaseType = "sqlite";
var $replaceQuote = "''"; // string to use to replace quotes
if ($this->transCnt>0)$this->transCnt -= 1;
return !empty($ret);
}
+
+ // mark newnham
+ function MetaColumns($table, $normalize=true)
+ {
+ global $ADODB_FETCH_MODE;
+ $false = false;
+ $save = $ADODB_FETCH_MODE;
+ $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
+ if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
+ $rs = $this->Execute("PRAGMA table_info('$table')");
+ if (isset($savem)) $this->SetFetchMode($savem);
+ if (!$rs) {
+ $ADODB_FETCH_MODE = $save;
+ return $false;
+ }
+ $arr = array();
+ while ($r = $rs->FetchRow()) {
+ $type = explode('(',$r['type']);
+ $size = '';
+ if (sizeof($type)==2)
+ $size = trim($type[1],')');
+ $fn = strtoupper($r['name']);
+ $fld = new ADOFieldObject;
+ $fld->name = $r['name'];
+ $fld->type = $type[0];
+ $fld->max_length = $size;
+ $fld->not_null = $r['notnull'];
+ $fld->default_value = $r['dflt_value'];
+ $fld->scale = 0;
+ if (isset($r['pk']) && $r['pk']) $fld->primary_key=1;
+ if ($save == ADODB_FETCH_NUM) $arr[] = $fld;
+ else $arr[strtoupper($fld->name)] = $fld;
+ }
+ $rs->Close();
+ $ADODB_FETCH_MODE = $save;
+ return $arr;
+ }
+
+ function _init($parentDriver)
+ {
+
+ $parentDriver->hasTransactions = false;
+ $parentDriver->hasInsertID = true;
+ }
function _insertid()
{
return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
}
- function &MetaColumns($tab)
- {
- global $ADODB_FETCH_MODE;
-
- $rs = $this->Execute("select * from $tab limit 1");
- if (!$rs) return false;
- $arr = array();
- for ($i=0,$max=$rs->_numOfFields; $i < $max; $i++) {
- $fld =& $rs->FetchField($i);
- if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] =& $fld;
- else $arr[strtoupper($fld->name)] =& $fld;
- }
- $rs->Close();
- return $arr;
- }
function _createFunctions()
{
// returns true or false
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
- if (!function_exists('sqlite_open')) return false;
+ if (!function_exists('sqlite_open')) return null;
+ if (empty($argHostname) && $argDatabasename) $argHostname = $argDatabasename;
- $this->_connectionID = sqlite_open($argDatabasename);
+ $this->_connectionID = sqlite_open($argHostname);
if ($this->_connectionID === false) return false;
$this->_createFunctions();
return true;
// returns true or false
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
{
- if (!function_exists('sqlite_popen')) return false;
+ if (!function_exists('sqlite_open')) return null;
+ if (empty($argHostname) && $argDatabasename) $argHostname = $argDatabasename;
- $this->_connectionID = sqlite_popen($argDatabasename);
+ $this->_connectionID = sqlite_popen($argHostname);
if ($this->_connectionID === false) return false;
$this->_createFunctions();
return true;
return $rez;
}
- function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
+ 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' : '');
if ($secs2cache)
- $rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
+ $rs = $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
else
- $rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
+ $rs = $this->Execute($sql."$limitStr$offsetStr",$inputarr);
return $rs;
}
$MAXLOOPS = 100;
//$this->debug=1;
while (--$MAXLOOPS>=0) {
- $num = $this->GetOne("select id from $seq");
+ @($num = $this->GetOne("select id from $seq"));
if ($num === false) {
$this->Execute(sprintf($this->_genSeqSQL ,$seq));
$start -= 1;
return @sqlite_close($this->_connectionID);
}
+ function MetaIndexes($table, $primary = FALSE, $owner=false, $owner = false)
+ {
+ $false = false;
+ // save old fetch mode
+ global $ADODB_FETCH_MODE;
+ $save = $ADODB_FETCH_MODE;
+ $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+ if ($this->fetchMode !== FALSE) {
+ $savem = $this->SetFetchMode(FALSE);
+ }
+ $SQL=sprintf("SELECT name,sql FROM sqlite_master WHERE type='index' AND tbl_name='%s'", strtolower($table));
+ $rs = $this->Execute($SQL);
+ if (!is_object($rs)) {
+ if (isset($savem))
+ $this->SetFetchMode($savem);
+ $ADODB_FETCH_MODE = $save;
+ return $false;
+ }
+
+ $indexes = array ();
+ while ($row = $rs->FetchRow()) {
+ if ($primary && preg_match("/primary/i",$row[1]) == 0) continue;
+ if (!isset($indexes[$row[0]])) {
+
+ $indexes[$row[0]] = array(
+ 'unique' => preg_match("/unique/i",$row[1]),
+ 'columns' => 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)
+ */
+ $cols = explode("(",$row[1]);
+ $cols = explode(")",$cols[1]);
+ array_pop($cols);
+ $indexes[$row[0]]['columns'] = $cols;
+ }
+ if (isset($savem)) {
+ $this->SetFetchMode($savem);
+ $ADODB_FETCH_MODE = $save;
+ }
+ return $indexes;
+ }
}
case ADODB_FETCH_ASSOC: $this->fetchMode = SQLITE_ASSOC; break;
default: $this->fetchMode = SQLITE_BOTH; break;
}
+ $this->adodbFetchMode = $mode;
$this->_queryID = $queryID;
}
- function &FetchField($fieldOffset = -1)
+ function FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
$fld->name = sqlite_field_name($this->_queryID, $fieldOffset);
}
}
+?>
\ No newline at end of file