[TASK] Update ADOdb to 5.18
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-pdo_mysql.inc.php
1 <?php
2
3
4 /*
5 V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved.
6 Released under both BSD license and Lesser GPL library license.
7 Whenever there is any discrepancy between the two licenses,
8 the BSD license will take precedence.
9 Set tabs to 8.
10
11 */
12
13 class ADODB_pdo_mysql extends ADODB_pdo {
14 var $metaTablesSQL = "SHOW TABLES";
15 var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
16 var $sysDate = 'CURDATE()';
17 var $sysTimeStamp = 'NOW()';
18 var $hasGenID = true;
19 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
20 var $_dropSeqSQL = "drop table %s";
21 var $fmtTimeStamp = "'Y-m-d, H:i:s'";
22 var $nameQuote = '`';
23
24 function _init($parentDriver)
25 {
26
27 $parentDriver->hasTransactions = false;
28 #$parentDriver->_bindInputArray = false;
29 $parentDriver->hasInsertID = true;
30 $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
31 }
32
33 // dayFraction is a day in floating point
34 function OffsetDate($dayFraction,$date=false)
35 {
36 if (!$date) $date = $this->sysDate;
37
38 $fraction = $dayFraction * 24 * 3600;
39 return $date . ' + INTERVAL ' . $fraction.' SECOND';
40
41 // return "from_unixtime(unix_timestamp($date)+$fraction)";
42 }
43
44 function Concat()
45 {
46 $s = "";
47 $arr = func_get_args();
48
49 // suggestion by andrew005#mnogo.ru
50 $s = implode(',',$arr);
51 if (strlen($s) > 0) return "CONCAT($s)"; return '';
52 }
53
54 function ServerInfo()
55 {
56 $arr['description'] = ADOConnection::GetOne("select version()");
57 $arr['version'] = ADOConnection::_findvers($arr['description']);
58 return $arr;
59 }
60
61 function MetaTables($ttype=false,$showSchema=false,$mask=false)
62 {
63 $save = $this->metaTablesSQL;
64 if ($showSchema && is_string($showSchema)) {
65 $this->metaTablesSQL .= " from $showSchema";
66 }
67
68 if ($mask) {
69 $mask = $this->qstr($mask);
70 $this->metaTablesSQL .= " like $mask";
71 }
72 $ret = ADOConnection::MetaTables($ttype,$showSchema);
73
74 $this->metaTablesSQL = $save;
75 return $ret;
76 }
77
78 function SetTransactionMode( $transaction_mode )
79 {
80 $this->_transmode = $transaction_mode;
81 if (empty($transaction_mode)) {
82 $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
83 return;
84 }
85 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
86 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
87 }
88
89 function MetaColumns($table,$normalize=true)
90 {
91 $this->_findschema($table,$schema);
92 if ($schema) {
93 $dbName = $this->database;
94 $this->SelectDB($schema);
95 }
96 global $ADODB_FETCH_MODE;
97 $save = $ADODB_FETCH_MODE;
98 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
99
100 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
101 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
102
103 if ($schema) {
104 $this->SelectDB($dbName);
105 }
106
107 if (isset($savem)) $this->SetFetchMode($savem);
108 $ADODB_FETCH_MODE = $save;
109 if (!is_object($rs)) {
110 $false = false;
111 return $false;
112 }
113
114 $retarr = array();
115 while (!$rs->EOF){
116 $fld = new ADOFieldObject();
117 $fld->name = $rs->fields[0];
118 $type = $rs->fields[1];
119
120 // split type into type(length):
121 $fld->scale = null;
122 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
123 $fld->type = $query_array[1];
124 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
125 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
126 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
127 $fld->type = $query_array[1];
128 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
129 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
130 $fld->type = $query_array[1];
131 $arr = explode(",",$query_array[2]);
132 $fld->enums = $arr;
133 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
134 $fld->max_length = ($zlen > 0) ? $zlen : 1;
135 } else {
136 $fld->type = $type;
137 $fld->max_length = -1;
138 }
139 $fld->not_null = ($rs->fields[2] != 'YES');
140 $fld->primary_key = ($rs->fields[3] == 'PRI');
141 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
142 $fld->binary = (strpos($type,'blob') !== false);
143 $fld->unsigned = (strpos($type,'unsigned') !== false);
144
145 if (!$fld->binary) {
146 $d = $rs->fields[4];
147 if ($d != '' && $d != 'NULL') {
148 $fld->has_default = true;
149 $fld->default_value = $d;
150 } else {
151 $fld->has_default = false;
152 }
153 }
154
155 if ($save == ADODB_FETCH_NUM) {
156 $retarr[] = $fld;
157 } else {
158 $retarr[strtoupper($fld->name)] = $fld;
159 }
160 $rs->MoveNext();
161 }
162
163 $rs->Close();
164 return $retarr;
165 }
166
167
168 // parameters use PostgreSQL convention, not MySQL
169 function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
170 {
171 $offsetStr =($offset>=0) ? "$offset," : '';
172 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
173 if ($nrows < 0) $nrows = '18446744073709551615';
174
175 if ($secs)
176 $rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
177 else
178 $rs = $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
179 return $rs;
180 }
181 }
182 ?>