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