]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/drivers/adodb-mysqli.inc.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / drivers / adodb-mysqli.inc.php
1 <?php
2 /*
3 V4.22 15 Apr 2004  (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
4   Released under both BSD license and Lesser GPL library license.
5   Whenever there is any discrepancy between the two licenses,
6   the BSD license will take precedence.
7   Set tabs to 8.
8
9   MySQL code that does not support transactions. Use mysqlt if you need transactions.
10   Requires mysql client. Works on Windows and Unix.
11
12 21 October 2003: MySQLi extension implementation by Arjen de Rijke (a.de.rijke@xs4all.nl)
13 Based on adodb 3.40
14 */
15 if (!defined("_ADODB_MYSQL_LAYER")) {
16     define("_ADODB_MYSQL_LAYER", 1);
17
18     class ADODB_mysqli extends ADOConnection
19     {
20         var $databaseType = 'mysqli';
21         var $dataProvider = 'native';
22         var $hasInsertID = true;
23         var $hasAffectedRows = true;
24         var $metaTablesSQL = "SHOW TABLES";
25         var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
26         var $fmtTimeStamp = "'Y-m-d H:i:s'";
27         var $hasLimit = true;
28         var $hasMoveFirst = true;
29         var $hasGenID = true;
30         var $upperCase = 'upper';
31         var $isoDates = true; // accepts dates in ISO format
32         var $sysDate = 'CURDATE()';
33         var $sysTimeStamp = 'NOW()';
34         var $hasTransactions = false;
35         var $forceNewConnect = false;
36         var $poorAffectedRows = true;
37         var $clientFlags = 0;
38         var $executeOnly = true;
39         var $substr = "substring";
40         var $nameQuote = '`'; /// string to use to quote identifiers and names
41         //var $_bindInputArray = true;
42
43         function ADODB_mysqli()
44         {
45             if (!extension_loaded("mysqli")) {
46                 trigger_error("You must have the MySQLi extension.", E_USER_ERROR);
47             }
48         }
49
50         function IfNull($field, $ifNull)
51         {
52             return " IFNULL($field, $ifNull) "; // if MySQL
53         }
54
55         function ServerInfo()
56         {
57             $arr['description'] = $this->GetOne("select version()");
58             $arr['version'] = ADOConnection::_findvers($arr['description']);
59             return $arr;
60         }
61
62         function BeginTrans()
63         {
64             if ($this->transOff) return true;
65             $this->transCnt += 1;
66             $this->Execute('SET AUTOCOMMIT=0');
67             $this->Execute('BEGIN');
68             return true;
69         }
70
71         function CommitTrans($ok = true)
72         {
73             if ($this->transOff) return true;
74             if (!$ok) return $this->RollbackTrans();
75
76             if ($this->transCnt) $this->transCnt -= 1;
77             $this->Execute('COMMIT');
78             $this->Execute('SET AUTOCOMMIT=1');
79             return true;
80         }
81
82         function RollbackTrans()
83         {
84             if ($this->transOff) return true;
85             if ($this->transCnt) $this->transCnt -= 1;
86             $this->Execute('ROLLBACK');
87             $this->Execute('SET AUTOCOMMIT=1');
88             return true;
89         }
90
91         // if magic quotes disabled, use mysql_real_escape_string()
92         // From readme.htm:
93         // Quotes a string to be sent to the database. The $magic_quotes_enabled
94         // parameter may look funny, but the idea is if you are quoting a
95         // string extracted from a POST/GET variable, then
96         // pass get_magic_quotes_gpc() as the second parameter. This will
97         // ensure that the variable is not quoted twice, once by qstr and once
98         // by the magic_quotes_gpc.
99         //
100         //Eg. $s = $db->qstr(HTTP_GET_VARS['name'],get_magic_quotes_gpc());
101         function qstr($s, $magic_quotes = false)
102         {
103             if (!$magic_quotes) {
104                 if (ADODB_PHPVER >= 0x5000) {
105                     //  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
106                     return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'";
107                 } else {
108                     trigger_error("phpver < 5 not implemented", E_USER_ERROR);
109                 }
110
111                 if ($this->replaceQuote[0] == '\\') {
112                     $s = adodb_str_replace(array('\\', "\0"), array('\\\\', "\\\0"), $s);
113                 }
114                 return "'" . str_replace("'", $this->replaceQuote, $s) . "'";
115             }
116             // undo magic quotes for "
117             $s = str_replace('\\"', '"', $s);
118             return "'$s'";
119         }
120
121         function _insertid()
122         {
123 //        $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
124             $result = @mysqli_insert_id($this->_connectionID);
125             if ($result == -1) {
126                 if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : " . $this->ErrorMsg());
127             }
128             return $result;
129         }
130
131         // Only works for INSERT, UPDATE and DELETE query's
132         function _affectedrows()
133         {
134             //  $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
135             $result = @mysqli_affected_rows($this->_connectionID);
136             if ($result == -1) {
137                 if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : " . $this->ErrorMsg());
138             }
139             return $result;
140         }
141
142         // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
143         // Reference on Last_Insert_ID on the recommended way to simulate sequences
144         var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
145         var $_genSeqSQL = "create table %s (id int not null)";
146         var $_genSeq2SQL = "insert into %s values (%s)";
147         var $_dropSeqSQL = "drop table %s";
148
149         function CreateSequence($seqname = 'adodbseq', $startID = 1)
150         {
151             if (empty($this->_genSeqSQL)) return false;
152             $u = strtoupper($seqname);
153
154             $ok = $this->Execute(sprintf($this->_genSeqSQL, $seqname));
155             if (!$ok) return false;
156             return $this->Execute(sprintf($this->_genSeq2SQL, $seqname, $startID - 1));
157         }
158
159         function GenID($seqname = 'adodbseq', $startID = 1)
160         {
161             // post-nuke sets hasGenID to false
162             if (!$this->hasGenID) return false;
163
164             $getnext = sprintf($this->_genIDSQL, $seqname);
165             $holdtransOK = $this->_transOK; // save the current status
166             $rs = @$this->Execute($getnext);
167             if (!$rs) {
168                 if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
169                 $u = strtoupper($seqname);
170                 $this->Execute(sprintf($this->_genSeqSQL, $seqname));
171                 $this->Execute(sprintf($this->_genSeq2SQL, $seqname, $startID - 1));
172                 $rs = $this->Execute($getnext);
173             }
174             $this->genID = mysqli_insert_id($this->_connectionID);
175
176             if ($rs) $rs->Close();
177
178             return $this->genID;
179         }
180
181         function &MetaDatabases()
182         {
183             $query = "SHOW DATABASES";
184             $ret =& $this->Execute($query);
185             return $ret;
186         }
187
188
189         function &MetaIndexes($table, $primary = FALSE)
190         {
191             // save old fetch mode
192             global $ADODB_FETCH_MODE;
193
194             $save = $ADODB_FETCH_MODE;
195             $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
196             if ($this->fetchMode !== FALSE) {
197                 $savem = $this->SetFetchMode(FALSE);
198             }
199
200             // get index details
201             $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s', $table));
202
203             // restore fetchmode
204             if (isset($savem)) {
205                 $this->SetFetchMode($savem);
206             }
207             $ADODB_FETCH_MODE = $save;
208
209             if (!is_object($rs)) {
210                 return FALSE;
211             }
212
213             $indexes = array();
214
215             // parse index data into array
216             while ($row = $rs->FetchRow()) {
217                 if ($primary == FALSE AND $row[2] == 'PRIMARY') {
218                     continue;
219                 }
220
221                 if (!isset($indexes[$row[2]])) {
222                     $indexes[$row[2]] = array(
223                         'unique' => ($row[1] == 0),
224                         'columns' => array()
225                     );
226                 }
227
228                 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
229             }
230
231             // sort columns by order in the index
232             foreach (array_keys($indexes) as $index) {
233                 ksort($indexes[$index]['columns']);
234             }
235
236             return $indexes;
237         }
238
239
240         // Format date column in sql string given an input format that understands Y M D
241         function SQLDate($fmt, $col = false)
242         {
243             if (!$col) $col = $this->sysTimeStamp;
244             $s = 'DATE_FORMAT(' . $col . ",'";
245             $concat = false;
246             $len = strlen($fmt);
247             for ($i = 0; $i < $len; $i++) {
248                 $ch = $fmt[$i];
249                 switch ($ch) {
250                     case 'Y':
251                     case 'y':
252                         $s .= '%Y';
253                         break;
254                     case 'Q':
255                     case 'q':
256                         $s .= "'),Quarter($col)";
257
258                         if ($len > $i + 1) $s .= ",DATE_FORMAT($col,'";
259                         else $s .= ",('";
260                         $concat = true;
261                         break;
262                     case 'M':
263                         $s .= '%b';
264                         break;
265
266                     case 'm':
267                         $s .= '%m';
268                         break;
269                     case 'D':
270                     case 'd':
271                         $s .= '%d';
272                         break;
273
274                     case 'H':
275                         $s .= '%H';
276                         break;
277
278                     case 'h':
279                         $s .= '%I';
280                         break;
281
282                     case 'i':
283                         $s .= '%i';
284                         break;
285
286                     case 's':
287                         $s .= '%s';
288                         break;
289
290                     case 'a':
291                     case 'A':
292                         $s .= '%p';
293                         break;
294
295                     default:
296
297                         if ($ch == '\\') {
298                             $i++;
299                             $ch = substr($fmt, $i, 1);
300                         }
301                         $s .= $ch;
302                         break;
303                 }
304             }
305             $s .= "')";
306             if ($concat) $s = "CONCAT($s)";
307             return $s;
308         }
309
310         // returns concatenated string
311         // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
312         function Concat()
313         {
314             $s = "";
315             $arr = func_get_args();
316
317             // suggestion by andrew005@mnogo.ru
318             $s = implode(',', $arr);
319             if (strlen($s) > 0) return "CONCAT($s)";
320             else return '';
321         }
322
323         // dayFraction is a day in floating point
324         function OffsetDate($dayFraction, $date = false)
325         {
326             if (!$date)
327                 $date = $this->sysDate;
328             return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
329         }
330
331         // returns true or false
332         // To add: parameter int $port,
333         //         parameter string $socket
334         function _connect($argHostname = NULL,
335                           $argUsername = NULL,
336                           $argPassword = NULL,
337                           $argDatabasename = NULL)
338         {
339             // @ means: error surpression on
340             $this->_connectionID = @mysqli_init();
341
342             if (is_null($this->_connectionID)) {
343                 // mysqli_init only fails if insufficient memory
344                 if ($this->debug)
345                     ADOConnection::outp("mysqli_init() failed : " . $this->ErrorMsg());
346                 return false;
347             }
348             // Set connection options
349             // Not implemented now
350             // mysqli_options($this->_connection,,);
351             if (mysqli_real_connect($this->_connectionID,
352                 $argHostname,
353                 $argUsername,
354                 $argPassword,
355                 $argDatabasename)
356             ) {
357                 if ($argDatabasename) {
358                     return $this->SelectDB($argDatabasename);
359                 }
360
361                 return true;
362             } else {
363                 if ($this->debug)
364                     ADOConnection::outp("Could't connect : " . $this->ErrorMsg());
365                 return false;
366             }
367         }
368
369         // returns true or false
370         // How to force a persistent connection
371         function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
372         {
373             // not implemented in mysqli (yet)?
374             $this->_connectionID = mysqli_connect($argHostname,
375                 $argUsername,
376                 $argPassword,
377                 $argDatabasename);
378             if ($this->_connectionID === false) return false;
379             //      if ($this->autoRollback) $this->RollbackTrans();
380             if ($argDatabasename) return $this->SelectDB($argDatabasename);
381             return true;
382         }
383
384         // When is this used? Close old connection first?
385         // In _connect(), check $this->forceNewConnect?
386         function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
387         {
388             $this->forceNewConnect = true;
389             $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
390         }
391
392         function &MetaColumns($table)
393         {
394             if ($this->metaColumnsSQL) {
395                 global $ADODB_FETCH_MODE;
396                 $save = $ADODB_FETCH_MODE;
397                 $rs = false;
398                 switch ($ADODB_FETCH_MODE) {
399                     case ADODB_FETCH_NUM:
400                         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
401                         $rs = $this->Execute(sprintf($this->metaColumnsSQL,
402                             $table));
403
404                         $ADODB_FETCH_MODE = $save;
405                         if ($rs === false) break;
406                         $retarr = array();
407                         while (!$rs->EOF) {
408                             $fld = new ADOFieldObject();
409                             $fld->name = $rs->fields[0];
410                             $fld->type = $rs->fields[1];
411                             // split type into type(length):
412                             if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) {
413                                 $fld->type = $query_array[1];
414                                 $fld->max_length = $query_array[2];
415                             } else {
416                                 $fld->max_length = -1;
417                             }
418                             $fld->not_null = ($rs->fields[2] != 'YES');
419                             $fld->primary_key = ($rs->fields[3] == 'PRI');
420                             $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
421                             $fld->binary = (strpos($fld->type, 'blob') !== false);
422                             if (!$fld->binary) {
423                                 $d = $rs->fields[4];
424                                 $d = $rs->fields['Default'];
425                                 if ($d != "" && $d != "NULL") {
426                                     $fld->has_default = true;
427                                     $fld->default_value = $d;
428                                 } else {
429                                     $fld->has_default = false;
430                                 }
431                             }
432                             $retarr[strtoupper($fld->name)] = $fld;
433                             $rs->MoveNext();
434                         }
435                         break;
436                     case ADODB_FETCH_ASSOC:
437                     case ADODB_FETCH_DEFAULT:
438                     case ADODB_FETCH_BOTH:
439                         $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
440                         $rs = $this->Execute(sprintf($this->metaColumnsSQL,
441                             $table));
442                         $ADODB_FETCH_MODE = $save;
443                         if ($rs === false) break;
444                         $retarr = array();
445                         while (!$rs->EOF) {
446                             $fld = new ADOFieldObject();
447                             $fld->name = $rs->fields['Field'];
448                             $fld->type = $rs->fields['Type'];
449
450                             // split type into type(length):
451                             if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) {
452                                 $fld->type = $query_array[1];
453                                 $fld->max_length = $query_array[2];
454                             } else {
455                                 $fld->max_length = -1;
456                             }
457                             $fld->not_null = ($rs->fields['Null'] != 'YES');
458                             $fld->primary_key = ($rs->fields['Key'] == 'PRI');
459                             $fld->auto_increment = (strpos($rs->fields['Extra'], 'auto_increment') !== false);
460                             $fld->binary = (strpos($fld->type, 'blob') !== false);
461                             if (!$fld->binary) {
462                                 $d = $rs->fields['Default'];
463                                 if ($d != "" && $d != "NULL") {
464                                     $fld->has_default = true;
465                                     $fld->default_value = $d;
466                                 } else {
467                                     $fld->has_default = false;
468                                 }
469                             }
470                             $retarr[strtoupper($fld->name)] = $fld;
471                             $rs->MoveNext();
472                         }
473                         break;
474                     default:
475                 }
476
477                 if ($rs === false) return false;
478                 $rs->Close();
479                 return $retarr;
480             }
481             return false;
482         }
483
484         // returns true or false
485         function SelectDB($dbName)
486         {
487 //          $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
488             $this->databaseName = $dbName;
489             if ($this->_connectionID) {
490                 $result = @mysqli_select_db($this->_connectionID, $dbName);
491                 if (!$result) {
492                     ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg());
493                 }
494                 return $result;
495             }
496             return false;
497         }
498
499         // parameters use PostgreSQL convention, not MySQL
500         function &SelectLimit($sql,
501                               $nrows = -1,
502                               $offset = -1,
503                               $inputarr = false,
504                               $arg3 = false,
505                               $secs = 0)
506         {
507             $offsetStr = ($offset >= 0) ? "$offset," : '';
508
509             if ($secs)
510                 $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows", $inputarr, $arg3);
511             else
512                 $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows", $inputarr, $arg3);
513
514             return $rs;
515         }
516
517
518         function Prepare($sql)
519         {
520             return $sql;
521
522             $stmt = mysqli_prepare($this->_connectionID, $sql);
523             if (!$stmt) return false;
524             return array($sql, $stmt);
525         }
526
527
528         // returns queryID or false
529         function _query($sql, $inputarr)
530         {
531             global $ADODB_COUNTRECS;
532
533             if (is_array($sql)) {
534                 $stmt = $sql[1];
535                 foreach ($inputarr as $k => $v) {
536                     if (is_string($v)) $a[] = MYSQLI_BIND_STRING;
537                     else if (is_integer($v)) $a[] = MYSQLI_BIND_INT;
538                     else $a[] = MYSQLI_BIND_DOUBLE;
539
540                     $fnarr =& array_merge(array($stmt, $a), $inputarr);
541                     $ret = call_user_func_array('mysqli_bind_param', $fnarr);
542                 }
543                 $ret = mysqli_execute($stmt);
544                 return $ret;
545             }
546             if (!$mysql_res = mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) {
547                 if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg());
548                 return false;
549             }
550
551             return $mysql_res;
552         }
553
554         /*      Returns: the last error message from previous database operation        */
555         function ErrorMsg()
556         {
557             if (empty($this->_connectionID))
558                 $this->_errorMsg = @mysqli_error();
559             else
560                 $this->_errorMsg = @mysqli_error($this->_connectionID);
561             return $this->_errorMsg;
562         }
563
564         /*      Returns: the last error number from previous database operation */
565         function ErrorNo()
566         {
567             if (empty($this->_connectionID))
568                 return @mysqli_errno();
569             else
570                 return @mysqli_errno($this->_connectionID);
571         }
572
573         // returns true or false
574         function _close()
575         {
576             @mysqli_close($this->_connectionID);
577             $this->_connectionID = false;
578         }
579
580         /*
581         * Maximum size of C field
582         */
583         function CharMax()
584         {
585             return 255;
586         }
587
588         /*
589         * Maximum size of X field
590         */
591         function TextMax()
592         {
593             return 4294967295;
594         }
595
596
597     }
598
599     /*--------------------------------------------------------------------------------------
600          Class Name: Recordset
601     --------------------------------------------------------------------------------------*/
602
603     class ADORecordSet_mysqli extends ADORecordSet
604     {
605
606         var $databaseType = "mysqli";
607         var $canSeek = true;
608
609         function ADORecordSet_mysqli($queryID, $mode = false)
610         {
611             if ($mode === false) {
612                 global $ADODB_FETCH_MODE;
613                 $mode = $ADODB_FETCH_MODE;
614             }
615             switch ($mode) {
616                 case ADODB_FETCH_NUM:
617                     $this->fetchMode = MYSQLI_NUM;
618                     break;
619                 case ADODB_FETCH_ASSOC:
620                     $this->fetchMode = MYSQLI_ASSOC;
621                     break;
622                 case ADODB_FETCH_DEFAULT:
623                 case ADODB_FETCH_BOTH:
624                 default:
625                     $this->fetchMode = MYSQLI_ASSOC;
626                     break;
627             }
628             $this->ADORecordSet($queryID);
629         }
630
631         function _initrs()
632         {
633             // mysqli_num_rows only return correct number, depens
634             // on the use of mysql_store_result and mysql_use_result
635             if (!$this->Connection->executeOnly) {
636                 $this->_numOfRows = @mysqli_num_rows($this->_queryID);
637                 $this->_numOfFields = @mysqli_num_fields($this->_queryID);
638             } else {
639                 $this->_numOfRows = 0;
640                 $this->_numOfFields = 0;
641             }
642         }
643
644         function &FetchField($fieldOffset = -1)
645         {
646             $fieldnr = $fieldOffset;
647             if ($fieldOffset != -1) {
648                 $fieldOffset = mysqi_field_seek($this->_queryID, $fieldnr);
649             }
650             $o = mysqli_fetch_field($this->_queryID);
651             return $o;
652         }
653
654         function &GetRowAssoc($upper = true)
655         {
656             if ($this->fetchMode == MYSQLI_ASSOC && !$upper)
657                 return $this->fields;
658             $row =& ADORecordSet::GetRowAssoc($upper);
659             return $row;
660         }
661
662         /* Use associative array to get fields array */
663         function Fields($colname)
664         {
665             if ($this->fetchMode != MYSQLI_NUM)
666                 return @$this->fields[$colname];
667
668             if (!$this->bind) {
669                 $this->bind = array();
670                 for ($i = 0; $i < $this->_numOfFields; $i++) {
671                     $o = $this->FetchField($i);
672                     $this->bind[strtoupper($o->name)] = $i;
673                 }
674             }
675             return $this->fields[$this->bind[strtoupper($colname)]];
676         }
677
678         function _seek($row)
679         {
680             if ($this->_numOfRows == 0)
681                 return false;
682
683             if ($row < 0)
684                 return false;
685
686             mysqli_data_seek($this->_queryID, $row);
687             $this->EOF = false;
688             return true;
689         }
690
691         // 10% speedup to move MoveNext to child class
692         // This is the only implementation that works now (23-10-2003).
693         // Other functions return no or the wrong results.
694         function MoveNext()
695         {
696             if ($this->EOF)
697                 return false;
698             $this->_currentRow++;
699             switch ($this->fetchMode) {
700                 case MYSQLI_NUM:
701                     $this->fields = mysqli_fetch_array($this->_queryID);
702                     break;
703                 case MYSQLI_ASSOC:
704                 case MYSQLI_BOTH:
705                     $this->fields = mysqli_fetch_assoc($this->_queryID);
706                     break;
707                 default:
708             }
709             if (is_array($this->fields))
710                 return true;
711             $this->EOF = true;
712             return false;
713         }
714
715         function _fetch()
716         {
717             // mysqli_fetch_array($this->_queryID, MYSQLI_NUM) does not
718             // work (22-10-2003). But mysqli_fetch_array($this->_queryID) gives
719             // int resulttype should default to MYSQLI_BOTH,but give MYSQLI_NUM.
720
721             //    $this->fields =  mysqli_fetch_fields($this->_queryID);
722             //    $this->fields =  mysqli_fetch_array($this->_queryID); //, $this->fetchMode);
723
724             $this->fields = mysqli_fetch_assoc($this->_queryID); // $this->fetchMode);
725             return is_array($this->fields);
726         }
727
728         function _close()
729         {
730             mysqli_free_result($this->_queryID);
731             $this->_queryID = false;
732         }
733
734         function MetaType($t, $len = -1, $fieldobj = false)
735         {
736             if (is_object($t)) {
737                 $fieldobj = $t;
738                 $t = $fieldobj->type;
739                 $len = $fieldobj->max_length;
740             }
741
742             $len = -1; // mysql max_length is not accurate
743             switch (strtoupper($t)) {
744                 case 'STRING':
745                 case 'CHAR':
746                 case 'VARCHAR':
747                 case 'TINYBLOB':
748                 case 'TINYTEXT':
749                 case 'ENUM':
750                 case 'SET':
751                     if ($len <= $this->blobSize) return 'C';
752
753                 case 'TEXT':
754                 case 'LONGTEXT':
755                 case 'MEDIUMTEXT':
756                     return 'X';
757
758                 // php_mysql extension always returns 'blob' even if 'text'
759                 // so we have to check whether binary...
760                 case 'IMAGE':
761                 case 'LONGBLOB':
762                 case 'BLOB':
763                 case 'MEDIUMBLOB':
764                     return !empty($fieldobj->binary) ? 'B' : 'X';
765                 case 'YEAR':
766                 case 'DATE':
767                     return 'D';
768
769                 case 'TIME':
770                 case 'DATETIME':
771                 case 'TIMESTAMP':
772                     return 'T';
773
774                 case 'INT':
775                 case 'INTEGER':
776                 case 'BIGINT':
777                 case 'TINYINT':
778                 case 'MEDIUMINT':
779                 case 'SMALLINT':
780
781                     if (!empty($fieldobj->primary_key)) return 'R';
782                     else return 'I';
783                 // Added floating-point types
784                 // Maybe not necessery.
785                 case 'FLOAT':
786                 case 'DOUBLE':
787                     //          case 'DOUBLE PRECISION':
788                 case 'DECIMAL':
789                 case 'DEC':
790                 case 'FIXED':
791                 default:
792                     return 'N';
793             }
794         }
795
796     }
797
798 }