fix Row size too large error, change varchar(255) to TEXT
[openemr.git] / gacl / adodb / drivers / adodb-pdo_mysql.inc.php
blobe4ec76660e978bc9d6ec6d84a88babacbf9b246d
1 <?php
4 /*
5 V4.92a 29 Aug 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.
11 */
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 $nameQuote = '`';
20 function _init($parentDriver)
23 $parentDriver->hasTransactions = false;
24 $parentDriver->_bindInputArray = false;
25 $parentDriver->hasInsertID = true;
26 $parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
29 // dayFraction is a day in floating point
30 function OffsetDate($dayFraction,$date=false)
32 if (!$date) $date = $this->sysDate;
34 $fraction = $dayFraction * 24 * 3600;
35 return $date . ' + INTERVAL ' . $fraction.' SECOND';
37 // return "from_unixtime(unix_timestamp($date)+$fraction)";
40 function ServerInfo()
42 $arr['description'] = ADOConnection::GetOne("select version()");
43 $arr['version'] = ADOConnection::_findvers($arr['description']);
44 return $arr;
47 function &MetaTables($ttype=false,$showSchema=false,$mask=false)
49 $save = $this->metaTablesSQL;
50 if ($showSchema && is_string($showSchema)) {
51 $this->metaTablesSQL .= " from $showSchema";
54 if ($mask) {
55 $mask = $this->qstr($mask);
56 $this->metaTablesSQL .= " like $mask";
58 $ret =& ADOConnection::MetaTables($ttype,$showSchema);
60 $this->metaTablesSQL = $save;
61 return $ret;
64 function SetTransactionMode( $transaction_mode )
66 $this->_transmode = $transaction_mode;
67 if (empty($transaction_mode)) {
68 $this->Execute('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ');
69 return;
71 if (!stristr($transaction_mode,'isolation')) $transaction_mode = 'ISOLATION LEVEL '.$transaction_mode;
72 $this->Execute("SET SESSION TRANSACTION ".$transaction_mode);
75 function &MetaColumns($table)
77 $this->_findschema($table,$schema);
78 if ($schema) {
79 $dbName = $this->database;
80 $this->SelectDB($schema);
82 global $ADODB_FETCH_MODE;
83 $save = $ADODB_FETCH_MODE;
84 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
86 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
87 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
89 if ($schema) {
90 $this->SelectDB($dbName);
93 if (isset($savem)) $this->SetFetchMode($savem);
94 $ADODB_FETCH_MODE = $save;
95 if (!is_object($rs)) {
96 $false = false;
97 return $false;
100 $retarr = array();
101 while (!$rs->EOF){
102 $fld = new ADOFieldObject();
103 $fld->name = $rs->fields[0];
104 $type = $rs->fields[1];
106 // split type into type(length):
107 $fld->scale = null;
108 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
109 $fld->type = $query_array[1];
110 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
111 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
112 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
113 $fld->type = $query_array[1];
114 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
115 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
116 $fld->type = $query_array[1];
117 $arr = explode(",",$query_array[2]);
118 $fld->enums = $arr;
119 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
120 $fld->max_length = ($zlen > 0) ? $zlen : 1;
121 } else {
122 $fld->type = $type;
123 $fld->max_length = -1;
125 $fld->not_null = ($rs->fields[2] != 'YES');
126 $fld->primary_key = ($rs->fields[3] == 'PRI');
127 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
128 $fld->binary = (strpos($type,'blob') !== false);
129 $fld->unsigned = (strpos($type,'unsigned') !== false);
131 if (!$fld->binary) {
132 $d = $rs->fields[4];
133 if ($d != '' && $d != 'NULL') {
134 $fld->has_default = true;
135 $fld->default_value = $d;
136 } else {
137 $fld->has_default = false;
141 if ($save == ADODB_FETCH_NUM) {
142 $retarr[] = $fld;
143 } else {
144 $retarr[strtoupper($fld->name)] = $fld;
146 $rs->MoveNext();
149 $rs->Close();
150 return $retarr;
154 // parameters use PostgreSQL convention, not MySQL
155 function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
157 $offsetStr =($offset>=0) ? "$offset," : '';
158 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
159 if ($nrows < 0) $nrows = '18446744073709551615';
161 if ($secs)
162 $rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr$nrows",$inputarr);
163 else
164 $rs =& $this->Execute($sql." LIMIT $offsetStr$nrows",$inputarr);
165 return $rs;