global $_ADODB_ACTIVE_DBS;
global $ADODB_ACTIVE_CACHESECS; // set to true to enable caching of metadata such as field info
+global $ACTIVE_RECORD_SAFETY; // set to false to disable safety checks
// array of ADODB_Active_DB's, indexed by ADODB_Active_Record->_dbat
$_ADODB_ACTIVE_DBS = array();
-
+$ACTIVE_RECORD_SAFETY = true;
class ADODB_Active_DB {
var $db; // ADOConnection
// set a numeric array (using natural table field ordering) as object properties
function Set(&$row)
{
+ global $ACTIVE_RECORD_SAFETY;
+
$db =& $this->DB();
if (!$row) {
$this->_saved = true;
$table =& $this->TableInfo();
- if (sizeof($table->flds) != sizeof($row)) {
+ if ($ACTIVE_RECORD_SAFETY && sizeof($table->flds) != sizeof($row)) {
$this->Error("Table structure of $this->_table has changed","Load");
return false;
}
return $this->connection->MetaIndexes($this->TableName($table), $primary, $owner);
}
+
function MetaType($t,$len=-1,$fieldobj=false)
- {
- return ADORecordSet::MetaType($t,$len,$fieldobj);
+ {
+ 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'
+ );
+
+ if (!$this->connection->IsConnected()) {
+ $t = strtoupper($t);
+ if (isset($typeMap[$t])) return $typeMap[$t];
+ return 'N';
+ }
+ return $this->connection->MetaType($t,$len,$fieldobj);
}
function NameQuote($name = NULL,$allowBrackets=false)
$val = $zthis->DBDate($arrFields[$fname]);
break;
- case "T":
+ \r
+ case "T":\r
$val = $zthis->DBTimeStamp($arrFields[$fname]);
break;
// moodle change start - see readme_moodle.txt
- case "L": //Integer field suitable for storing booleans (0 or 1)
- case "I": //Integer
- $val = (int)$arrFields[$fname];
- break;
-
case "F": //Floating point number
case "N": //Numeric or decimal number
$val = (float)$arrFields[$fname];
break;
+
+ case "L": //Integer field suitable for storing booleans (0 or 1)
// moodle change end
+ case "I":
+ case "R":
+ $val = (int) $arrFields[$fname];
+ break;
- default:
- $val = $arrFields[$fname];
+ default:
+ $val = str_replace(array("'"," ","("),"",$arrFields[$fname]); // basic sql injection defence
if (empty($val)) $val = '0';
break;
}
/*
* Set tabs to 4 for best viewing.
*
- * Latest version is available at http://adodb.sourceforge.net
+ * Latest version is available at http://adodb.sourceforge.net/
*
* This is the main include file for ADOdb.
* Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php
$dir = $ADODB_CACHE_DIR;
if ($this->debug) {
- ADOConnection::outp( "CacheFlush: $dir<br><pre>\n", $this->_dirFlush($dir),"</pre>");
+ ADOConnection::outp( "CacheFlush: $dir<br><pre>\n". $this->_dirFlush($dir)."</pre>");
} else {
$this->_dirFlush($dir);
}
* Just specify the directory, and tell it if you want to delete the directory or just clear it out.
* Note: $kill_top_level is used internally in the function to flush subdirectories.
*/
- function _dirFlush($dir, $kill_top_level = false) {
+ function _dirFlush($dir, $kill_top_level = false)
+ {
if(!$dh = @opendir($dir)) return;
while (($obj = readdir($dh))) {
- if($obj=='.' || $obj=='..')
- continue;
-
- if (!@unlink($dir.'/'.$obj))
- $this->_dirFlush($dir.'/'.$obj, true);
+ if($obj=='.' || $obj=='..') continue;
+ $f = $dir.'/'.$obj;
+
+ if (strpos($obj,'.cache')) @unlink($f);
+ if (is_dir($f)) $this->_dirFlush($f, true);
}
- if ($kill_top_level === true)
- @rmdir($dir);
+ if ($kill_top_level === true) @rmdir($dir);
return true;
}
if ($argProvider) $dbc->Provider = $argProvider;
- if ($argProvider) $argHostname = "PROVIDER=$argProvider;DRIVER={SQL Server};SERVER=$argHostname";
-
-
if ($argDatabasename) $argHostname .= ";DATABASE=$argDatabasename";
if ($argUsername) $argHostname .= ";$u=$argUsername";
if ($argPassword)$argHostname .= ";$p=$argPassword";
var $sysDate = 'CURRENT DATE';
var $sysTimeStamp = 'CURRENT TIMESTAMP';
- var $fmtTimeStamp = "'Y-m-d-H.i.s'";
+ var $fmtTimeStamp = "'Y-m-d-H:i:s'";
var $replaceQuote = "''"; // string to use to replace quotes
var $dataProvider = "db2";
var $hasAffectedRows = true;
// Reference on Last_Insert_ID on the recommended way to simulate sequences
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
var $_genSeqSQL = "create table %s (id int not null)";
+ var $_genSeqCountSQL = "select count(*) from %s";
var $_genSeq2SQL = "insert into %s values (%s)";
var $_dropSeqSQL = "drop table %s";
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
$u = strtoupper($seqname);
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
- $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+ $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
+ if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
$rs = $this->Execute($getnext);
}
- $this->genID = mysql_insert_id($this->_connectionID);
- if ($rs) $rs->Close();
+ if ($rs) {
+ $this->genID = mysql_insert_id($this->_connectionID);
+ $rs->Close();
+ } else
+ $this->genID = 0;
$this->_logsql = $savelog;
return $this->genID;
$fld->primary_key = ($rs->fields[3] == 'PRI');
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
$fld->binary = (strpos($type,'blob') !== false);
- $fld->unsigned = (strpos($type,'unsigned') !== false);
-
+ $fld->unsigned = (strpos($type,'unsigned') !== false);
+ $fld->zerofill = (strpos($type,'zerofill') !== false);
+
if (!$fld->binary) {
$d = $rs->fields[4];
if ($d != '' && $d != 'NULL') {
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
$u = strtoupper($seqname);
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
- $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
+ $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
+ if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
$rs = $this->Execute($getnext);
}
- $this->genID = mysqli_insert_id($this->_connectionID);
-
- if ($rs) $rs->Close();
+ if ($rs) {
+ $this->genID = mysqli_insert_id($this->_connectionID);
+ $rs->Close();
+ } else
+ $this->genID = 0;
+
return $this->genID;
}
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
$fld->binary = (strpos($type,'blob') !== false);
$fld->unsigned = (strpos($type,'unsigned') !== false);
+ $fld->zerofill = (strpos($type,'zerofill') !== false);
if (!$fld->binary) {
$d = $rs->fields[4];
var $firstrows = true; // enable first rows optimization on SelectLimit()
var $selectOffsetAlg1 = 100; // when to use 1st algorithm of selectlimit.
var $NLS_DATE_FORMAT = 'YYYY-MM-DD'; // To include time, use 'RRRR-MM-DD HH24:MI:SS'
+ var $dateformat = 'YYYY-MM-DD'; // for DBDate()
var $useDBDateFormatForTextInput=false;
var $datetime = false; // MetaType('DATE') returns 'D' (datetime==false) or 'T' (datetime == true)
var $_refLOBs = array();
if (empty($d) && $d !== 0) return 'null';
if (is_string($d)) $d = ADORecordSet::UnixDate($d);
- return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->NLS_DATE_FORMAT."')";
+ return "TO_DATE(".adodb_date($this->fmtDate,$d).",'".$this->dateformat."')";
}
function BindDate($d)
{
if (empty($ts) && $ts !== 0) return 'null';
if (is_string($ts)) $ts = ADORecordSet::UnixTimeStamp($ts);
- return 'TO_DATE('.adodb_date($this->fmtTimeStamp,$ts).",'RRRR-MM-DD, HH:MI:SS AM')";
+ return 'TO_DATE('.adodb_date("'Y-m-d H:i:s'",$ts).",'RRRR-MM-DD, HH24:MI:SS')";
}
function RowLock($tables,$where,$flds='1 as ignore')
if ($argDatabasename) $argUsername .= "@$argDatabasename";
//if ($argHostname) print "<p>Connect: 1st argument should be left blank for $this->databaseType</p>";
- if ($mode = 1)
+ if ($mode == 1)
$this->_connectionID = ora_plogon($argUsername,$argPassword);
else
$this->_connectionID = ora_logon($argUsername,$argPassword);
--- /dev/null
+<?php
+// by Trirat Petchsingh <rosskouk#gmail.com>
+$ADODB_LANG_ARRAY = array (
+ 'LANG' => 'th',
+ DB_ERROR => 'error ไม่รู้สาเหตุ',
+ DB_ERROR_ALREADY_EXISTS => 'มีà¹?ลà¹\89ว',
+ DB_ERROR_CANNOT_CREATE => 'สร้างไม่ได้',
+ DB_ERROR_CANNOT_DELETE => 'ลบไม่ได้',
+ DB_ERROR_CANNOT_DROP => 'drop ไม่ได้',
+ DB_ERROR_CONSTRAINT => 'constraint violation',
+ DB_ERROR_DIVZERO => 'หาà¸?à¸\94à¹\89วยสูà¸?',
+ DB_ERROR_INVALID => 'ไม่ valid',
+ DB_ERROR_INVALID_DATE => 'วันที่ เวลา ไม่ valid',
+ DB_ERROR_INVALID_NUMBER => 'เลขไม่ valid',
+ DB_ERROR_MISMATCH => 'mismatch',
+ DB_ERROR_NODBSELECTED => 'à¹\84มà¹\88à¹\84à¸\94à¹\89à¹\80ลืà¸à¸?à¸?าà¸\99à¸\82à¹\89à¸à¸¡à¸¹à¸¥',
+ DB_ERROR_NOSUCHFIELD => 'ไม่มีฟีลด์นี้',
+ DB_ERROR_NOSUCHTABLE => 'ไม่มีตารางนี้',
+ DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
+ DB_ERROR_NOT_FOUND => 'ไม่พบ',
+ DB_ERROR_NOT_LOCKED => 'à¹\84มà¹\88à¹\84à¸\94à¹\89ลà¹\8aà¸à¸?',
+ DB_ERROR_SYNTAX => 'ผิด syntax',
+ DB_ERROR_UNSUPPORTED => 'ไม่ support',
+ DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
+ DB_ERROR_INVALID_DSN => 'invalid DSN',
+ DB_ERROR_CONNECT_FAILED => 'ไม่สามารถ connect',
+ 0 => 'no error', // DB_OK
+ DB_ERROR_NEED_MORE_DATA => 'ข้อมูลไม่เพียงพอ',
+ DB_ERROR_EXTENSION_NOT_FOUND=> 'ไม่พบ extension',
+ DB_ERROR_NOSUCHDB => 'ไม่มีข้อมูลนี้',
+ DB_ERROR_ACCESS_VIOLATION => 'permissions ไม่พอ'
+);
+?>
+
where name = 'free memory' and pool = 'shared pool'",
'Percentage of data cache actually in use - should be over 85%'),
- 'shared pool utilization ratio' => array('RATIOU',
- 'select round((sga.bytes/p.value)*100,2)
+ 'shared pool utilization ratio' => array('RATIOU',
+ 'select round((sga.bytes/case when p.value=0 then sga.bytes else to_number(p.value) end)*100,2)
from v$sgastat sga, v$parameter p
where sga.name = \'free memory\' and sga.pool = \'shared pool\'
and p.name = \'shared_pool_size\'',
-Description of ADODB v4.94 library import into Moodle
+Description of ADODB v4.95a library import into Moodle
Removed:
* contrib/
/*!
*/
- function &_conn($conn=null) {
- return $GLOBALS['ADODB_SESS_CONN'];
+ function &_conn($conn=null)
+ {
+ if (isset($GLOBALS['ADODB_SESS_CONN'])) {
+ $conn =& $GLOBALS['ADODB_SESS_CONN'];
+ return $conn;
+ }
+ $false = false;
+ return $false;
}
/*!
$rs =& $conn->Execute($sql,array($expireref,$key));
$qkey = $conn->qstr($key);
- $rs2 =& $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob));
+ $rs2 = $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob));
$rs = @$conn->CompleteTrans();