From: skodak Date: Thu, 24 May 2007 17:14:58 +0000 (+0000) Subject: MDL-9876 import adodb 4.95a X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=98518b6221d50cdff212a3599f575f838cede0db;p=moodle.git MDL-9876 import adodb 4.95a --- diff --git a/lib/adodb/adodb-active-record.inc.php b/lib/adodb/adodb-active-record.inc.php index 35bf968edd..29b4da2062 100644 --- a/lib/adodb/adodb-active-record.inc.php +++ b/lib/adodb/adodb-active-record.inc.php @@ -18,10 +18,11 @@ 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 @@ -322,6 +323,8 @@ class ADODB_Active_Record { // set a numeric array (using natural table field ordering) as object properties function Set(&$row) { + global $ACTIVE_RECORD_SAFETY; + $db =& $this->DB(); if (!$row) { @@ -332,7 +335,7 @@ class ADODB_Active_Record { $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; } diff --git a/lib/adodb/adodb-datadict.inc.php b/lib/adodb/adodb-datadict.inc.php index c31edd8223..f2c4661a6d 100644 --- a/lib/adodb/adodb-datadict.inc.php +++ b/lib/adodb/adodb-datadict.inc.php @@ -215,9 +215,117 @@ class ADODB_DataDict { 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) diff --git a/lib/adodb/adodb-lib.inc.php b/lib/adodb/adodb-lib.inc.php index 2cae67c100..e4ef8124a9 100644 --- a/lib/adodb/adodb-lib.inc.php +++ b/lib/adodb/adodb-lib.inc.php @@ -968,24 +968,26 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields, $val = $zthis->DBDate($arrFields[$fname]); break; - case "T": + + case "T": $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; } diff --git a/lib/adodb/adodb.inc.php b/lib/adodb/adodb.inc.php index 351d505e33..1e7c94ed0f 100644 --- a/lib/adodb/adodb.inc.php +++ b/lib/adodb/adodb.inc.php @@ -2,7 +2,7 @@ /* * 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 @@ -1576,7 +1576,7 @@ $dir = $ADODB_CACHE_DIR; if ($this->debug) { - ADOConnection::outp( "CacheFlush: $dir
\n", $this->_dirFlush($dir),"
"); + ADOConnection::outp( "CacheFlush: $dir
\n". $this->_dirFlush($dir)."
"); } else { $this->_dirFlush($dir); } @@ -1599,18 +1599,18 @@ * 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; } diff --git a/lib/adodb/drivers/adodb-ado5.inc.php b/lib/adodb/drivers/adodb-ado5.inc.php index a0e2e3ee36..bfcf7c26e0 100644 --- a/lib/adodb/drivers/adodb-ado5.inc.php +++ b/lib/adodb/drivers/adodb-ado5.inc.php @@ -101,9 +101,6 @@ class ADODB_ado extends ADOConnection { 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"; diff --git a/lib/adodb/drivers/adodb-db2.inc.php b/lib/adodb/drivers/adodb-db2.inc.php index 9c1882d2f6..1a86a1d221 100644 --- a/lib/adodb/drivers/adodb-db2.inc.php +++ b/lib/adodb/drivers/adodb-db2.inc.php @@ -33,7 +33,7 @@ class ADODB_db2 extends ADOConnection { 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; diff --git a/lib/adodb/drivers/adodb-mysql.inc.php b/lib/adodb/drivers/adodb-mysql.inc.php index 14d288e7e6..a9103523e8 100644 --- a/lib/adodb/drivers/adodb-mysql.inc.php +++ b/lib/adodb/drivers/adodb-mysql.inc.php @@ -184,6 +184,7 @@ class ADODB_mysql extends ADOConnection { // 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"; @@ -212,12 +213,16 @@ class ADODB_mysql extends ADOConnection { 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; @@ -442,8 +447,9 @@ class ADODB_mysql extends ADOConnection { $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') { diff --git a/lib/adodb/drivers/adodb-mysqli.inc.php b/lib/adodb/drivers/adodb-mysqli.inc.php index 00b53ccf83..eea763438c 100644 --- a/lib/adodb/drivers/adodb-mysqli.inc.php +++ b/lib/adodb/drivers/adodb-mysqli.inc.php @@ -273,13 +273,17 @@ class ADODB_mysqli extends ADOConnection { 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; } @@ -559,6 +563,7 @@ class ADODB_mysqli extends ADOConnection { $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]; diff --git a/lib/adodb/drivers/adodb-oci8.inc.php b/lib/adodb/drivers/adodb-oci8.inc.php index 3681876f2e..b86c10b781 100644 --- a/lib/adodb/drivers/adodb-oci8.inc.php +++ b/lib/adodb/drivers/adodb-oci8.inc.php @@ -83,6 +83,7 @@ class ADODB_oci8 extends ADOConnection { 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(); @@ -276,7 +277,7 @@ NATSOFT.DOMAIN = 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) @@ -300,7 +301,7 @@ NATSOFT.DOMAIN = { 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') diff --git a/lib/adodb/drivers/adodb-oracle.inc.php b/lib/adodb/drivers/adodb-oracle.inc.php index 3c6dbd3014..3c9023ad03 100644 --- a/lib/adodb/drivers/adodb-oracle.inc.php +++ b/lib/adodb/drivers/adodb-oracle.inc.php @@ -150,7 +150,7 @@ class ADODB_oracle extends ADOConnection { if ($argDatabasename) $argUsername .= "@$argDatabasename"; //if ($argHostname) print "

Connect: 1st argument should be left blank for $this->databaseType

"; - if ($mode = 1) + if ($mode == 1) $this->_connectionID = ora_plogon($argUsername,$argPassword); else $this->_connectionID = ora_logon($argUsername,$argPassword); diff --git a/lib/adodb/lang/adodb_th.inc.php b/lib/adodb/lang/adodb_th.inc.php new file mode 100644 index 0000000000..745441cc1b --- /dev/null +++ b/lib/adodb/lang/adodb_th.inc.php @@ -0,0 +1,34 @@ + +$ADODB_LANG_ARRAY = array ( + 'LANG' => 'th', + DB_ERROR => 'error ไม่รู้สาเหตุ', + DB_ERROR_ALREADY_EXISTS => 'มีà¹?ล้ว', + DB_ERROR_CANNOT_CREATE => 'สร้างไม่ได้', + DB_ERROR_CANNOT_DELETE => 'ลบไม่ได้', + DB_ERROR_CANNOT_DROP => 'drop ไม่ได้', + DB_ERROR_CONSTRAINT => 'constraint violation', + DB_ERROR_DIVZERO => 'หาà¸?ด้วยสูà¸?', + DB_ERROR_INVALID => 'ไม่ valid', + DB_ERROR_INVALID_DATE => 'วันที่ เวลา ไม่ valid', + DB_ERROR_INVALID_NUMBER => 'เลขไม่ valid', + DB_ERROR_MISMATCH => 'mismatch', + DB_ERROR_NODBSELECTED => 'ไม่ได้เลือà¸?à¸?านข้อมูล', + DB_ERROR_NOSUCHFIELD => 'ไม่มีฟีลด์นี้', + DB_ERROR_NOSUCHTABLE => 'ไม่มีตารางนี้', + DB_ERROR_NOT_CAPABLE => 'DB backend not capable', + DB_ERROR_NOT_FOUND => 'ไม่พบ', + DB_ERROR_NOT_LOCKED => 'ไม่ได้ล๊อà¸?', + 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 ไม่พอ' +); +?> + diff --git a/lib/adodb/perf/perf-oci8.inc.php b/lib/adodb/perf/perf-oci8.inc.php index a4bcda67fd..19df7a2b44 100644 --- a/lib/adodb/perf/perf-oci8.inc.php +++ b/lib/adodb/perf/perf-oci8.inc.php @@ -109,8 +109,8 @@ AND b.name = 'sorts (memory)'", 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\'', diff --git a/lib/adodb/readme_moodle.txt b/lib/adodb/readme_moodle.txt index f4db42b3a8..6c6267ebf5 100644 --- a/lib/adodb/readme_moodle.txt +++ b/lib/adodb/readme_moodle.txt @@ -1,4 +1,4 @@ -Description of ADODB v4.94 library import into Moodle +Description of ADODB v4.95a library import into Moodle Removed: * contrib/ diff --git a/lib/adodb/session/adodb-session2.php b/lib/adodb/session/adodb-session2.php index c5932b64ae..e4ac07d3d8 100644 --- a/lib/adodb/session/adodb-session2.php +++ b/lib/adodb/session/adodb-session2.php @@ -443,8 +443,14 @@ class ADODB_Session { /*! */ - 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; } /*! @@ -768,7 +774,7 @@ class ADODB_Session { $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();