Documentation TYPO3 par Ameos

adodb-pdo_mysql.inc.php

00001 <?php
00002 
00003 
00004 /*
00005 V4.93 10 Oct 2006  (c) 2000-2006 John Lim (jlim#natsoft.com.my). 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 $nameQuote = '`';
00019 
00020         function _init($parentDriver)
00021         {
00022         
00023                 $parentDriver->hasTransactions = false;
00024                 $parentDriver->_bindInputArray = false;
00025                 $parentDriver->hasInsertID = true;
00026                 $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
00027         }
00028         
00029                 // dayFraction is a day in floating point
00030         function OffsetDate($dayFraction,$date=false)
00031         {               
00032                 if (!$date) $date = $this->sysDate;
00033                 
00034                 $fraction = $dayFraction * 24 * 3600;
00035                 return $date . ' + INTERVAL ' .  $fraction.' SECOND';
00036                 
00037 //              return "from_unixtime(unix_timestamp($date)+$fraction)";
00038         }
00039         
00040         function ServerInfo()
00041         {
00042                 $arr['description'] = ADOConnection::GetOne("select version()");
00043                 $arr['version'] = ADOConnection::_findvers($arr['description']);
00044                 return $arr;
00045         }
00046         
00047         function &MetaTables($ttype=false,$showSchema=false,$mask=false) 
00048         {       
00049                 $save = $this->metaTablesSQL;
00050                 if ($showSchema && is_string($showSchema)) {
00051                         $this->metaTablesSQL .= " from $showSchema";
00052                 }
00053                 
00054                 if ($mask) {
00055                         $mask = $this->qstr($mask);
00056                         $this->metaTablesSQL .= " like $mask";
00057                 }
00058                 $ret =& ADOConnection::MetaTables($ttype,$showSchema);
00059                 
00060                 $this->metaTablesSQL = $save;
00061                 return $ret;
00062         }
00063         
00064         function SetTransactionMode( $transaction_mode ) 
00065         {
00066                 $this->_transmode  = $transaction_mode;
00067                 if (empty($transaction_mode)) {
00068                         $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
00069                         return;
00070                 }
00071                 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
00072                 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
00073         }
00074         
00075         function &MetaColumns($table) 
00076         {
00077                 $this->_findschema($table,$schema);
00078                 if ($schema) {
00079                         $dbName = $this->database;
00080                         $this->SelectDB($schema);
00081                 }
00082                 global $ADODB_FETCH_MODE;
00083                 $save = $ADODB_FETCH_MODE;
00084                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
00085                 
00086                 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
00087                 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
00088                 
00089                 if ($schema) {
00090                         $this->SelectDB($dbName);
00091                 }
00092                 
00093                 if (isset($savem)) $this->SetFetchMode($savem);
00094                 $ADODB_FETCH_MODE = $save;
00095                 if (!is_object($rs)) {
00096                         $false = false;
00097                         return $false;
00098                 }
00099                         
00100                 $retarr = array();
00101                 while (!$rs->EOF){
00102                         $fld = new ADOFieldObject();
00103                         $fld->name = $rs->fields[0];
00104                         $type = $rs->fields[1];
00105                         
00106                         // split type into type(length):
00107                         $fld->scale = null;
00108                         if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
00109                                 $fld->type = $query_array[1];
00110                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00111                                 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
00112                         } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
00113                                 $fld->type = $query_array[1];
00114                                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
00115                         } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
00116                                 $fld->type = $query_array[1];
00117                                 $arr = explode(",",$query_array[2]);
00118                                 $fld->enums = $arr;
00119                                 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
00120                                 $fld->max_length = ($zlen > 0) ? $zlen : 1;
00121                         } else {
00122                                 $fld->type = $type;
00123                                 $fld->max_length = -1;
00124                         }
00125                         $fld->not_null = ($rs->fields[2] != 'YES');
00126                         $fld->primary_key = ($rs->fields[3] == 'PRI');
00127                         $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
00128                         $fld->binary = (strpos($type,'blob') !== false);
00129                         $fld->unsigned = (strpos($type,'unsigned') !== false);
00130                                 
00131                         if (!$fld->binary) {
00132                                 $d = $rs->fields[4];
00133                                 if ($d != '' && $d != 'NULL') {
00134                                         $fld->has_default = true;
00135                                         $fld->default_value = $d;
00136                                 } else {
00137                                         $fld->has_default = false;
00138                                 }
00139                         }
00140                         
00141                         if ($save == ADODB_FETCH_NUM) {
00142                                 $retarr[] = $fld;
00143                         } else {
00144                                 $retarr[strtoupper($fld->name)] = $fld;
00145                         }
00146                                 $rs->MoveNext();
00147                         }
00148                 
00149                         $rs->Close();
00150                         return $retarr; 
00151         }
00152                 
00153         
00154         // parameters use PostgreSQL convention, not MySQL
00155         function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
00156         {
00157                 $offsetStr =($offset>=0) ? "$offset," : '';
00158                 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
00159                 if ($nrows < 0) $nrows = '18446744073709551615'; 
00160                 
00161                 if ($secs)
00162                         $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
00163                 else
00164                         $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
00165                 return $rs;
00166         }
00167 }
00168 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6