ChangeLog
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-pdo_mysql.inc.php
1 <?php
2
3
4 /*
5 V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). 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 $_bindInputArray = false;
17 var $sysDate = 'CURDATE()';
18 var $sysTimeStamp = 'NOW()';
19
20 function _init($parentDriver)
21 {
22
23 $parentDriver->hasTransactions = false;
24 $parentDriver->_bindInputArray = true;
25 $parentDriver->hasInsertID = true;
26 $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
27 }
28
29 function ServerInfo()
30 {
31 $arr['description'] = ADOConnection::GetOne("select version()");
32 $arr['version'] = ADOConnection::_findvers($arr['description']);
33 return $arr;
34 }
35
36 function &MetaTables($ttype=false,$showSchema=false,$mask=false)
37 {
38 $save = $this->metaTablesSQL;
39 if ($showSchema && is_string($showSchema)) {
40 $this->metaTablesSQL .= " from $showSchema";
41 }
42
43 if ($mask) {
44 $mask = $this->qstr($mask);
45 $this->metaTablesSQL .= " like $mask";
46 }
47 $ret =& ADOConnection::MetaTables($ttype,$showSchema);
48
49 $this->metaTablesSQL = $save;
50 return $ret;
51 }
52
53 function SetTransactionMode( $transaction_mode )
54 {
55 $this->_transmode = $transaction_mode;
56 if (empty($transaction_mode)) {
57 $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
58 return;
59 }
60 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
61 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
62 }
63
64 function &MetaColumns($table)
65 {
66 $this->_findschema($table,$schema);
67 if ($schema) {
68 $dbName = $this->database;
69 $this->SelectDB($schema);
70 }
71 global $ADODB_FETCH_MODE;
72 $save = $ADODB_FETCH_MODE;
73 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
74
75 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
76 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
77
78 if ($schema) {
79 $this->SelectDB($dbName);
80 }
81
82 if (isset($savem)) $this->SetFetchMode($savem);
83 $ADODB_FETCH_MODE = $save;
84 if (!is_object($rs)) {
85 $false = false;
86 return $false;
87 }
88
89 $retarr = array();
90 while (!$rs->EOF){
91 $fld = new ADOFieldObject();
92 $fld->name = $rs->fields[0];
93 $type = $rs->fields[1];
94
95 // split type into type(length):
96 $fld->scale = null;
97 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
98 $fld->type = $query_array[1];
99 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
100 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
101 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
102 $fld->type = $query_array[1];
103 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
104 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
105 $fld->type = $query_array[1];
106 $arr = explode(",",$query_array[2]);
107 $fld->enums = $arr;
108 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
109 $fld->max_length = ($zlen > 0) ? $zlen : 1;
110 } else {
111 $fld->type = $type;
112 $fld->max_length = -1;
113 }
114 $fld->not_null = ($rs->fields[2] != 'YES');
115 $fld->primary_key = ($rs->fields[3] == 'PRI');
116 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
117 $fld->binary = (strpos($type,'blob') !== false);
118 $fld->unsigned = (strpos($type,'unsigned') !== false);
119
120 if (!$fld->binary) {
121 $d = $rs->fields[4];
122 if ($d != '' && $d != 'NULL') {
123 $fld->has_default = true;
124 $fld->default_value = $d;
125 } else {
126 $fld->has_default = false;
127 }
128 }
129
130 if ($save == ADODB_FETCH_NUM) {
131 $retarr[] = $fld;
132 } else {
133 $retarr[strtoupper($fld->name)] = $fld;
134 }
135 $rs->MoveNext();
136 }
137
138 $rs->Close();
139 return $retarr;
140 }
141
142
143 // parameters use PostgreSQL convention, not MySQL
144 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
145 {
146 $offsetStr =($offset>=0) ? "$offset," : '';
147 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
148 if ($nrows < 0) $nrows = '18446744073709551615';
149
150 if ($secs)
151 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
152 else
153 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
154 return $rs;
155 }
156 }
157 ?>