]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9876 import adodb 4.95a
authorskodak <skodak>
Thu, 24 May 2007 17:14:58 +0000 (17:14 +0000)
committerskodak <skodak>
Thu, 24 May 2007 17:14:58 +0000 (17:14 +0000)
14 files changed:
lib/adodb/adodb-active-record.inc.php
lib/adodb/adodb-datadict.inc.php
lib/adodb/adodb-lib.inc.php
lib/adodb/adodb.inc.php
lib/adodb/drivers/adodb-ado5.inc.php
lib/adodb/drivers/adodb-db2.inc.php
lib/adodb/drivers/adodb-mysql.inc.php
lib/adodb/drivers/adodb-mysqli.inc.php
lib/adodb/drivers/adodb-oci8.inc.php
lib/adodb/drivers/adodb-oracle.inc.php
lib/adodb/lang/adodb_th.inc.php [new file with mode: 0644]
lib/adodb/perf/perf-oci8.inc.php
lib/adodb/readme_moodle.txt
lib/adodb/session/adodb-session2.php

index 35bf968edde3315c9b1ab02320460f3e97e647e5..29b4da2062d3eef967f659bee9f1bdedfa03dbd1 100644 (file)
 
 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;
                }
index c31edd82237ada2f960b169822df3ef2f0d9a912..f2c4661a6dd7e206ca45b4632626aac87c99ebf8 100644 (file)
@@ -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)
index 2cae67c1003ce029ee70060a06437db6735dfe7c..e4ef8124a942f4e2cf56c05ee9478c4a41b15e01 100644 (file)
@@ -968,24 +968,26 @@ function _adodb_column_sql(&$zthis, $action, $type, $fname, $fnameq, $arrFields,
                        $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;
        }
index 351d505e330d66ac165caba99ee86baf0abd134b..1e7c94ed0f32bed7603ef8aaaced254c8bd5ce90 100644 (file)
@@ -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
             $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;
    }
    
index a0e2e3ee3653d3c92408296181c03b665283fb8b..bfcf7c26e09bf6040959d10c8ed75130b590e50b 100644 (file)
@@ -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";
index 9c1882d2f6df115f40da630c08f2ea779de145bd..1a86a1d2219c3f9d62387e6ddbc10ad89a42f5b9 100644 (file)
@@ -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;
index 14d288e7e683ffa827c3458d3d692afc7fdb10b4..a9103523e810232afddd8fb54a72b49bf39e2d20 100644 (file)
@@ -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') {
index 00b53ccf83df770472e27629b26179dba90dce62..eea763438c60773d765422dcc2b109ec06b8ad16 100644 (file)
@@ -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];
index 3681876f2e48deb30324614aceef610fda40ea2a..b86c10b781cfd0508a0b550511478a9cc099c43c 100644 (file)
@@ -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') 
index 3c6dbd3014ea7cd16cbd4c3409827aad04c51a39..3c9023ad030e262189ef403cd2aa502269e532de 100644 (file)
@@ -150,7 +150,7 @@ class ADODB_oracle extends ADOConnection {
                        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);
diff --git a/lib/adodb/lang/adodb_th.inc.php b/lib/adodb/lang/adodb_th.inc.php
new file mode 100644 (file)
index 0000000..745441c
--- /dev/null
@@ -0,0 +1,34 @@
+<?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 ไม่พอ'
+);
+?>
+
index a4bcda67fdfef3a5b5633040665aac07de08d870..19df7a2b44c4d2fab2437a8c3874fb95325d5f74 100644 (file)
@@ -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\'',
index f4db42b3a8d1bee618d7881c6038214485539e22..6c6267ebf537b91b0cd5ff97585fd8baeda785bb 100644 (file)
@@ -1,4 +1,4 @@
-Description of ADODB v4.94 library import into Moodle
+Description of ADODB v4.95a library import into Moodle
 
 Removed:
  * contrib/
index c5932b64aebf46125daae3494a24de5b00085548..e4ac07d3d857570228b6aec8af3bb44953f98320 100644 (file)
@@ -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();