Add new directory structure. Tags will contain current and past releases, and stable will contain any bug fixes to the current stable release so users won't have to get the potentially broken trunk build to fix a screwup in stable.
Trunk updated to 0.9 git-svn-id: http://kusabax.cultnet.net/svn/repo/stable@176 73d99b7e-4f53-4972-b7b7-2ecd3c4d89ee
This commit is contained in:
commit
88bacfad9c
316 files changed
+79806
No files matched your search
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
V4.65 22 July 2005 (c) 2000-2005 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.
|
||||
|
||||
Set tabs to 4 for best viewing.
|
||||
|
||||
Modified 28 August, 2005 for use with ADOdb Lite by Mark Dickenson
|
||||
|
||||
*/
|
||||
|
||||
// security - hide paths
|
||||
if (!defined('ADODB_DIR')) die();
|
||||
|
||||
class ADODB2_sqlite extends ADODB_DataDict {
|
||||
|
||||
var $dbtype = 'sqlite';
|
||||
var $seqField = false;
|
||||
|
||||
var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
|
||||
|
||||
function ActualType($meta)
|
||||
{
|
||||
switch($meta) {
|
||||
case 'C': return 'VARCHAR';
|
||||
case 'XL':
|
||||
case 'X': return 'VARCHAR(250)';
|
||||
|
||||
case 'C2': return 'VARCHAR';
|
||||
case 'X2': return 'VARCHAR(250)';
|
||||
|
||||
case 'B': return 'VARCHAR';
|
||||
|
||||
case 'D': return 'DATE';
|
||||
case 'T': return 'DATE';
|
||||
|
||||
case 'L': return 'DECIMAL(1)';
|
||||
case 'I': return 'DECIMAL(10)';
|
||||
case 'I1': return 'DECIMAL(3)';
|
||||
case 'I2': return 'DECIMAL(5)';
|
||||
case 'I4': return 'DECIMAL(10)';
|
||||
case 'I8': return 'DECIMAL(20)';
|
||||
|
||||
case 'F': return 'DECIMAL(32,8)';
|
||||
case 'N': return 'DECIMAL';
|
||||
default:
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
|
||||
function AlterColumnSQL($tabname, $flds)
|
||||
{
|
||||
if ($this->debug) $this->outp("AlterColumnSQL not supported");
|
||||
return array();
|
||||
}
|
||||
|
||||
function DropColumnSQL($tabname, $flds)
|
||||
{
|
||||
if ($this->debug) $this->outp("DropColumnSQL not supported");
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* ADOdb Lite Date Module for SQLite
|
||||
*
|
||||
*/
|
||||
|
||||
if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);
|
||||
|
||||
@include(ADODB_DIR . '/adodb-time.inc.php');
|
||||
|
||||
eval('class sqlite_date_EXTENDER extends '. $last_module . '_ADOConnection { }');
|
||||
|
||||
class sqlite_date_ADOConnection extends sqlite_date_EXTENDER
|
||||
{
|
||||
var $fmtDate = "'Y-m-d'"; /// used by DBDate() as the default date format used by the database
|
||||
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||
var $emptyDate = ' ';
|
||||
var $emptyTimeStamp = ' ';
|
||||
var $sysDate = "adodb_date('Y-m-d')";
|
||||
var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')";
|
||||
var $isoDates = false; /// accepts dates in ISO format
|
||||
|
||||
function Time()
|
||||
{
|
||||
$rs =& $this->_Execute("select $this->sysTimeStamp");
|
||||
if ($rs && !$rs->EOF)
|
||||
return $this->UnixTimeStamp(reset($rs->fields));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function OffsetDate($dayFraction, $date=false)
|
||||
{
|
||||
if (!$date)
|
||||
$date = $this->sysDate;
|
||||
|
||||
return '('.$date.'+'.$dayFraction.')';
|
||||
}
|
||||
|
||||
function SetDateLocale($locale = 'En')
|
||||
{
|
||||
$this->locale = $locale;
|
||||
switch (strtoupper($locale))
|
||||
{
|
||||
case 'EN':
|
||||
$this->fmtDate="'Y-m-d'";
|
||||
$this->fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||
break;
|
||||
|
||||
case 'US':
|
||||
$this->fmtDate = "'m-d-Y'";
|
||||
$this->fmtTimeStamp = "'m-d-Y H:i:s'";
|
||||
break;
|
||||
|
||||
case 'NL':
|
||||
case 'FR':
|
||||
case 'RO':
|
||||
case 'IT':
|
||||
$this->fmtDate="'d-m-Y'";
|
||||
$this->fmtTimeStamp = "'d-m-Y H:i:s'";
|
||||
break;
|
||||
|
||||
case 'GE':
|
||||
$this->fmtDate="'d.m.Y'";
|
||||
$this->fmtTimeStamp = "'d.m.Y H:i:s'";
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->fmtDate="'Y-m-d'";
|
||||
$this->fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function DBDate($date)
|
||||
{
|
||||
if (empty($date) && $date !== 0)
|
||||
return 'null';
|
||||
|
||||
if (is_string($date) && !is_numeric($date)) {
|
||||
if ($date === 'null' || strncmp($date, "'", 1) === 0)
|
||||
return $date;
|
||||
|
||||
if ($this->isoDates)
|
||||
return "'$date'";
|
||||
|
||||
$date = $this->UnixDate($date);
|
||||
}
|
||||
|
||||
return adodb_date($this->fmtDate,$date);
|
||||
}
|
||||
|
||||
function DBTimeStamp($timestamp)
|
||||
{
|
||||
if (empty($timestamp) && $timestamp !== 0)
|
||||
return 'null';
|
||||
|
||||
# strlen(14) allows YYYYMMDDHHMMSS format
|
||||
if (!is_string($timestamp) || (is_numeric($timestamp) && strlen($timestamp)<14))
|
||||
return adodb_date($this->fmtTimeStamp, $timestamp);
|
||||
|
||||
if ($timestamp === 'null')
|
||||
return $timestamp;
|
||||
|
||||
if ($this->isoDates && strlen($timestamp) !== 14)
|
||||
return "'$timestamp'";
|
||||
|
||||
$timestamp = $this->UnixTimeStamp($timestamp);
|
||||
return adodb_date($this->fmtTimeStamp, $timestamp);
|
||||
}
|
||||
|
||||
function UnixDate($v)
|
||||
{
|
||||
if (is_object($v)) {
|
||||
// odbtp support
|
||||
//( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
|
||||
return adodb_mktime($v->hour, $v->minute, $v->second, $v->month, $v->day, $v->year);
|
||||
}
|
||||
|
||||
if (is_numeric($v) && strlen($v) !== 8)
|
||||
return $v;
|
||||
|
||||
if (!preg_match( "|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})|", ($v), $rr))
|
||||
return false;
|
||||
|
||||
if ($rr[1] <= TIMESTAMP_FIRST_YEAR)
|
||||
return 0;
|
||||
|
||||
// h-m-s-MM-DD-YY
|
||||
return adodb_mktime(0, 0, 0, $rr[2], $rr[3], $rr[1]);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
if (is_object($v)) {
|
||||
// odbtp support
|
||||
//( [year] => 2004 [month] => 9 [day] => 4 [hour] => 12 [minute] => 44 [second] => 8 [fraction] => 0 )
|
||||
return adodb_mktime($v->hour, $v->minute, $v->second, $v->month, $v->day, $v->year);
|
||||
}
|
||||
|
||||
if (!preg_match("|^([0-9]{4})[-/\.]?([0-9]{1,2})[-/\.]?([0-9]{1,2})[ ,-]*(([0-9]{1,2}):?([0-9]{1,2}):?([0-9\.]{1,4}))?|", ($v), $rr))
|
||||
return false;
|
||||
|
||||
if ($rr[1] <= TIMESTAMP_FIRST_YEAR && $rr[2]<= 1)
|
||||
return 0;
|
||||
|
||||
// h-m-s-MM-DD-YY
|
||||
if (!isset($rr[5]))
|
||||
return adodb_mktime(0, 0, 0, $rr[2], $rr[3], $rr[1]);
|
||||
else return adodb_mktime($rr[5], $rr[6], $rr[7], $rr[2], $rr[3], $rr[1]);
|
||||
}
|
||||
|
||||
function UserDate($v, $fmt='Y-m-d', $gmt=false)
|
||||
{
|
||||
$tt = $this->UnixDate($v);
|
||||
|
||||
// $tt == -1 if pre TIMESTAMP_FIRST_YEAR
|
||||
if (($tt === false || $tt == -1) && $v != false)
|
||||
return $v;
|
||||
else if ($tt == 0)
|
||||
return $this->emptyDate;
|
||||
else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
|
||||
}
|
||||
|
||||
return ($gmt) ? adodb_gmdate($fmt, $tt) : adodb_date($fmt, $tt);
|
||||
}
|
||||
|
||||
function UserTimeStamp($v, $fmt='Y-m-d H:i:s', $gmt=false)
|
||||
{
|
||||
if (!isset($v))
|
||||
return $this->emptyTimeStamp;
|
||||
|
||||
# strlen(14) allows YYYYMMDDHHMMSS format
|
||||
if (is_numeric($v) && strlen($v)<14)
|
||||
return ($gmt) ? adodb_gmdate($fmt,$v) : adodb_date($fmt,$v);
|
||||
|
||||
$tt = $this->UnixTimeStamp($v);
|
||||
// $tt == -1 if pre TIMESTAMP_FIRST_YEAR
|
||||
if (($tt === false || $tt == -1) && $v != false)
|
||||
return $v;
|
||||
|
||||
if ($tt == 0)
|
||||
return $this->emptyTimeStamp;
|
||||
else return ($gmt) ? adodb_gmdate($fmt,$tt) : adodb_date($fmt,$tt);
|
||||
}
|
||||
|
||||
function SQLDate($fmt, $col=false)
|
||||
{
|
||||
$fmt = $this->qstr($fmt);
|
||||
return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
|
||||
}
|
||||
}
|
||||
|
||||
eval('class sqlite_date_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
|
||||
|
||||
class sqlite_date_ResultSet extends sqlite_date_resultset_EXTENDER
|
||||
{
|
||||
var $emptyTimeStamp = ' '; /// what to display when $time==0
|
||||
var $emptyDate = ' '; /// what to display when $time==0
|
||||
var $datetime = false;
|
||||
|
||||
function UserTimeStamp($v, $fmt='Y-m-d H:i:s')
|
||||
{
|
||||
if (is_numeric($v) && strlen($v)<14)
|
||||
return adodb_date($fmt,$v);
|
||||
|
||||
$tt = $this->UnixTimeStamp($v);
|
||||
// $tt == -1 if pre TIMESTAMP_FIRST_YEAR
|
||||
if (($tt === false || $tt == -1) && $v != false)
|
||||
return $v;
|
||||
|
||||
if ($tt === 0)
|
||||
return $this->emptyTimeStamp;
|
||||
else return adodb_date($fmt,$tt);
|
||||
}
|
||||
|
||||
function UserDate($v,$fmt='Y-m-d')
|
||||
{
|
||||
$tt = $this->UnixDate($v);
|
||||
// $tt == -1 if pre TIMESTAMP_FIRST_YEAR
|
||||
if (($tt === false || $tt == -1) && $v != false)
|
||||
return $v;
|
||||
else if ($tt == 0)
|
||||
return $this->emptyDate;
|
||||
else if ($tt == -1) { // pre-TIMESTAMP_FIRST_YEAR
|
||||
}
|
||||
return adodb_date($fmt,$tt);
|
||||
}
|
||||
|
||||
function UnixDate($v)
|
||||
{
|
||||
return sqlite_date_ADOConnection::UnixDate($v);
|
||||
}
|
||||
|
||||
function UnixTimeStamp($v)
|
||||
{
|
||||
return sqlite_date_ADOConnection::UnixTimeStamp($v);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,614 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* ADOdb Lite is a PHP class to encapsulate multiple database APIs and is compatible with
|
||||
* a subset of the ADODB Command Syntax.
|
||||
* Currently supports Frontbase, MaxDB, miniSQL, MSSQL, MSSQL Pro, MySQLi, MySQLt, MySQL, PostgresSQL,
|
||||
* PostgresSQL64, PostgresSQL7, SqLite and Sybase.
|
||||
*
|
||||
*/
|
||||
|
||||
class sqlite_driver_ADOConnection extends ADOConnection
|
||||
{
|
||||
var $sysDate = "date('Y-m-d')";
|
||||
var $sysTimeStamp = "date('Y-m-d H:i:s')";
|
||||
|
||||
function sqlite_driver_ADOConnection()
|
||||
{
|
||||
$this->dbtype = 'sqlite';
|
||||
$this->dataProvider = 'sqlite';
|
||||
}
|
||||
|
||||
/**
|
||||
* Connection to database server and selected database
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _connect($host = "", $username = "", $password = "", $database = "", $persistent, $forcenew)
|
||||
{
|
||||
if (!function_exists('sqlite_factory')) return false;
|
||||
|
||||
$this->host = $host;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
$this->database = ($database == "") ? $host : $database;
|
||||
$this->persistent = $persistent;
|
||||
$this->forcenewconnection = $forcenew;
|
||||
|
||||
if($this->persistent == 1)
|
||||
{
|
||||
$this->connectionId = @sqlite_popen( $this->database );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->connectionId = @sqlite_open( $this->database );
|
||||
}
|
||||
|
||||
if ($this->connectionId === false)
|
||||
{
|
||||
if ($fn = $this->raiseErrorFn)
|
||||
$fn($this->dbtype, 'CONNECT', $this->ErrorNo(), $this->ErrorMsg(), $this->host, $this->database, $this);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose a database to connect.
|
||||
*
|
||||
* @param dbname is the name of the database to select
|
||||
* @return true or false
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function SelectDB($dbname)
|
||||
{
|
||||
$this->database = $dbname;
|
||||
|
||||
$this->connectionId = sqlite_close( $this->connectionId );
|
||||
|
||||
if($this->persistent == 1)
|
||||
{
|
||||
$this->connectionId = @sqlite_popen( $this->database );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->connectionId = @sqlite_open( $this->database );
|
||||
}
|
||||
|
||||
if ($this->connectionId === false)
|
||||
{
|
||||
if ($fn = $this->raiseErrorFn)
|
||||
$fn($this->dbtype, 'CONNECT', $this->ErrorNo(), $this->ErrorMsg(), $this->host, $this->database, $this);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return database error message
|
||||
* Usage: $errormessage =& $db->ErrorMsg();
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function ErrorMsg()
|
||||
{
|
||||
$errorno = @sqlite_last_error( $this->connectionId );
|
||||
$error = ($errorno) ? sqlite_error_string($errorno) : '';
|
||||
return $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return database error number
|
||||
* Usage: $errorbo =& $db->ErrorNo();
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function ErrorNo()
|
||||
{
|
||||
return @sqlite_last_error($this->connectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns # of affected rows from insert/delete/update query
|
||||
*
|
||||
* @access public
|
||||
* @return integer Affected rows
|
||||
*/
|
||||
|
||||
function Affected_Rows()
|
||||
{
|
||||
return @sqlite_changes( $this->connectionId );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last record id of an inserted item
|
||||
* Usage: $db->Insert_ID();
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function Insert_ID()
|
||||
{
|
||||
return @sqlite_last_insert_rowid($this->connectionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Correctly quotes a string so that all strings are escape coded.
|
||||
* An example is $db->qstr("Haven't a clue.");
|
||||
*
|
||||
* @param string the string to quote
|
||||
* @param [magic_quotes] if $s is GET/POST var, set to get_magic_quotes_gpc().
|
||||
*
|
||||
* @return single-quoted string IE: 'Haven\'t a clue.'
|
||||
*/
|
||||
|
||||
function qstr($string, $magic_quotes=false)
|
||||
{
|
||||
// Ugly hack alert! Repalce backticks with some arbitrary character
|
||||
$string = str_replace('`', "\x1C", $string);
|
||||
if (!$magic_quotes) {
|
||||
return "'".str_replace("'", "''", $string)."'";
|
||||
}
|
||||
$string = str_replace("\\'", "''", str_replace('\\\\', '\\', str_replace('\\"', '"', $string)));
|
||||
return "'" . $string . "'";
|
||||
}
|
||||
|
||||
function QMagic($string)
|
||||
{
|
||||
return $this->qstr($string, get_magic_quotes_gpc());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns concatenated string
|
||||
* Usage: $db->Concat($str1,$str2);
|
||||
*
|
||||
* @return concatenated string
|
||||
*/
|
||||
function Concat()
|
||||
{
|
||||
$arr = func_get_args();
|
||||
return implode("||", $arr);
|
||||
}
|
||||
|
||||
function IfNull( $field, $ifNull )
|
||||
{
|
||||
return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes database connection
|
||||
* Usage: $db->close();
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function Close()
|
||||
{
|
||||
@sqlite_close( $this->connectionId );
|
||||
$this->connectionId = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns All Records in an array
|
||||
*
|
||||
* Usage: $db->GetAll($sql);
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function &GetAll($sql, $inputarr = false)
|
||||
{
|
||||
$data =& $this->GetArray($sql, $inputarr);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns All Records in an array
|
||||
*
|
||||
* Usage: $db->GetArray($sql);
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function &GetArray($sql, $inputarr = false)
|
||||
{
|
||||
$data = false;
|
||||
$result =& $this->Execute($sql, $inputarr);
|
||||
if ($result)
|
||||
{
|
||||
$data =& $result->GetArray();
|
||||
$result->Close();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes SQL query and instantiates resultset methods
|
||||
*
|
||||
* @access private
|
||||
* @return mixed Resultset methods
|
||||
*/
|
||||
|
||||
function &do_query( $sql, $offset, $nrows, $inputarr=false )
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
$sql = str_replace('`by`', "'by'", $sql);
|
||||
$sql = str_replace('`order`', '"order"', $sql);
|
||||
$sql = str_replace('`when`', '"when"', $sql);
|
||||
$sql = str_replace('`desc`', "'desc'", $sql);
|
||||
$sql = str_replace('`', '', $sql);
|
||||
$sql = str_replace("\x1C", "`", $sql);
|
||||
if (strpos($sql, "(DISTINCT ipmd5)")) {
|
||||
$sql = str_replace("(DISTINCT ipmd5) FROM " . KU_DBPREFIX . "posts", "(ipmd5) FROM (SELECT DISTINCT ipmd5 FROM " . KU_DBPREFIX . "posts", $sql);
|
||||
$sql .= ")";
|
||||
}
|
||||
$sql = str_replace('IS_DELETED', 'is_deleted', $sql);
|
||||
$sql = str_replace("HIGH_PRIORITY", "", $sql);
|
||||
|
||||
$false = false;
|
||||
|
||||
$offsetStr = '';
|
||||
$limitStr = '';
|
||||
if ($offset != -1 || $nrows != -1)
|
||||
{
|
||||
$offsetStr = ($offset>=0) ? " OFFSET " . $offset . "," : '';
|
||||
$limitStr = ($nrows >= 0) ? " LIMIT ". $nrows : ($offset >= 0 ? ' LIMIT 999999999' : '');
|
||||
}
|
||||
|
||||
if ($inputarr && is_array($inputarr)) {
|
||||
$sqlarr = explode('?', $sql);
|
||||
if (!is_array(reset($inputarr))) $inputarr = array($inputarr);
|
||||
foreach($inputarr as $arr) {
|
||||
$sql = ''; $i = 0;
|
||||
foreach($arr as $v) {
|
||||
$sql .= $sqlarr[$i];
|
||||
switch(gettype($v)){
|
||||
case 'string':
|
||||
$sql .= $this->qstr($v);
|
||||
break;
|
||||
case 'double':
|
||||
$sql .= str_replace(',', '.', $v);
|
||||
break;
|
||||
case 'boolean':
|
||||
$sql .= $v ? 1 : 0;
|
||||
break;
|
||||
default:
|
||||
if ($v === null)
|
||||
$sql .= 'NULL';
|
||||
else $sql .= $v;
|
||||
}
|
||||
$i += 1;
|
||||
}
|
||||
$sql .= $sqlarr[$i];
|
||||
if ($i+1 != sizeof($sqlarr))
|
||||
return $false;
|
||||
$this->sql = $sql . "$limitStr$offsetStr";
|
||||
$time_start = array_sum(explode(' ', microtime()));
|
||||
$this->query_count++;
|
||||
$resultId = @sqlite_query( $this->sql, $this->connectionId );
|
||||
$time_total = (array_sum(explode(' ', microtime())) - $time_start);
|
||||
$this->query_time_total += $time_total;
|
||||
if($this->debug_console)
|
||||
{
|
||||
$this->query_list[] = $this->sql;
|
||||
$this->query_list_time[] = $time_total;
|
||||
$this->query_list_errors[] = $this->ErrorMsg();
|
||||
}
|
||||
if($this->debug)
|
||||
{
|
||||
$this->outp($sql . "$limitStr$offsetStr");
|
||||
}
|
||||
if ($resultId === false) { // error handling if query fails
|
||||
if ($fn = $this->raiseErrorFn)
|
||||
$fn($this->dbtype, 'EXECUTE', $this->ErrorNo(), $this->ErrorMsg(), $this->sql, $inputarr, $this);
|
||||
return $false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sql = $sql . "$limitStr$offsetStr";
|
||||
$time_start = array_sum(explode(' ', microtime()));
|
||||
$this->query_count++;
|
||||
$resultId = @sqlite_query( $this->sql, $this->connectionId );
|
||||
$time_total = (array_sum(explode(' ', microtime())) - $time_start);
|
||||
$this->query_time_total += $time_total;
|
||||
if($this->debug_console)
|
||||
{
|
||||
$this->query_list[] = $this->sql;
|
||||
$this->query_list_time[] = $time_total;
|
||||
$this->query_list_errors[] = $this->ErrorMsg();
|
||||
}
|
||||
if($this->debug)
|
||||
{
|
||||
$this->outp($sql . "$limitStr$offsetStr");
|
||||
}
|
||||
}
|
||||
|
||||
if ($resultId === false) { // error handling if query fails
|
||||
if ($fn = $this->raiseErrorFn)
|
||||
$fn($this->dbtype, 'EXECUTE', $this->ErrorNo(), $this->ErrorMsg(), $this->sql, $inputarr, $this);
|
||||
return $false;
|
||||
}
|
||||
|
||||
if ($resultId === true) { // return simplified recordset for inserts/updates/deletes with lower overhead
|
||||
$recordset = new ADORecordSet_empty();
|
||||
return $recordset;
|
||||
}
|
||||
|
||||
$resultset_name = $this->last_module_name . "_ResultSet";
|
||||
$recordset = new $resultset_name( $resultId, $this->connectionId );
|
||||
|
||||
$recordset->_currentRow = 0;
|
||||
|
||||
switch ($ADODB_FETCH_MODE)
|
||||
{
|
||||
case ADODB_FETCH_NUM: $recordset->fetchMode = SQLITE_NUM; break;
|
||||
case ADODB_FETCH_ASSOC:$recordset->fetchMode = SQLITE_ASSOC; break;
|
||||
default:
|
||||
case ADODB_FETCH_DEFAULT:
|
||||
case ADODB_FETCH_BOTH:$recordset->fetchMode = SQLITE_BOTH; break;
|
||||
}
|
||||
|
||||
$recordset->_numOfRows = @sqlite_num_rows( $resultId );
|
||||
if( $recordset->_numOfRows == 0)
|
||||
{
|
||||
$recordset->EOF = true;
|
||||
}
|
||||
$recordset->_numOfFields = @sqlite_num_fields( $resultId );
|
||||
$recordset->_fetch();
|
||||
|
||||
return $recordset;
|
||||
}
|
||||
}
|
||||
|
||||
class sqlite_driver_ResultSet
|
||||
{
|
||||
var $connectionId;
|
||||
var $fields;
|
||||
var $resultId;
|
||||
var $_currentRow = 0;
|
||||
var $_numOfRows = -1;
|
||||
var $_numOfFields = -1;
|
||||
var $fetchMode;
|
||||
var $EOF;
|
||||
|
||||
/**
|
||||
* sqliteResultSet Constructor
|
||||
*
|
||||
* @access private
|
||||
* @param string $record
|
||||
* @param string $resultId
|
||||
*/
|
||||
|
||||
function sqlite_driver_ResultSet( $resultId, $connectionId )
|
||||
{
|
||||
$this->fields = array();
|
||||
$this->connectionId = $connectionId;
|
||||
$this->record = array();
|
||||
$this->resultId = $resultId;
|
||||
$this->EOF = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees resultset
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function close()
|
||||
{
|
||||
$this->fields = array();
|
||||
$this->resultId = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns field name from select query
|
||||
*
|
||||
* @access public
|
||||
* @param string $field
|
||||
* @return string Field name
|
||||
*/
|
||||
|
||||
function fields( $field )
|
||||
{
|
||||
if(empty($field))
|
||||
{
|
||||
return $this->fields;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->fields[$field];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns numrows from select query
|
||||
*
|
||||
* @access public
|
||||
* @return integer Numrows
|
||||
*/
|
||||
|
||||
function RecordCount()
|
||||
{
|
||||
return $this->_numOfRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns num of fields from select query
|
||||
*
|
||||
* @access public
|
||||
* @return integer numfields
|
||||
*/
|
||||
|
||||
function FieldCount()
|
||||
{
|
||||
return $this->_numOfFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns next record
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function MoveNext()
|
||||
{
|
||||
if (@$this->fields = sqlite_fetch_array($this->resultId,$this->fetchMode)) {
|
||||
$this->_currentRow += 1;
|
||||
return true;
|
||||
}
|
||||
if (!$this->EOF) {
|
||||
$this->_currentRow += 1;
|
||||
$this->EOF = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the first row in the recordset. Many databases do NOT support this.
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
|
||||
function MoveFirst()
|
||||
{
|
||||
if ($this->_currentRow == 0) return true;
|
||||
return $this->Move(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Last Record
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function MoveLast()
|
||||
{
|
||||
if ($this->EOF) return false;
|
||||
return $this->Move($this->_numOfRows - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Random access to a specific row in the recordset. Some databases do not support
|
||||
* access to previous rows in the databases (no scrolling backwards).
|
||||
*
|
||||
* @param rowNumber is the row to move to (0-based)
|
||||
*
|
||||
* @return true if there still rows available, or false if there are no more rows (EOF).
|
||||
*/
|
||||
|
||||
function Move($rowNumber = 0)
|
||||
{
|
||||
if ($rowNumber == $this->_currentRow) return true;
|
||||
$this->EOF = false;
|
||||
if ($this->_numOfRows > 0){
|
||||
if ($rowNumber >= $this->_numOfRows - 1){
|
||||
$rowNumber = $this->_numOfRows - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_seek($rowNumber)) {
|
||||
$this->_currentRow = $rowNumber;
|
||||
if ($this->_fetch()) {
|
||||
return true;
|
||||
}
|
||||
$this->fields = false;
|
||||
}
|
||||
$this->EOF = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform Seek to specific row
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _seek($row)
|
||||
{
|
||||
if ($this->_numOfRows == 0) return false;
|
||||
return @sqlite_seek($this->resultId,$row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills field array with first database element when query initially executed
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
|
||||
function _fetch()
|
||||
{
|
||||
$this->fields = @sqlite_fetch_array($this->resultId,$this->fetchMode);
|
||||
return is_array($this->fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if last record reached
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function EOF()
|
||||
{
|
||||
if( $this->_currentRow < $this->_numOfRows)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->EOF = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns All Records in an array
|
||||
*
|
||||
* @access public
|
||||
* @param [nRows] is the number of rows to return. -1 means every row.
|
||||
*/
|
||||
|
||||
function &GetArray($nRows = -1)
|
||||
{
|
||||
$results = array();
|
||||
$cnt = 0;
|
||||
while (!$this->EOF && $nRows != $cnt) {
|
||||
$results[] = $this->fields;
|
||||
$this->MoveNext();
|
||||
$cnt++;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
function &GetRows($nRows = -1)
|
||||
{
|
||||
$arr =& $this->GetArray($nRows);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
function &GetAll($nRows = -1)
|
||||
{
|
||||
$arr =& $this->GetArray($nRows);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch field information for a table.
|
||||
*
|
||||
* @return object containing the name, type and max_length
|
||||
*/
|
||||
function FetchField($fieldOffset = -1)
|
||||
{
|
||||
$fieldObject = new ADOFieldObject;
|
||||
$fieldObject->name = sqlite_field_name($this->resultId, $fieldOffset);
|
||||
$fieldObject->type = 'VARCHAR';
|
||||
$fieldObject->max_length = -1;
|
||||
return $fieldObject;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* ADOdb Lite Extend Module for Mysqlt
|
||||
*
|
||||
*/
|
||||
|
||||
eval('class sqlite_extend_EXTENDER extends '. $last_module . '_ADOConnection { }');
|
||||
|
||||
class sqlite_extend_ADOConnection extends sqlite_extend_EXTENDER
|
||||
{
|
||||
function &GetAssoc($sql, $inputarr=false, $force_array = false, $first2cols = false)
|
||||
{
|
||||
$data = false;
|
||||
$result =& $this->Execute($sql, $inputarr);
|
||||
if ($result) {
|
||||
$data =& $result->GetAssoc($force_array, $first2cols);
|
||||
$result->Close();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a sequence id and stores it in $this->genID;
|
||||
* GenID is only available if $this->hasGenID = true;
|
||||
*
|
||||
* @param seqname name of sequence to use
|
||||
* @param startID if sequence does not exist, start at this ID
|
||||
* @return 0 if not supported, otherwise a sequence id
|
||||
*/
|
||||
|
||||
var $_genSeqSQL = "create table %s (id integer)";
|
||||
var $_dropSeqSQL = 'drop table %s';
|
||||
var $genID = 0;
|
||||
|
||||
function GenID($seqname='adodbseq', $startID=1)
|
||||
{
|
||||
$MAXLOOPS = 100;
|
||||
while (--$MAXLOOPS>=0) {
|
||||
@($num = $this->GetOne("select id from $seq"));
|
||||
if ($num === false) {
|
||||
$this->Execute(sprintf($this->_genSeqSQL, $seq));
|
||||
$start -= 1;
|
||||
$num = '0';
|
||||
$result = $this->Execute("insert into $seq values($start)");
|
||||
if (!$result)
|
||||
return false;
|
||||
}
|
||||
$this->Execute("update $seq set id=id+1 where id=$num");
|
||||
|
||||
if ($this->affected_rows() > 0) {
|
||||
$num += 1;
|
||||
$this->genID = $num;
|
||||
return $num;
|
||||
}
|
||||
}
|
||||
if ($fn = $this->raiseErrorFn) {
|
||||
$fn($this->databaseType, 'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts", $seq, $num);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function CreateSequence($seqname='adodbseq', $start=1)
|
||||
{
|
||||
$ok = $this->Execute(sprintf($this->_genSeqSQL, $seqname));
|
||||
if (!$ok)
|
||||
return false;
|
||||
$start -= 1;
|
||||
return $this->Execute("insert into $seqname values($start)");
|
||||
}
|
||||
|
||||
function DropSequence($seqname)
|
||||
{
|
||||
return $this->Execute(sprintf($this->_dropSeqSQL, $seqname));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval('class sqlite_extend_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
|
||||
|
||||
class sqlite_extend_ResultSet extends sqlite_extend_resultset_EXTENDER
|
||||
{
|
||||
function &GetAssoc($force_array = false, $first2cols = false)
|
||||
{
|
||||
$results = false;
|
||||
|
||||
if ($this->_numOfFields > 1) {
|
||||
$numIndex = isset($this->fields[0]);
|
||||
$results = array();
|
||||
if (!$first2cols && ($this->_numOfFields > 2 || $force_array)) {
|
||||
if ($numIndex) {
|
||||
while (!$this->EOF) {
|
||||
$results[trim($this->fields[0])] = array_slice($this->fields, 1);
|
||||
$this->MoveNext();
|
||||
}
|
||||
} else {
|
||||
while (!$this->EOF) {
|
||||
$results[trim(reset($this->fields))] = array_slice($this->fields, 1);
|
||||
$this->MoveNext();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($numIndex) {
|
||||
while (!$this->EOF) {
|
||||
$results[trim(($this->fields[0]))] = $this->fields[1];
|
||||
$this->MoveNext();
|
||||
}
|
||||
} else {
|
||||
while (!$this->EOF) {
|
||||
$v1 = trim(reset($this->fields));
|
||||
$v2 = ''.next($this->fields);
|
||||
$results[$v1] = $v2;
|
||||
$this->MoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
function PO_RecordCount($table="", $condition="")
|
||||
{
|
||||
$lnumrows = $this->_numOfRows;
|
||||
if($lnumrows == -1 && $this->connectionId)
|
||||
{
|
||||
if($table)
|
||||
{
|
||||
if ($condition)
|
||||
$condition = " WHERE " . $condition;
|
||||
$resultrows = &$this->connectionId->Execute("SELECT COUNT(*) FROM $table $condition");
|
||||
if ($resultrows)
|
||||
$lnumrows = reset($resultrows->fields);
|
||||
}
|
||||
}
|
||||
return $lnumrows;
|
||||
}
|
||||
|
||||
function CurrentRow()
|
||||
{
|
||||
return $this->_currentRow;
|
||||
}
|
||||
|
||||
function AbsolutePosition()
|
||||
{
|
||||
return $this->_currentRow;
|
||||
}
|
||||
|
||||
function NextRecordSet()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
/**
|
||||
* ADOdb Lite Meta Module for SQlite
|
||||
*
|
||||
* Portions of the Meta Coding came from ADOdb
|
||||
*/
|
||||
|
||||
/*
|
||||
(c) 2000-2005 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. See License.txt.
|
||||
*/
|
||||
|
||||
eval('class sqlite_meta_EXTENDER extends '. $last_module . '_ADOConnection { }');
|
||||
|
||||
class sqlite_meta_ADOConnection extends sqlite_meta_EXTENDER
|
||||
{
|
||||
var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
|
||||
var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
|
||||
|
||||
function MetaError($err=false)
|
||||
{
|
||||
include_once(ADODB_DIR."/adodb-error.inc.php");
|
||||
if ($err === false)
|
||||
$err = $this->ErrorNo();
|
||||
|
||||
return adodb_error($this->dataProvider,$this->databaseType,$err);
|
||||
}
|
||||
|
||||
function MetaErrorMsg($errno)
|
||||
{
|
||||
include_once(ADODB_DIR."/adodb-error.inc.php");
|
||||
return adodb_errormsg($errno);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns an array with the primary key columns in it.
|
||||
*/
|
||||
function MetaPrimaryKeys($table, $owner=false)
|
||||
{
|
||||
// owner not used in base class - see oci8
|
||||
$p = array();
|
||||
$objs =& $this->MetaColumns($table);
|
||||
if ($objs) {
|
||||
foreach($objs as $v) {
|
||||
if (!empty($v->primary_key))
|
||||
$p[] = $v->name;
|
||||
}
|
||||
}
|
||||
if (sizeof($p)) return $p;
|
||||
if (function_exists('ADODB_VIEW_PRIMARYKEYS'))
|
||||
return ADODB_VIEW_PRIMARYKEYS($this->databaseType, $this->database, $table, $owner);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns assoc array where keys are tables, and values are foreign keys
|
||||
*/
|
||||
function MetaForeignKeys($table, $owner=false, $upper=false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// not the fastest implementation - quick and dirty - jlim
|
||||
// for best performance, use the actual $rs->MetaType().
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
if (empty($this->_metars)) {
|
||||
$rsclass = $this->last_module_name . "_ResultSet";
|
||||
$this->_metars =& new $rsclass(false,$this->fetchMode);
|
||||
}
|
||||
|
||||
return $this->_metars->MetaType($t,$len,$fieldobj);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the databases that the driver can connect to.
|
||||
* Some databases will return an empty array.
|
||||
*
|
||||
* @return an array of database names.
|
||||
*/
|
||||
function MetaDatabases()
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
if ($this->metaDatabasesSQL) {
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||
|
||||
$arr = $this->GetCol($this->metaDatabasesSQL);
|
||||
if (isset($savem)) $this->SetFetchMode($savem);
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ttype can either be 'VIEW' or 'TABLE' or false.
|
||||
* If false, both views and tables are returned.
|
||||
* "VIEW" returns only views
|
||||
* "TABLE" returns only tables
|
||||
* @param showSchema returns the schema/user with the table name, eg. USER.TABLE
|
||||
* @param mask is the input mask - only supported by oci8 and postgresql
|
||||
*
|
||||
* @return array of tables for current database.
|
||||
*/
|
||||
|
||||
function &MetaTables($ttype=false,$showSchema=false,$mask=false)
|
||||
{
|
||||
global $ADODB_FETCH_MODE;
|
||||
|
||||
$false = false;
|
||||
if ($mask) {
|
||||
return $false;
|
||||
}
|
||||
if ($this->metaTablesSQL) {
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||
|
||||
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||
|
||||
$rs = $this->Execute($this->metaTablesSQL);
|
||||
if (isset($savem)) $this->SetFetchMode($savem);
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
if ($rs === false) return $false;
|
||||
$arr =& $rs->GetArray();
|
||||
$arr2 = array();
|
||||
|
||||
if ($hast = ($ttype && isset($arr[0][1]))) {
|
||||
$showt = strncmp($ttype,'T',1);
|
||||
}
|
||||
|
||||
for ($i=0; $i < sizeof($arr); $i++) {
|
||||
if ($hast) {
|
||||
if ($showt == 0) {
|
||||
if (strncmp($arr[$i][1],'T',1) == 0) $arr2[] = trim($arr[$i][0]);
|
||||
} else {
|
||||
if (strncmp($arr[$i][1],'V',1) == 0) $arr2[] = trim($arr[$i][0]);
|
||||
}
|
||||
} else
|
||||
$arr2[] = trim($arr[$i][0]);
|
||||
}
|
||||
$rs->Close();
|
||||
return $arr2;
|
||||
}
|
||||
return $false;
|
||||
}
|
||||
|
||||
function _findschema(&$table,&$schema)
|
||||
{
|
||||
if (!$schema && ($at = strpos($table,'.')) !== false) {
|
||||
$schema = substr($table,0,$at);
|
||||
$table = substr($table,$at+1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List columns in a database as an array of ADOFieldObjects.
|
||||
* See top of file for definition of object.
|
||||
*
|
||||
* @param $table table name to query
|
||||
* @param $normalize makes table name case-insensitive (required by some databases)
|
||||
* @schema is optional database schema to use - not supported by all databases.
|
||||
*
|
||||
* @return array of ADOFieldObjects for current table.
|
||||
*/
|
||||
function &MetaColumns($tab)
|
||||
{
|
||||
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('$tab')");
|
||||
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 ($save == ADODB_FETCH_NUM) $arr[] = $fld;
|
||||
else $arr[strtoupper($fld->name)] = $fld;
|
||||
}
|
||||
$rs->Close();
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* List indexes on a table as an array.
|
||||
* @param table table name to query
|
||||
* @param primary true to only show primary keys. Not actually used for most databases
|
||||
*
|
||||
* @return array of indexes on current table. Each element represents an index, and is itself an associative array.
|
||||
|
||||
Array (
|
||||
[name_of_index] => Array
|
||||
(
|
||||
[unique] => true or false
|
||||
[columns] => Array
|
||||
(
|
||||
[0] => firstname
|
||||
[1] => lastname
|
||||
)
|
||||
)
|
||||
*/
|
||||
function &MetaIndexes($table, $primary = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* List columns names in a table as an array.
|
||||
* @param table table name to query
|
||||
*
|
||||
* @return array of column names for current table.
|
||||
*/
|
||||
function &MetaColumnNames($table, $numIndexes=false,$useattnum=false /* only for postgres */)
|
||||
{
|
||||
$objarr =& $this->MetaColumns($table);
|
||||
if (!is_array($objarr)) {
|
||||
$false = false;
|
||||
return $false;
|
||||
}
|
||||
$arr = array();
|
||||
if ($numIndexes) {
|
||||
$i = 0;
|
||||
if ($useattnum) {
|
||||
foreach($objarr as $v)
|
||||
$arr[$v->attnum] = $v->name;
|
||||
|
||||
} else
|
||||
foreach($objarr as $v) $arr[$i++] = $v->name;
|
||||
} else
|
||||
foreach($objarr as $v) $arr[strtoupper($v->name)] = $v->name;
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
function MetaTransaction($mode,$db)
|
||||
{
|
||||
$mode = strtoupper($mode);
|
||||
$mode = str_replace('ISOLATION LEVEL ','',$mode);
|
||||
|
||||
switch($mode) {
|
||||
|
||||
case 'READ UNCOMMITTED':
|
||||
switch($db) {
|
||||
case 'oci8':
|
||||
case 'oracle':
|
||||
return 'ISOLATION LEVEL READ COMMITTED';
|
||||
default:
|
||||
return 'ISOLATION LEVEL READ UNCOMMITTED';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'READ COMMITTED':
|
||||
return 'ISOLATION LEVEL READ COMMITTED';
|
||||
break;
|
||||
|
||||
case 'REPEATABLE READ':
|
||||
switch($db) {
|
||||
case 'oci8':
|
||||
case 'oracle':
|
||||
return 'ISOLATION LEVEL SERIALIZABLE';
|
||||
default:
|
||||
return 'ISOLATION LEVEL REPEATABLE READ';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'SERIALIZABLE':
|
||||
return 'ISOLATION LEVEL SERIALIZABLE';
|
||||
break;
|
||||
|
||||
default:
|
||||
return $mode;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval('class sqlite_meta_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
|
||||
|
||||
class sqlite_meta_ResultSet extends sqlite_meta_resultset_EXTENDER
|
||||
{
|
||||
/**
|
||||
* Get the metatype of the column. This is used for formatting. This is because
|
||||
* many databases use different names for the same type, so we transform the original
|
||||
* type to our standardised version which uses 1 character codes:
|
||||
*
|
||||
* @param t is the type passed in. Normally is ADOFieldObject->type.
|
||||
* @param len is the maximum length of that field. This is because we treat character
|
||||
* fields bigger than a certain size as a 'B' (blob).
|
||||
* @param fieldobj is the field object returned by the database driver. Can hold
|
||||
* additional info (eg. primary_key for mysql).
|
||||
*
|
||||
* @return the general type of the data:
|
||||
* C for character < 250 chars
|
||||
* X for teXt (>= 250 chars)
|
||||
* B for Binary
|
||||
* N for numeric or floating point
|
||||
* D for date
|
||||
* T for timestamp
|
||||
* L for logical/Boolean
|
||||
* I for integer
|
||||
* R for autoincrement counter/integer
|
||||
*
|
||||
*
|
||||
*/
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
if (is_object($t)) {
|
||||
$fieldobj = $t;
|
||||
$t = $fieldobj->type;
|
||||
$len = $fieldobj->max_length;
|
||||
}
|
||||
|
||||
$len = -1; // mysql max_length is not accurate
|
||||
switch (strtoupper($t)) {
|
||||
case 'STRING':
|
||||
case 'CHAR':
|
||||
case 'VARCHAR':
|
||||
case 'TINYBLOB':
|
||||
case 'TINYTEXT':
|
||||
case 'ENUM':
|
||||
case 'SET':
|
||||
if ($len <= $this->blobSize) return 'C';
|
||||
|
||||
case 'TEXT':
|
||||
case 'LONGTEXT':
|
||||
case 'MEDIUMTEXT':
|
||||
return 'X';
|
||||
|
||||
// php_mysql extension always returns 'blob' even if 'text'
|
||||
// so we have to check whether binary...
|
||||
case 'IMAGE':
|
||||
case 'LONGBLOB':
|
||||
case 'BLOB':
|
||||
case 'MEDIUMBLOB':
|
||||
return !empty($fieldobj->binary) ? 'B' : 'X';
|
||||
|
||||
case 'YEAR':
|
||||
case 'DATE': return 'D';
|
||||
|
||||
case 'TIME':
|
||||
case 'DATETIME':
|
||||
case 'TIMESTAMP': return 'T';
|
||||
|
||||
case 'INT':
|
||||
case 'INTEGER':
|
||||
case 'BIGINT':
|
||||
case 'TINYINT':
|
||||
case 'MEDIUMINT':
|
||||
case 'SMALLINT':
|
||||
|
||||
if (!empty($fieldobj->primary_key)) return 'R';
|
||||
else return 'I';
|
||||
|
||||
default:
|
||||
static $typeMap = array(
|
||||
'VARCHAR' => 'C',
|
||||
'VARCHAR2' => 'C',
|
||||
'CHAR' => 'C',
|
||||
'C' => 'C',
|
||||
'STRING' => 'C',
|
||||
'NCHAR' => 'C',
|
||||
'NVARCHAR' => 'C',
|
||||
'VARYING' => 'C',
|
||||
'BPCHAR' => 'C',
|
||||
'CHARACTER' => 'C',
|
||||
'INTERVAL' => 'C', # Postgres
|
||||
'MACADDR' => 'C', # postgres
|
||||
##
|
||||
'LONGCHAR' => 'X',
|
||||
'TEXT' => 'X',
|
||||
'NTEXT' => 'X',
|
||||
'M' => 'X',
|
||||
'X' => 'X',
|
||||
'CLOB' => 'X',
|
||||
'NCLOB' => 'X',
|
||||
'LVARCHAR' => 'X',
|
||||
##
|
||||
'BLOB' => 'B',
|
||||
'IMAGE' => 'B',
|
||||
'BINARY' => 'B',
|
||||
'VARBINARY' => 'B',
|
||||
'LONGBINARY' => 'B',
|
||||
'B' => 'B',
|
||||
##
|
||||
'YEAR' => 'D', // mysql
|
||||
'DATE' => 'D',
|
||||
'D' => 'D',
|
||||
##
|
||||
'UNIQUEIDENTIFIER' => 'C', # MS SQL Server
|
||||
##
|
||||
'TIME' => 'T',
|
||||
'TIMESTAMP' => 'T',
|
||||
'DATETIME' => 'T',
|
||||
'TIMESTAMPTZ' => 'T',
|
||||
'T' => 'T',
|
||||
'TIMESTAMP WITHOUT TIME ZONE' => 'T', // postgresql
|
||||
##
|
||||
'BOOL' => 'L',
|
||||
'BOOLEAN' => 'L',
|
||||
'BIT' => 'L',
|
||||
'L' => 'L',
|
||||
##
|
||||
'COUNTER' => 'R',
|
||||
'R' => 'R',
|
||||
'SERIAL' => 'R', // ifx
|
||||
'INT IDENTITY' => 'R',
|
||||
##
|
||||
'INT' => 'I',
|
||||
'INT2' => 'I',
|
||||
'INT4' => 'I',
|
||||
'INT8' => 'I',
|
||||
'INTEGER' => 'I',
|
||||
'INTEGER UNSIGNED' => 'I',
|
||||
'SHORT' => 'I',
|
||||
'TINYINT' => 'I',
|
||||
'SMALLINT' => 'I',
|
||||
'I' => 'I',
|
||||
##
|
||||
'LONG' => 'N', // interbase is numeric, oci8 is blob
|
||||
'BIGINT' => 'N', // this is bigger than PHP 32-bit integers
|
||||
'DECIMAL' => 'N',
|
||||
'DEC' => 'N',
|
||||
'REAL' => 'N',
|
||||
'DOUBLE' => 'N',
|
||||
'DOUBLE PRECISION' => 'N',
|
||||
'SMALLFLOAT' => 'N',
|
||||
'FLOAT' => 'N',
|
||||
'NUMBER' => 'N',
|
||||
'NUM' => 'N',
|
||||
'NUMERIC' => 'N',
|
||||
'MONEY' => 'N',
|
||||
|
||||
## informix 9.2
|
||||
'SQLINT' => 'I',
|
||||
'SQLSERIAL' => 'I',
|
||||
'SQLSMINT' => 'I',
|
||||
'SQLSMFLOAT' => 'N',
|
||||
'SQLFLOAT' => 'N',
|
||||
'SQLMONEY' => 'N',
|
||||
'SQLDECIMAL' => 'N',
|
||||
'SQLDATE' => 'D',
|
||||
'SQLVCHAR' => 'C',
|
||||
'SQLCHAR' => 'C',
|
||||
'SQLDTIME' => 'T',
|
||||
'SQLINTERVAL' => 'N',
|
||||
'SQLBYTES' => 'B',
|
||||
'SQLTEXT' => 'X',
|
||||
## informix 10
|
||||
"SQLINT8" => 'I8',
|
||||
"SQLSERIAL8" => 'I8',
|
||||
"SQLNCHAR" => 'C',
|
||||
"SQLNVCHAR" => 'C',
|
||||
"SQLLVARCHAR" => 'X',
|
||||
"SQLBOOL" => 'L'
|
||||
);
|
||||
|
||||
$tmap = false;
|
||||
$t = strtoupper($t);
|
||||
$tmap = (isset($typeMap[$t])) ? $typeMap[$t] : 'N';
|
||||
if ($t == 'LONG' && $this->dataProvider == 'oci8') return 'B';
|
||||
return $tmap;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/**
|
||||
* ADOdb Lite Transaction Module for Sqlite
|
||||
*
|
||||
*/
|
||||
|
||||
eval('class sqlite_transaction_EXTENDER extends '. $last_module . '_ADOConnection { }');
|
||||
|
||||
class sqlite_transaction_ADOConnection extends sqlite_transaction_EXTENDER
|
||||
{
|
||||
var $autoCommit = true;
|
||||
var $transOff = 0;
|
||||
var $transCnt = 0;
|
||||
var $transaction_status = true;
|
||||
|
||||
function StartTrans($errfn = 'ADODB_TransMonitor')
|
||||
{
|
||||
if ($this->transOff > 0) {
|
||||
$this->transOff += 1;
|
||||
return;
|
||||
}
|
||||
$this->transaction_status = true;
|
||||
|
||||
if ($this->debug && $this->transCnt > 0)
|
||||
ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");
|
||||
|
||||
$this->BeginTrans();
|
||||
$this->transOff = 1;
|
||||
}
|
||||
|
||||
function BeginTrans()
|
||||
{
|
||||
if ($this->transOff)
|
||||
return true;
|
||||
|
||||
$ret = $this->Execute("BEGIN TRANSACTION");
|
||||
$this->transCnt += 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
function CompleteTrans($autoComplete = true)
|
||||
{
|
||||
if ($this->transOff > 1) {
|
||||
$this->transOff -= 1;
|
||||
return true;
|
||||
}
|
||||
$this->transOff = 0;
|
||||
if ($this->transaction_status && $autoComplete) {
|
||||
if (!$this->CommitTrans()) {
|
||||
$this->transaction_status = false;
|
||||
if ($this->debug)
|
||||
ADOConnection::outp("Smart Commit failed");
|
||||
} else
|
||||
if ($this->debug)
|
||||
ADOConnection::outp("Smart Commit occurred");
|
||||
} else {
|
||||
$this->RollbackTrans();
|
||||
if ($this->debug)
|
||||
ADOCOnnection::outp("Smart Rollback occurred");
|
||||
}
|
||||
return $this->transaction_status;
|
||||
}
|
||||
|
||||
function CommitTrans($ok=true)
|
||||
{
|
||||
if ($this->transOff)
|
||||
return true;
|
||||
|
||||
if (!$ok)
|
||||
return $this->RollbackTrans();
|
||||
|
||||
$ret = $this->Execute("COMMIT");
|
||||
if ($this->transCnt>0)
|
||||
$this->transCnt -= 1;
|
||||
|
||||
return !empty($ret);
|
||||
}
|
||||
|
||||
function RollbackTrans()
|
||||
{
|
||||
if ($this->transOff)
|
||||
return true;
|
||||
|
||||
$ret = $this->Execute("ROLLBACK");
|
||||
if ($this->transCnt>0)
|
||||
$this->transCnt -= 1;
|
||||
|
||||
return !empty($ret);
|
||||
}
|
||||
|
||||
function FailTrans()
|
||||
{
|
||||
if ($this->debug)
|
||||
if ($this->transOff == 0) {
|
||||
ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");
|
||||
} else {
|
||||
ADOConnection::outp("FailTrans was called");
|
||||
}
|
||||
$this->transaction_status = false;
|
||||
}
|
||||
|
||||
function HasFailedTrans()
|
||||
{
|
||||
if ($this->transOff > 0)
|
||||
return $this->transaction_status == false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function RowLock($tables,$where,$flds='1 as ignore')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function CommitLock($table)
|
||||
{
|
||||
return $this->CommitTrans();
|
||||
}
|
||||
|
||||
function RollbackLock($table)
|
||||
{
|
||||
return $this->RollbackTrans();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval('class sqlite_transaction_resultset_EXTENDER extends '. $last_module . '_ResultSet { }');
|
||||
|
||||
class sqlite_transaction_ResultSet extends sqlite_transaction_resultset_EXTENDER
|
||||
{
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user