Updated adodb syysext to upstream version 5.0.8a.
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-mysql.inc.php
1 <?php
2 /*
3 V5.08 6 Apr 2009 (c) 2000-2009 John Lim (jlim#natsoft.com). 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 28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com)
13 */
14
15 // security - hide paths
16 if (!defined('ADODB_DIR')) die();
17
18 if (! defined("_ADODB_MYSQL_LAYER")) {
19 define("_ADODB_MYSQL_LAYER", 1 );
20
21 class ADODB_mysql extends ADOConnection {
22 var $databaseType = 'mysql';
23 var $dataProvider = 'mysql';
24 var $hasInsertID = true;
25 var $hasAffectedRows = true;
26 var $metaTablesSQL = "SHOW TABLES";
27 var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
28 var $fmtTimeStamp = "'Y-m-d H:i:s'";
29 var $hasLimit = true;
30 var $hasMoveFirst = true;
31 var $hasGenID = true;
32 var $isoDates = true; // accepts dates in ISO format
33 var $sysDate = 'CURDATE()';
34 var $sysTimeStamp = 'NOW()';
35 var $hasTransactions = false;
36 var $forceNewConnect = false;
37 var $poorAffectedRows = true;
38 var $clientFlags = 0;
39 var $substr = "substring";
40 var $nameQuote = '`'; /// string to use to quote identifiers and names
41 var $compat323 = false; // true if compat with mysql 3.23
42
43 function ADODB_mysql()
44 {
45 if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_';
46 }
47
48 function ServerInfo()
49 {
50 $arr['description'] = ADOConnection::GetOne("select version()");
51 $arr['version'] = ADOConnection::_findvers($arr['description']);
52 return $arr;
53 }
54
55 function IfNull( $field, $ifNull )
56 {
57 return " IFNULL($field, $ifNull) "; // if MySQL
58 }
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
79 function MetaIndexes ($table, $primary = FALSE, $owner=false)
80 {
81 // save old fetch mode
82 global $ADODB_FETCH_MODE;
83
84 $false = false;
85 $save = $ADODB_FETCH_MODE;
86 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
87 if ($this->fetchMode !== FALSE) {
88 $savem = $this->SetFetchMode(FALSE);
89 }
90
91 // get index details
92 $rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table));
93
94 // restore fetchmode
95 if (isset($savem)) {
96 $this->SetFetchMode($savem);
97 }
98 $ADODB_FETCH_MODE = $save;
99
100 if (!is_object($rs)) {
101 return $false;
102 }
103
104 $indexes = array ();
105
106 // parse index data into array
107 while ($row = $rs->FetchRow()) {
108 if ($primary == FALSE AND $row[2] == 'PRIMARY') {
109 continue;
110 }
111
112 if (!isset($indexes[$row[2]])) {
113 $indexes[$row[2]] = array(
114 'unique' => ($row[1] == 0),
115 'columns' => array()
116 );
117 }
118
119 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
120 }
121
122 // sort columns by order in the index
123 foreach ( array_keys ($indexes) as $index )
124 {
125 ksort ($indexes[$index]['columns']);
126 }
127
128 return $indexes;
129 }
130
131
132 // if magic quotes disabled, use mysql_real_escape_string()
133 function qstr($s,$magic_quotes=false)
134 {
135 if (is_null($s)) return 'NULL';
136 if (!$magic_quotes) {
137
138 if (ADODB_PHPVER >= 0x4300) {
139 if (is_resource($this->_connectionID))
140 return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
141 }
142 if ($this->replaceQuote[0] == '\\'){
143 $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
144 }
145 return "'".str_replace("'",$this->replaceQuote,$s)."'";
146 }
147
148 // undo magic quotes for "
149 $s = str_replace('\\"','"',$s);
150 return "'$s'";
151 }
152
153 function _insertid()
154 {
155 return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
156 //return mysql_insert_id($this->_connectionID);
157 }
158
159 function GetOne($sql,$inputarr=false)
160 {
161 if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
162 $rs = $this->SelectLimit($sql,1,-1,$inputarr);
163 if ($rs) {
164 $rs->Close();
165 if ($rs->EOF) return false;
166 return reset($rs->fields);
167 }
168 } else {
169 return ADOConnection::GetOne($sql,$inputarr);
170 }
171 return false;
172 }
173
174 function BeginTrans()
175 {
176 if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
177 }
178
179 function _affectedrows()
180 {
181 return mysql_affected_rows($this->_connectionID);
182 }
183
184 // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
185 // Reference on Last_Insert_ID on the recommended way to simulate sequences
186 var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
187 var $_genSeqSQL = "create table %s (id int not null)";
188 var $_genSeqCountSQL = "select count(*) from %s";
189 var $_genSeq2SQL = "insert into %s values (%s)";
190 var $_dropSeqSQL = "drop table %s";
191
192 function CreateSequence($seqname='adodbseq',$startID=1)
193 {
194 if (empty($this->_genSeqSQL)) return false;
195 $u = strtoupper($seqname);
196
197 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
198 if (!$ok) return false;
199 return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
200 }
201
202
203 function GenID($seqname='adodbseq',$startID=1)
204 {
205 // post-nuke sets hasGenID to false
206 if (!$this->hasGenID) return false;
207
208 $savelog = $this->_logsql;
209 $this->_logsql = false;
210 $getnext = sprintf($this->_genIDSQL,$seqname);
211 $holdtransOK = $this->_transOK; // save the current status
212 $rs = @$this->Execute($getnext);
213 if (!$rs) {
214 if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
215 $u = strtoupper($seqname);
216 $this->Execute(sprintf($this->_genSeqSQL,$seqname));
217 $cnt = $this->GetOne(sprintf($this->_genSeqCountSQL,$seqname));
218 if (!$cnt) $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
219 $rs = $this->Execute($getnext);
220 }
221
222 if ($rs) {
223 $this->genID = mysql_insert_id($this->_connectionID);
224 $rs->Close();
225 } else
226 $this->genID = 0;
227
228 $this->_logsql = $savelog;
229 return $this->genID;
230 }
231
232 function MetaDatabases()
233 {
234 $qid = mysql_list_dbs($this->_connectionID);
235 $arr = array();
236 $i = 0;
237 $max = mysql_num_rows($qid);
238 while ($i < $max) {
239 $db = mysql_tablename($qid,$i);
240 if ($db != 'mysql') $arr[] = $db;
241 $i += 1;
242 }
243 return $arr;
244 }
245
246
247 // Format date column in sql string given an input format that understands Y M D
248 function SQLDate($fmt, $col=false)
249 {
250 if (!$col) $col = $this->sysTimeStamp;
251 $s = 'DATE_FORMAT('.$col.",'";
252 $concat = false;
253 $len = strlen($fmt);
254 for ($i=0; $i < $len; $i++) {
255 $ch = $fmt[$i];
256 switch($ch) {
257
258 default:
259 if ($ch == '\\') {
260 $i++;
261 $ch = substr($fmt,$i,1);
262 }
263 /** FALL THROUGH */
264 case '-':
265 case '/':
266 $s .= $ch;
267 break;
268
269 case 'Y':
270 case 'y':
271 $s .= '%Y';
272 break;
273 case 'M':
274 $s .= '%b';
275 break;
276
277 case 'm':
278 $s .= '%m';
279 break;
280 case 'D':
281 case 'd':
282 $s .= '%d';
283 break;
284
285 case 'Q':
286 case 'q':
287 $s .= "'),Quarter($col)";
288
289 if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
290 else $s .= ",('";
291 $concat = true;
292 break;
293
294 case 'H':
295 $s .= '%H';
296 break;
297
298 case 'h':
299 $s .= '%I';
300 break;
301
302 case 'i':
303 $s .= '%i';
304 break;
305
306 case 's':
307 $s .= '%s';
308 break;
309
310 case 'a':
311 case 'A':
312 $s .= '%p';
313 break;
314
315 case 'w':
316 $s .= '%w';
317 break;
318
319 case 'W':
320 $s .= '%U';
321 break;
322
323 case 'l':
324 $s .= '%W';
325 break;
326 }
327 }
328 $s.="')";
329 if ($concat) $s = "CONCAT($s)";
330 return $s;
331 }
332
333
334 // returns concatenated string
335 // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
336 function Concat()
337 {
338 $s = "";
339 $arr = func_get_args();
340
341 // suggestion by andrew005@mnogo.ru
342 $s = implode(',',$arr);
343 if (strlen($s) > 0) return "CONCAT($s)";
344 else return '';
345 }
346
347 function OffsetDate($dayFraction,$date=false)
348 {
349 if (!$date) $date = $this->sysDate;
350
351 $fraction = $dayFraction * 24 * 3600;
352 return $date . ' + INTERVAL ' . $fraction.' SECOND';
353
354 // return "from_unixtime(unix_timestamp($date)+$fraction)";
355 }
356
357 // returns true or false
358 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
359 {
360 if (!empty($this->port)) $argHostname .= ":".$this->port;
361
362 if (ADODB_PHPVER >= 0x4300)
363 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
364 $this->forceNewConnect,$this->clientFlags);
365 else if (ADODB_PHPVER >= 0x4200)
366 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
367 $this->forceNewConnect);
368 else
369 $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
370
371 if ($this->_connectionID === false) return false;
372 if ($argDatabasename) return $this->SelectDB($argDatabasename);
373 return true;
374 }
375
376 // returns true or false
377 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
378 {
379 if (!empty($this->port)) $argHostname .= ":".$this->port;
380
381 if (ADODB_PHPVER >= 0x4300)
382 $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
383 else
384 $this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
385 if ($this->_connectionID === false) return false;
386 if ($this->autoRollback) $this->RollbackTrans();
387 if ($argDatabasename) return $this->SelectDB($argDatabasename);
388 return true;
389 }
390
391 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
392 {
393 $this->forceNewConnect = true;
394 return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
395 }
396
397 function MetaColumns($table)
398 {
399 $this->_findschema($table,$schema);
400 if ($schema) {
401 $dbName = $this->database;
402 $this->SelectDB($schema);
403 }
404 global $ADODB_FETCH_MODE;
405 $save = $ADODB_FETCH_MODE;
406 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
407
408 if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
409 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
410
411 if ($schema) {
412 $this->SelectDB($dbName);
413 }
414
415 if (isset($savem)) $this->SetFetchMode($savem);
416 $ADODB_FETCH_MODE = $save;
417 if (!is_object($rs)) {
418 $false = false;
419 return $false;
420 }
421
422 $retarr = array();
423 while (!$rs->EOF){
424 $fld = new ADOFieldObject();
425 $fld->name = $rs->fields[0];
426 $type = $rs->fields[1];
427
428 // split type into type(length):
429 $fld->scale = null;
430 if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
431 $fld->type = $query_array[1];
432 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
433 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
434 } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
435 $fld->type = $query_array[1];
436 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
437 } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
438 $fld->type = $query_array[1];
439 $arr = explode(",",$query_array[2]);
440 $fld->enums = $arr;
441 $zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
442 $fld->max_length = ($zlen > 0) ? $zlen : 1;
443 } else {
444 $fld->type = $type;
445 $fld->max_length = -1;
446 }
447 $fld->not_null = ($rs->fields[2] != 'YES');
448 $fld->primary_key = ($rs->fields[3] == 'PRI');
449 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
450 $fld->binary = (strpos($type,'blob') !== false || strpos($type,'binary') !== false);
451 $fld->unsigned = (strpos($type,'unsigned') !== false);
452 $fld->zerofill = (strpos($type,'zerofill') !== false);
453
454 if (!$fld->binary) {
455 $d = $rs->fields[4];
456 if ($d != '' && $d != 'NULL') {
457 $fld->has_default = true;
458 $fld->default_value = $d;
459 } else {
460 $fld->has_default = false;
461 }
462 }
463
464 if ($save == ADODB_FETCH_NUM) {
465 $retarr[] = $fld;
466 } else {
467 $retarr[strtoupper($fld->name)] = $fld;
468 }
469 $rs->MoveNext();
470 }
471
472 $rs->Close();
473 return $retarr;
474 }
475
476 // returns true or false
477 function SelectDB($dbName)
478 {
479 $this->database = $dbName;
480 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
481 if ($this->_connectionID) {
482 return @mysql_select_db($dbName,$this->_connectionID);
483 }
484 else return false;
485 }
486
487 // parameters use PostgreSQL convention, not MySQL
488 function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
489 {
490 $offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
491 // jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
492 if ($nrows < 0) $nrows = '18446744073709551615';
493
494 if ($secs)
495 $rs = $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
496 else
497 $rs = $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
498 return $rs;
499 }
500
501 // returns queryID or false
502 function _query($sql,$inputarr=false)
503 {
504 //global $ADODB_COUNTRECS;
505 //if($ADODB_COUNTRECS)
506 return mysql_query($sql,$this->_connectionID);
507 //else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
508 }
509
510 /* Returns: the last error message from previous database operation */
511 function ErrorMsg()
512 {
513
514 if ($this->_logsql) return $this->_errorMsg;
515 if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
516 else $this->_errorMsg = @mysql_error($this->_connectionID);
517 return $this->_errorMsg;
518 }
519
520 /* Returns: the last error number from previous database operation */
521 function ErrorNo()
522 {
523 if ($this->_logsql) return $this->_errorCode;
524 if (empty($this->_connectionID)) return @mysql_errno();
525 else return @mysql_errno($this->_connectionID);
526 }
527
528 // returns true or false
529 function _close()
530 {
531 @mysql_close($this->_connectionID);
532 $this->_connectionID = false;
533 }
534
535
536 /*
537 * Maximum size of C field
538 */
539 function CharMax()
540 {
541 return 255;
542 }
543
544 /*
545 * Maximum size of X field
546 */
547 function TextMax()
548 {
549 return 4294967295;
550 }
551
552 // "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
553 function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
554 {
555 global $ADODB_FETCH_MODE;
556 if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
557
558 if ( !empty($owner) ) {
559 $table = "$owner.$table";
560 }
561 $a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
562 if ($associative) {
563 $create_sql = isset($a_create_table["Create Table"]) ? $a_create_table["Create Table"] : $a_create_table["Create View"];
564 } else $create_sql = $a_create_table[1];
565
566 $matches = array();
567
568 if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
569 $foreign_keys = array();
570 $num_keys = count($matches[0]);
571 for ( $i = 0; $i < $num_keys; $i ++ ) {
572 $my_field = explode('`, `', $matches[1][$i]);
573 $ref_table = $matches[2][$i];
574 $ref_field = explode('`, `', $matches[3][$i]);
575
576 if ( $upper ) {
577 $ref_table = strtoupper($ref_table);
578 }
579
580 // see https://sourceforge.net/tracker/index.php?func=detail&aid=2287278&group_id=42718&atid=433976
581 if (!isset($foreign_keys[$ref_table])) {
582 $foreign_keys[$ref_table] = array();
583 }
584 $num_fields = count($my_field);
585 for ( $j = 0; $j < $num_fields; $j ++ ) {
586 if ( $associative ) {
587 $foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
588 } else {
589 $foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
590 }
591 }
592 }
593
594 return $foreign_keys;
595 }
596
597
598 }
599
600 /*--------------------------------------------------------------------------------------
601 Class Name: Recordset
602 --------------------------------------------------------------------------------------*/
603
604
605 class ADORecordSet_mysql extends ADORecordSet{
606
607 var $databaseType = "mysql";
608 var $canSeek = true;
609
610 function ADORecordSet_mysql($queryID,$mode=false)
611 {
612 if ($mode === false) {
613 global $ADODB_FETCH_MODE;
614 $mode = $ADODB_FETCH_MODE;
615 }
616 switch ($mode)
617 {
618 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
619 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
620 case ADODB_FETCH_DEFAULT:
621 case ADODB_FETCH_BOTH:
622 default:
623 $this->fetchMode = MYSQL_BOTH; break;
624 }
625 $this->adodbFetchMode = $mode;
626 $this->ADORecordSet($queryID);
627 }
628
629 function _initrs()
630 {
631 //GLOBAL $ADODB_COUNTRECS;
632 // $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
633 $this->_numOfRows = @mysql_num_rows($this->_queryID);
634 $this->_numOfFields = @mysql_num_fields($this->_queryID);
635 }
636
637 function FetchField($fieldOffset = -1)
638 {
639 if ($fieldOffset != -1) {
640 $o = @mysql_fetch_field($this->_queryID, $fieldOffset);
641 $f = @mysql_field_flags($this->_queryID,$fieldOffset);
642 if ($o) $o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich#att.com)
643 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
644 if ($o) $o->binary = (strpos($f,'binary')!== false);
645 }
646 else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
647 $o = @mysql_fetch_field($this->_queryID);
648 if ($o) $o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich#att.com)
649 //$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
650 }
651
652 return $o;
653 }
654
655 function GetRowAssoc($upper=true)
656 {
657 if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
658 else $row = ADORecordSet::GetRowAssoc($upper);
659 return $row;
660 }
661
662 /* Use associative array to get fields array */
663 function Fields($colname)
664 {
665 // added @ by "Michael William Miller" <mille562@pilot.msu.edu>
666 if ($this->fetchMode != MYSQL_NUM) 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) return false;
681 return @mysql_data_seek($this->_queryID,$row);
682 }
683
684 function MoveNext()
685 {
686 //return adodb_movenext($this);
687 //if (defined('ADODB_EXTENSION')) return adodb_movenext($this);
688 if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
689 $this->_currentRow += 1;
690 return true;
691 }
692 if (!$this->EOF) {
693 $this->_currentRow += 1;
694 $this->EOF = true;
695 }
696 return false;
697 }
698
699 function _fetch()
700 {
701 $this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
702 return is_array($this->fields);
703 }
704
705 function _close() {
706 @mysql_free_result($this->_queryID);
707 $this->_queryID = false;
708 }
709
710 function MetaType($t,$len=-1,$fieldobj=false)
711 {
712 if (is_object($t)) {
713 $fieldobj = $t;
714 $t = $fieldobj->type;
715 $len = $fieldobj->max_length;
716 }
717
718 $len = -1; // mysql max_length is not accurate
719 switch (strtoupper($t)) {
720 case 'STRING':
721 case 'CHAR':
722 case 'VARCHAR':
723 case 'TINYBLOB':
724 case 'TINYTEXT':
725 case 'ENUM':
726 case 'SET':
727 if ($len <= $this->blobSize) return 'C';
728
729 case 'TEXT':
730 case 'LONGTEXT':
731 case 'MEDIUMTEXT':
732 return 'X';
733
734 // php_mysql extension always returns 'blob' even if 'text'
735 // so we have to check whether binary...
736 case 'IMAGE':
737 case 'LONGBLOB':
738 case 'BLOB':
739 case 'MEDIUMBLOB':
740 case 'BINARY':
741 return !empty($fieldobj->binary) ? 'B' : 'X';
742
743 case 'YEAR':
744 case 'DATE': return 'D';
745
746 case 'TIME':
747 case 'DATETIME':
748 case 'TIMESTAMP': return 'T';
749
750 case 'INT':
751 case 'INTEGER':
752 case 'BIGINT':
753 case 'TINYINT':
754 case 'MEDIUMINT':
755 case 'SMALLINT':
756
757 if (!empty($fieldobj->primary_key)) return 'R';
758 else return 'I';
759
760 default: return 'N';
761 }
762 }
763
764 }
765
766 class ADORecordSet_ext_mysql extends ADORecordSet_mysql {
767 function ADORecordSet_ext_mysql($queryID,$mode=false)
768 {
769 if ($mode === false) {
770 global $ADODB_FETCH_MODE;
771 $mode = $ADODB_FETCH_MODE;
772 }
773 switch ($mode)
774 {
775 case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
776 case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
777 case ADODB_FETCH_DEFAULT:
778 case ADODB_FETCH_BOTH:
779 default:
780 $this->fetchMode = MYSQL_BOTH; break;
781 }
782 $this->adodbFetchMode = $mode;
783 $this->ADORecordSet($queryID);
784 }
785
786 function MoveNext()
787 {
788 return @adodb_movenext($this);
789 }
790 }
791
792
793 }
794 ?>