]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/adodb/drivers/adodb-odbc.inc.php
Upgrade adodb
[SourceForge/phpwiki.git] / lib / WikiDB / adodb / drivers / adodb-odbc.inc.php
1 <?php
2 /* 
3 V5.18 3 Sep 2012  (c) 2000-2012 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 4 for best viewing.
8   
9   Latest version is available at http://adodb.sourceforge.net
10   
11   Requires ODBC. Works on Windows and Unix.
12 */
13 // security - hide paths
14 if (!defined('ADODB_DIR')) die();
15
16   define("_ADODB_ODBC_LAYER", 2 );
17          
18 /*--------------------------------------------------------------------------------------
19 --------------------------------------------------------------------------------------*/
20
21
22 class ADODB_odbc extends ADOConnection {
23         var $databaseType = "odbc";     
24         var $fmtDate = "'Y-m-d'";
25         var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
26         var $replaceQuote = "''"; // string to use to replace quotes
27         var $dataProvider = "odbc";
28         var $hasAffectedRows = true;
29         var $binmode = ODBC_BINMODE_RETURN;
30         var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive
31                                                                 // breaking backward-compat
32         //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field
33         var $_bindInputArray = false;   
34         var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L
35         var $_genSeqSQL = "create table %s (id integer)";
36         var $_autocommit = true;
37         var $_haserrorfunctions = true;
38         var $_has_stupid_odbc_fetch_api_change = true;
39         var $_lastAffectedRows = 0;
40         var $uCaseTables = true; // for meta* functions, uppercase table names
41         
42         function ADODB_odbc() 
43         {       
44                 $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050;
45                 $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
46         }
47         
48                 // returns true or false
49         function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
50         {
51         global $php_errormsg;
52                 
53                 if (!function_exists('odbc_connect')) return null;
54                 
55                 if (!empty($argDatabasename) && stristr($argDSN, 'Database=') === false) {
56                         $argDSN = trim($argDSN);
57                         $endDSN = substr($argDSN, strlen($argDSN) - 1);
58                         if ($endDSN != ';') $argDSN .= ';';
59                         $argDSN .= 'Database='.$argDatabasename;
60                 }
61                 
62                 if (isset($php_errormsg)) $php_errormsg = '';
63                 if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
64                 else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
65                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
66                 if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
67                 
68                 return $this->_connectionID != false;
69         }
70         
71         // returns true or false
72         function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
73         {
74         global $php_errormsg;
75         
76                 if (!function_exists('odbc_connect')) return null;
77                 
78                 if (isset($php_errormsg)) $php_errormsg = '';
79                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
80                 if ($this->debug && $argDatabasename) {
81                         ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
82                 }
83         //      print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
84                 if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
85                 else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
86                 
87                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
88                 if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);
89                 if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
90                 
91                 return $this->_connectionID != false;
92         }
93
94         
95         function ServerInfo()
96         {
97         
98                 if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
99                         $dsn = strtoupper($this->host);
100                         $first = true;
101                         $found = false;
102                         
103                         if (!function_exists('odbc_data_source')) return false;
104                         
105                         while(true) {
106                                 
107                                 $rez = @odbc_data_source($this->_connectionID,
108                                         $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT);
109                                 $first = false;
110                                 if (!is_array($rez)) break;
111                                 if (strtoupper($rez['server']) == $dsn) {
112                                         $found = true;
113                                         break;
114                                 }
115                         } 
116                         if (!$found) return ADOConnection::ServerInfo();
117                         if (!isset($rez['version'])) $rez['version'] = '';
118                         return $rez;
119                 } else {
120                         return ADOConnection::ServerInfo();
121                 }
122         }
123
124         
125         function CreateSequence($seqname='adodbseq',$start=1)
126         {
127                 if (empty($this->_genSeqSQL)) return false;
128                 $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
129                 if (!$ok) return false;
130                 $start -= 1;
131                 return $this->Execute("insert into $seqname values($start)");
132         }
133         
134         var $_dropSeqSQL = 'drop table %s';
135         function DropSequence($seqname)
136         {
137                 if (empty($this->_dropSeqSQL)) return false;
138                 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
139         }
140         
141         /*
142                 This algorithm is not very efficient, but works even if table locking
143                 is not available.
144                 
145                 Will return false if unable to generate an ID after $MAXLOOPS attempts.
146         */
147         function GenID($seq='adodbseq',$start=1)
148         {       
149                 // if you have to modify the parameter below, your database is overloaded,
150                 // or you need to implement generation of id's yourself!
151                 $MAXLOOPS = 100;
152                 //$this->debug=1;
153                 while (--$MAXLOOPS>=0) {
154                         $num = $this->GetOne("select id from $seq");
155                         if ($num === false) {
156                                 $this->Execute(sprintf($this->_genSeqSQL ,$seq));       
157                                 $start -= 1;
158                                 $num = '0';
159                                 $ok = $this->Execute("insert into $seq values($start)");
160                                 if (!$ok) return false;
161                         } 
162                         $this->Execute("update $seq set id=id+1 where id=$num");
163                         
164                         if ($this->affected_rows() > 0) {
165                                 $num += 1;
166                                 $this->genID = $num;
167                                 return $num;
168                         } elseif ($this->affected_rows() == 0) {
169                                 // some drivers do not return a valid value => try with another method
170                                 $value = $this->GetOne("select id from $seq");
171                                 if ($value == $num + 1) {
172                                         return $value;
173                                 }
174                         }
175                 }
176                 if ($fn = $this->raiseErrorFn) {
177                         $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
178                 }
179                 return false;
180         }
181
182
183         function ErrorMsg()
184         {
185                 if ($this->_haserrorfunctions) {
186                         if ($this->_errorMsg !== false) return $this->_errorMsg;
187                         if (empty($this->_connectionID)) return @odbc_errormsg();
188                         return @odbc_errormsg($this->_connectionID);
189                 } else return ADOConnection::ErrorMsg();
190         }
191         
192         function ErrorNo()
193         {
194                 
195                 if ($this->_haserrorfunctions) {
196                         if ($this->_errorCode !== false) {
197                                 // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
198                                 return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode;
199                         }
200
201                         if (empty($this->_connectionID)) $e = @odbc_error(); 
202                         else $e = @odbc_error($this->_connectionID);
203                         
204                          // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
205                          // so we check and patch
206                         if (strlen($e)<=2) return 0;
207                         return $e;
208                 } else return ADOConnection::ErrorNo();
209         }
210         
211         
212
213         function BeginTrans()
214         {       
215                 if (!$this->hasTransactions) return false;
216                 if ($this->transOff) return true; 
217                 $this->transCnt += 1;
218                 $this->_autocommit = false;
219                 return odbc_autocommit($this->_connectionID,false);
220         }
221         
222         function CommitTrans($ok=true) 
223         { 
224                 if ($this->transOff) return true; 
225                 if (!$ok) return $this->RollbackTrans();
226                 if ($this->transCnt) $this->transCnt -= 1;
227                 $this->_autocommit = true;
228                 $ret = odbc_commit($this->_connectionID);
229                 odbc_autocommit($this->_connectionID,true);
230                 return $ret;
231         }
232         
233         function RollbackTrans()
234         {
235                 if ($this->transOff) return true; 
236                 if ($this->transCnt) $this->transCnt -= 1;
237                 $this->_autocommit = true;
238                 $ret = odbc_rollback($this->_connectionID);
239                 odbc_autocommit($this->_connectionID,true);
240                 return $ret;
241         }
242         
243         function MetaPrimaryKeys($table)
244         {
245         global $ADODB_FETCH_MODE;
246         
247                 if ($this->uCaseTables) $table = strtoupper($table);
248                 $schema = '';
249                 $this->_findschema($table,$schema);
250
251                 $savem = $ADODB_FETCH_MODE;
252                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
253                 $qid = @odbc_primarykeys($this->_connectionID,'',$schema,$table);
254                 
255                 if (!$qid) {
256                         $ADODB_FETCH_MODE = $savem;
257                         return false;
258                 }
259                 $rs = new ADORecordSet_odbc($qid);
260                 $ADODB_FETCH_MODE = $savem;
261                 
262                 if (!$rs) return false;
263                 $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
264                 
265                 $arr = $rs->GetArray();
266                 $rs->Close();
267                 //print_r($arr);
268                 $arr2 = array();
269                 for ($i=0; $i < sizeof($arr); $i++) {
270                         if ($arr[$i][3]) $arr2[] = $arr[$i][3];
271                 }
272                 return $arr2;
273         }
274         
275         
276         
277         function MetaTables($ttype=false)
278         {
279         global $ADODB_FETCH_MODE;
280         
281                 $savem = $ADODB_FETCH_MODE;
282                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
283                 $qid = odbc_tables($this->_connectionID);
284                 
285                 $rs = new ADORecordSet_odbc($qid);
286                 
287                 $ADODB_FETCH_MODE = $savem;
288                 if (!$rs) {
289                         $false = false;
290                         return $false;
291                 }
292                 $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
293                 
294                 $arr = $rs->GetArray();
295                 //print_r($arr);
296                 
297                 $rs->Close();
298                 $arr2 = array();
299                 
300                 if ($ttype) {
301                         $isview = strncmp($ttype,'V',1) === 0;
302                 }
303                 for ($i=0; $i < sizeof($arr); $i++) {
304                         if (!$arr[$i][2]) continue;
305                         $type = $arr[$i][3];
306                         if ($ttype) { 
307                                 if ($isview) {
308                                         if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2];
309                                 } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
310                         } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
311                 }
312                 return $arr2;
313         }
314         
315 /*
316 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp
317 / SQL data type codes /
318 #define SQL_UNKNOWN_TYPE        0
319 #define SQL_CHAR                        1
320 #define SQL_NUMERIC              2
321 #define SQL_DECIMAL              3
322 #define SQL_INTEGER              4
323 #define SQL_SMALLINT            5
324 #define SQL_FLOAT                  6
325 #define SQL_REAL                        7
326 #define SQL_DOUBLE                8
327 #if (ODBCVER >= 0x0300)
328 #define SQL_DATETIME            9
329 #endif
330 #define SQL_VARCHAR             12
331
332
333 / One-parameter shortcuts for date/time data types /
334 #if (ODBCVER >= 0x0300)
335 #define SQL_TYPE_DATE     91
336 #define SQL_TYPE_TIME     92
337 #define SQL_TYPE_TIMESTAMP 93
338
339 #define SQL_UNICODE                             (-95)
340 #define SQL_UNICODE_VARCHAR                     (-96)
341 #define SQL_UNICODE_LONGVARCHAR                 (-97)
342 */
343         function ODBCTypes($t)
344         {
345                 switch ((integer)$t) {
346                 case 1: 
347                 case 12:
348                 case 0:
349                 case -95:
350                 case -96:
351                         return 'C';
352                 case -97:
353                 case -1: //text
354                         return 'X';
355                 case -4: //image
356                         return 'B';
357                                 
358                 case 9: 
359                 case 91:
360                         return 'D';
361                 
362                 case 10:
363                 case 11:
364                 case 92:
365                 case 93:
366                         return 'T';
367                         
368                 case 4:
369                 case 5:
370                 case -6:
371                         return 'I';
372                         
373                 case -11: // uniqidentifier
374                         return 'R';
375                 case -7: //bit
376                         return 'L';
377                 
378                 default:
379                         return 'N';
380                 }
381         }
382         
383         function MetaColumns($table, $normalize=true)
384         {
385         global $ADODB_FETCH_MODE;
386         
387                 $false = false;
388                 if ($this->uCaseTables) $table = strtoupper($table);
389                 $schema = '';
390                 $this->_findschema($table,$schema);
391                 
392                 $savem = $ADODB_FETCH_MODE;
393                 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
394         
395                 /*if (false) { // after testing, confirmed that the following does not work becoz of a bug
396                         $qid2 = odbc_tables($this->_connectionID);
397                         $rs = new ADORecordSet_odbc($qid2);             
398                         $ADODB_FETCH_MODE = $savem;
399                         if (!$rs) return false;
400                         $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
401                         $rs->_fetch();
402                         
403                         while (!$rs->EOF) {
404                                 if ($table == strtoupper($rs->fields[2])) {
405                                         $q = $rs->fields[0];
406                                         $o = $rs->fields[1];
407                                         break;
408                                 }
409                                 $rs->MoveNext();
410                         }
411                         $rs->Close();
412                         
413                         $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');
414                 } */
415                 
416                 switch ($this->databaseType) {
417                 case 'access':
418                 case 'vfp':
419                         $qid = odbc_columns($this->_connectionID);#,'%','',strtoupper($table),'%');
420                         break;
421                 
422                 
423                 case 'db2':
424             $colname = "%";
425             $qid = odbc_columns($this->_connectionID, "", $schema, $table, $colname);
426             break;
427                         
428                 default:
429                         $qid = @odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%');
430                         if (empty($qid)) $qid = odbc_columns($this->_connectionID);
431                         break;
432                 }
433                 if (empty($qid)) return $false;
434                 
435                 $rs = new ADORecordSet_odbc($qid);
436                 $ADODB_FETCH_MODE = $savem;
437                 
438                 if (!$rs) return $false;
439                 $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
440                 $rs->_fetch();
441                 
442                 $retarr = array();
443                 
444                 /*
445                 $rs->fields indices
446                 0 TABLE_QUALIFIER
447                 1 TABLE_SCHEM
448                 2 TABLE_NAME
449                 3 COLUMN_NAME
450                 4 DATA_TYPE
451                 5 TYPE_NAME
452                 6 PRECISION
453                 7 LENGTH
454                 8 SCALE
455                 9 RADIX
456                 10 NULLABLE
457                 11 REMARKS
458                 */
459                 while (!$rs->EOF) {
460                 //      adodb_pr($rs->fields);
461                         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
462                                 $fld = new ADOFieldObject();
463                                 $fld->name = $rs->fields[3];
464                                 $fld->type = $this->ODBCTypes($rs->fields[4]);
465                                 
466                                 // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
467                                 // access uses precision to store length for char/varchar
468                                 if ($fld->type == 'C' or $fld->type == 'X') {
469                                         if ($this->databaseType == 'access') 
470                                                 $fld->max_length = $rs->fields[6];
471                                         else if ($rs->fields[4] <= -95) // UNICODE
472                                                 $fld->max_length = $rs->fields[7]/2;
473                                         else
474                                                 $fld->max_length = $rs->fields[7];
475                                 } else 
476                                         $fld->max_length = $rs->fields[7];
477                                 $fld->not_null = !empty($rs->fields[10]);
478                                 $fld->scale = $rs->fields[8];
479                                 $retarr[strtoupper($fld->name)] = $fld; 
480                         } else if (sizeof($retarr)>0)
481                                 break;
482                         $rs->MoveNext();
483                 }
484                 $rs->Close(); //-- crashes 4.03pl1 -- why?
485                 
486                 if (empty($retarr)) $retarr = false;
487                 return $retarr;
488         }
489         
490         function Prepare($sql)
491         {
492                 if (! $this->_bindInputArray) return $sql; // no binding
493                 $stmt = odbc_prepare($this->_connectionID,$sql);
494                 if (!$stmt) {
495                         // we don't know whether odbc driver is parsing prepared stmts, so just return sql
496                         return $sql;
497                 }
498                 return array($sql,$stmt,false);
499         }
500
501         /* returns queryID or false */
502         function _query($sql,$inputarr=false) 
503         {
504         GLOBAL $php_errormsg;
505                 if (isset($php_errormsg)) $php_errormsg = '';
506                 $this->_error = '';
507                 
508                 if ($inputarr) {
509                         if (is_array($sql)) {
510                                 $stmtid = $sql[1];
511                         } else {
512                                 $stmtid = odbc_prepare($this->_connectionID,$sql);
513         
514                                 if ($stmtid == false) {
515                                         $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
516                                         return false;
517                                 }
518                         }
519                         
520                         if (! odbc_execute($stmtid,$inputarr)) {
521                                 //@odbc_free_result($stmtid);
522                                 if ($this->_haserrorfunctions) {
523                                         $this->_errorMsg = odbc_errormsg();
524                                         $this->_errorCode = odbc_error();
525                                 }
526                                 return false;
527                         }
528                 
529                 } else if (is_array($sql)) {
530                         $stmtid = $sql[1];
531                         if (!odbc_execute($stmtid)) {
532                                 //@odbc_free_result($stmtid);
533                                 if ($this->_haserrorfunctions) {
534                                         $this->_errorMsg = odbc_errormsg();
535                                         $this->_errorCode = odbc_error();
536                                 }
537                                 return false;
538                         }
539                 } else
540                         $stmtid = odbc_exec($this->_connectionID,$sql);
541                 
542                 $this->_lastAffectedRows = 0;
543                 if ($stmtid) {
544                         if (@odbc_num_fields($stmtid) == 0) {
545                                 $this->_lastAffectedRows = odbc_num_rows($stmtid);
546                                 $stmtid = true;
547                         } else {
548                                 $this->_lastAffectedRows = 0;
549                                 odbc_binmode($stmtid,$this->binmode);
550                                 odbc_longreadlen($stmtid,$this->maxblobsize);
551                         }
552                         
553                         if ($this->_haserrorfunctions) {
554                                 $this->_errorMsg = '';
555                                 $this->_errorCode = 0;
556                         } else
557                                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
558                 } else {
559                         if ($this->_haserrorfunctions) {
560                                 $this->_errorMsg = odbc_errormsg();
561                                 $this->_errorCode = odbc_error();
562                         } else
563                                 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
564                 }
565                 return $stmtid;
566         }
567
568         /*
569                 Insert a null into the blob field of the table first.
570                 Then use UpdateBlob to store the blob.
571                 
572                 Usage:
573                  
574                 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
575                 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
576         */
577         function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
578         {
579                 return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
580         }
581         
582         // returns true or false
583         function _close()
584         {
585                 $ret = @odbc_close($this->_connectionID);
586                 $this->_connectionID = false;
587                 return $ret;
588         }
589
590         function _affectedrows()
591         {
592                 return $this->_lastAffectedRows;
593         }
594         
595 }
596         
597 /*--------------------------------------------------------------------------------------
598          Class Name: Recordset
599 --------------------------------------------------------------------------------------*/
600
601 class ADORecordSet_odbc extends ADORecordSet {  
602         
603         var $bind = false;
604         var $databaseType = "odbc";             
605         var $dataProvider = "odbc";
606         var $useFetchArray;
607         var $_has_stupid_odbc_fetch_api_change;
608         
609         function ADORecordSet_odbc($id,$mode=false)
610         {
611                 if ($mode === false) {  
612                         global $ADODB_FETCH_MODE;
613                         $mode = $ADODB_FETCH_MODE;
614                 }
615                 $this->fetchMode = $mode;
616                 
617                 $this->_queryID = $id;
618                 
619                 // the following is required for mysql odbc driver in 4.3.1 -- why?
620                 $this->EOF = false;
621                 $this->_currentRow = -1;
622                 //$this->ADORecordSet($id);
623         }
624
625
626         // returns the field object
627         function FetchField($fieldOffset = -1) 
628         {
629                 
630                 $off=$fieldOffset+1; // offsets begin at 1
631                 
632                 $o= new ADOFieldObject();
633                 $o->name = @odbc_field_name($this->_queryID,$off);
634                 $o->type = @odbc_field_type($this->_queryID,$off);
635                 $o->max_length = @odbc_field_len($this->_queryID,$off);
636                 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
637                 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
638                 return $o;
639         }
640         
641         /* Use associative array to get fields array */
642         function Fields($colname)
643         {
644                 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
645                 if (!$this->bind) {
646                         $this->bind = array();
647                         for ($i=0; $i < $this->_numOfFields; $i++) {
648                                 $o = $this->FetchField($i);
649                                 $this->bind[strtoupper($o->name)] = $i;
650                         }
651                 }
652
653                  return $this->fields[$this->bind[strtoupper($colname)]];
654         }
655         
656                 
657         function _initrs()
658         {
659         global $ADODB_COUNTRECS;
660                 $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1;
661                 $this->_numOfFields = @odbc_num_fields($this->_queryID);
662                 // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0
663                 if ($this->_numOfRows == 0) $this->_numOfRows = -1;
664                 //$this->useFetchArray = $this->connection->useFetchArray;
665                 $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
666         }       
667         
668         function _seek($row)
669         {
670                 return false;
671         }
672         
673         // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated
674         function GetArrayLimit($nrows,$offset=-1) 
675         {
676                 if ($offset <= 0) {
677                         $rs = $this->GetArray($nrows);
678                         return $rs;
679                 }
680                 $savem = $this->fetchMode;
681                 $this->fetchMode = ADODB_FETCH_NUM;
682                 $this->Move($offset);
683                 $this->fetchMode = $savem;
684                 
685                 if ($this->fetchMode & ADODB_FETCH_ASSOC) {
686                         $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
687                 }
688                 
689                 $results = array();
690                 $cnt = 0;
691                 while (!$this->EOF && $nrows != $cnt) {
692                         $results[$cnt++] = $this->fields;
693                         $this->MoveNext();
694                 }
695                 
696                 return $results;
697         }
698         
699         
700         function MoveNext() 
701         {
702                 if ($this->_numOfRows != 0 && !$this->EOF) {            
703                         $this->_currentRow++;
704                         
705                         if ($this->_has_stupid_odbc_fetch_api_change)
706                                 $rez = @odbc_fetch_into($this->_queryID,$this->fields);
707                         else {
708                                 $row = 0;
709                                 $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
710                         }
711                         if ($rez) {
712                                 if ($this->fetchMode & ADODB_FETCH_ASSOC) {
713                                         $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
714                                 }
715                                 return true;
716                         }
717                 }
718                 $this->fields = false;
719                 $this->EOF = true;
720                 return false;
721         }       
722         
723         function _fetch()
724         {
725
726                 if ($this->_has_stupid_odbc_fetch_api_change)
727                         $rez = @odbc_fetch_into($this->_queryID,$this->fields);
728                 else {
729                         $row = 0;
730                         $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
731                 }
732                 if ($rez) {
733                         if ($this->fetchMode & ADODB_FETCH_ASSOC) {
734                                 $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
735                         }
736                         return true;
737                 }
738                 $this->fields = false;
739                 return false;
740         }
741         
742         function _close() 
743         {
744                 return @odbc_free_result($this->_queryID);              
745         }
746
747 }
748 ?>