Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/adodb/drivers/adodb-pdo_mysql.inc.php
Go to the documentation of this file.
00001 <?php
00002 
00003 
00004 /*
00005 V5.14 8 Sept 2011  (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
00006   Released under both BSD license and Lesser GPL library license. 
00007   Whenever there is any discrepancy between the two licenses, 
00008   the BSD license will take precedence.
00009   Set tabs to 8.
00010  
00011 */ 
00012 
00013 class ADODB_pdo_mysql extends ADODB_pdo {
00014         var $metaTablesSQL = "SHOW TABLES";     
00015         var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
00016         var $sysDate = 'CURDATE()';
00017         var $sysTimeStamp = 'NOW()';
00018         var $hasGenID = true;
00019         var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
00020         var $_dropSeqSQL = "drop table %s";
00021         var $fmtTimeStamp = "'Y-m-d, H:i:s'";
00022         var $nameQuote = '`';
00023 
00024         function _init($parentDriver)
00025         {
00026         
00027                 $parentDriver->hasTransactions = false;
00028                 #$parentDriver->_bindInputArray = false;
00029                 $parentDriver->hasInsertID = true;
00030                 $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
00031         }
00032         
00033                 // dayFraction is a day in floating point
00034         function OffsetDate($dayFraction,$date=false)
00035         {               
00036                 if (!$date) $date = $this->sysDate;
00037                 
00038                 $fraction = $dayFraction * 24 * 3600;
00039                 return $date . ' + INTERVAL ' .  $fraction.' SECOND';
00040                 
00041 //              return "from_unixtime(unix_timestamp($date)+$fraction)";
00042         }
00043         
00044         function Concat() 
00045         {       
00046                 $s = "";
00047                 $arr = func_get_args();
00048 
00049                 // suggestion by andrew005#mnogo.ru
00050                 $s = implode(',',$arr);
00051                 if (strlen($s) > 0) return "CONCAT($s)"; return ''; 
00052         }
00053         
00054         function ServerInfo()
00055         {
00056                 $arr['description'] = ADOConnection::GetOne("select version()");
00057                 $arr['version'] = ADOConnection::_findvers($arr['description']);
00058                 return $arr;
00059         }
00060         
00061         function MetaTables($ttype=false,$showSchema=false,$mask=false) 
00062         {       
00063                 $save = $this->metaTablesSQL;
00064                 if ($showSchema && is_string($showSchema)) {
00065                         $this->metaTablesSQL .= " from $showSchema";
00066                 }
00067                 
00068                 if ($mask) {
00069                         $mask = $this->qstr($mask);
00070                         $this->metaTablesSQL .= " like $mask";
00071                 }
00072                 $ret = ADOConnection::MetaTables($ttype,$showSchema);
00073                 
00074                 $this->metaTablesSQL = $save;
00075                 return $ret;
00076         }
00077         
00078         function SetTransactionMode( $transaction_mode ) 
00079         {
00080                 $this->_transmode  = $transaction_mode;
00081                 if (empty($transaction_mode)) {
00082                         $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
00083                         return;
00084                 }
00085                 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
00086                 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
00087         }
00088         
00089         function MetaColumns($table,$normalize=true)
00090         {
00091                 $this->_findschema($table,$schema);
00092                 if ($schema) {
00093                         $dbName = $this->database;
00094                         $this->SelectDB($schema);
00095                 }
00096                 global $ADODB_FETCH_MODE;
00097                 $save = $ADODB_FETCH_MODE;
00098                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00099                 
00100                 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
00101                 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
00102                 
00103                 if ($schema) {
00104                         $this->SelectDB($dbName);
00105                 }
00106                 
00107                 if (isset($savem)) $this->SetFetchMode($savem);
00108                 $ADODB_FETCH_MODE = $save;
00109                 if (!is_object($rs)) {
00110                         $false = false;
00111                         return $false;
00112                 }
00113                         
00114                 $retarr = array();
00115                 while (!$rs->EOF){
00116                         $fld = new ADOFieldObject();
00117                         $fld->name = $rs->fields[0];
00118                         $type = $rs->fields[1];
00119                         
00120                         // split type into type(length):
00121                         $fld->scale = null;
00122                         if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
00123                                 $fld->type = $query_array[1];
00124                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00125                                 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
00126                         } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
00127                                 $fld->type = $query_array[1];
00128                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00129                         } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
00130                                 $fld->type = $query_array[1];
00131                                 $arr = explode(",",$query_array[2]);
00132                                 $fld->enums = $arr;
00133                                 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
00134                                 $fld->max_length = ($zlen > 0) ? $zlen : 1;
00135                         } else {
00136                                 $fld->type = $type;
00137                                 $fld->max_length = -1;
00138                         }
00139                         $fld->not_null = ($rs->fields[2] != 'YES');
00140                         $fld->primary_key = ($rs->fields[3] == 'PRI');
00141                         $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
00142                         $fld->binary = (strpos($type,'blob') !== false);
00143                         $fld->unsigned = (strpos($type,'unsigned') !== false);
00144                                 
00145                         if (!$fld->binary) {
00146                                 $d = $rs->fields[4];
00147                                 if ($d != '' && $d != 'NULL') {
00148                                         $fld->has_default = true;
00149                                         $fld->default_value = $d;
00150                                 } else {
00151                                         $fld->has_default = false;
00152                                 }
00153                         }
00154                         
00155                         if ($save == ADODB_FETCH_NUM) {
00156                                 $retarr[] = $fld;
00157                         } else {
00158                                 $retarr[strtoupper($fld->name)] = $fld;
00159                         }
00160                                 $rs->MoveNext();
00161                         }
00162                 
00163                         $rs->Close();
00164                         return $retarr; 
00165         }
00166                 
00167         
00168         // parameters use PostgreSQL convention, not MySQL
00169         function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
00170         {
00171                 $offsetStr =($offset>=0) ? "$offset," : '';
00172                 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
00173                 if ($nrows < 0) $nrows = '18446744073709551615'; 
00174                 
00175                 if ($secs)
00176                         $rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
00177                 else
00178                         $rs = $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
00179                 return $rs;
00180         }
00181 }
00182 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations