ChangeLog
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-odbtp.inc.php
1 <?php
2 /*
3 V4.90 8 June 2006 (c) 2000-2006 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. See License.txt.
7 Set tabs to 4 for best viewing.
8 Latest version is available at http://adodb.sourceforge.net
9 */
10 // Code contributed by "stefan bogdan" <sbogdan#rsb.ro>
11
12 // security - hide paths
13 if (!defined('ADODB_DIR')) die();
14
15 define("_ADODB_ODBTP_LAYER", 2 );
16
17 class ADODB_odbtp extends ADOConnection{
18 var $databaseType = "odbtp";
19 var $dataProvider = "odbtp";
20 var $fmtDate = "'Y-m-d'";
21 var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
22 var $replaceQuote = "''"; // string to use to replace quotes
23 var $odbc_driver = 0;
24 var $hasAffectedRows = true;
25 var $hasInsertID = false;
26 var $hasGenID = true;
27 var $hasMoveFirst = true;
28
29 var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)";
30 var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'";
31 var $_bindInputArray = false;
32 var $_useUnicodeSQL = false;
33 var $_canPrepareSP = false;
34 var $_dontPoolDBC = true;
35
36 function ADODB_odbtp()
37 {
38 }
39
40 function ServerInfo()
41 {
42 return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID),
43 'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID));
44 }
45
46 function ErrorMsg()
47 {
48 if (empty($this->_connectionID)) return @odbtp_last_error();
49 return @odbtp_last_error($this->_connectionID);
50 }
51
52 function ErrorNo()
53 {
54 if (empty($this->_connectionID)) return @odbtp_last_error_state();
55 return @odbtp_last_error_state($this->_connectionID);
56 }
57
58 function _insertid()
59 {
60 // SCOPE_IDENTITY()
61 // Returns the last IDENTITY value inserted into an IDENTITY column in
62 // the same scope. A scope is a module -- a stored procedure, trigger,
63 // function, or batch. Thus, two statements are in the same scope if
64 // they are in the same stored procedure, function, or batch.
65 return $this->GetOne($this->identitySQL);
66 }
67
68 function _affectedrows()
69 {
70 if ($this->_queryID) {
71 return @odbtp_affected_rows ($this->_queryID);
72 } else
73 return 0;
74 }
75
76 function CreateSequence($seqname='adodbseq',$start=1)
77 {
78 //verify existence
79 $num = $this->GetOne("select seq_value from adodb_seq");
80 $seqtab='adodb_seq';
81 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
82 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID );
83 //if using vfp dbc file
84 if( !strcasecmp(strrchr($path, '.'), '.dbc') )
85 $path = substr($path,0,strrpos($path,'\/'));
86 $seqtab = $path . '/' . $seqtab;
87 }
88 if($num == false) {
89 if (empty($this->_genSeqSQL)) return false;
90 $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab));
91 }
92 $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'");
93 if ($num) {
94 return false;
95 }
96 $start -= 1;
97 return $this->Execute("insert into adodb_seq values('$seqname',$start)");
98 }
99
100 function DropSequence($seqname)
101 {
102 if (empty($this->_dropSeqSQL)) return false;
103 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
104 }
105
106 function GenID($seq='adodbseq',$start=1)
107 {
108 $seqtab='adodb_seq';
109 if( $this->odbc_driver == ODB_DRIVER_FOXPRO) {
110 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID );
111 //if using vfp dbc file
112 if( !strcasecmp(strrchr($path, '.'), '.dbc') )
113 $path = substr($path,0,strrpos($path,'\/'));
114 $seqtab = $path . '/' . $seqtab;
115 }
116 $MAXLOOPS = 100;
117 while (--$MAXLOOPS>=0) {
118 $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'");
119 if ($num === false) {
120 //verify if abodb_seq table exist
121 $ok = $this->GetOne("select seq_value from adodb_seq ");
122 if(!$ok) {
123 //creating the sequence table adodb_seq
124 $this->Execute(sprintf($this->_genSeqSQL ,$seqtab));
125 }
126 $start -= 1;
127 $num = '0';
128 $ok = $this->Execute("insert into adodb_seq values('$seq',$start)");
129 if (!$ok) return false;
130 }
131 $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'");
132 if($ok) {
133 $num += 1;
134 $this->genID = $num;
135 return $num;
136 }
137 }
138 if ($fn = $this->raiseErrorFn) {
139 $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
140 }
141 return false;
142 }
143
144 //example for $UserOrDSN
145 //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO;
146 //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO;
147 //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=;
148 //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest;
149 //if uid & pwd can be separate
150 function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
151 {
152 $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase);
153 if ($this->_connectionID === false) {
154 $this->_errorMsg = $this->ErrorMsg() ;
155 return false;
156 }
157 if ($this->_dontPoolDBC) {
158 if (function_exists('odbtp_dont_pool_dbc'))
159 @odbtp_dont_pool_dbc($this->_connectionID);
160 }
161 else {
162 $this->_dontPoolDBC = true;
163 }
164 $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID);
165 $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID));
166 $this->odbc_name = $dbms;
167
168 // Account for inconsistent DBMS names
169 if( $this->odbc_driver == ODB_DRIVER_ORACLE )
170 $dbms = 'oracle';
171 else if( $this->odbc_driver == ODB_DRIVER_SYBASE )
172 $dbms = 'sybase';
173
174 // Set DBMS specific attributes
175 switch( $dbms ) {
176 case 'microsoft sql server':
177 $this->databaseType = 'odbtp_mssql';
178 $this->fmtDate = "'Y-m-d'";
179 $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
180 $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
181 $this->sysTimeStamp = 'GetDate()';
182 $this->ansiOuter = true;
183 $this->leftOuter = '*=';
184 $this->rightOuter = '=*';
185 $this->hasTop = 'top';
186 $this->hasInsertID = true;
187 $this->hasTransactions = true;
188 $this->_bindInputArray = true;
189 $this->_canSelectDb = true;
190 $this->substr = "substring";
191 $this->length = 'len';
192 $this->identitySQL = 'select @@IDENTITY';
193 $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'";
194 $this->_canPrepareSP = true;
195 break;
196 case 'access':
197 $this->databaseType = 'odbtp_access';
198 $this->fmtDate = "#Y-m-d#";
199 $this->fmtTimeStamp = "#Y-m-d h:i:sA#";
200 $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
201 $this->sysTimeStamp = 'NOW';
202 $this->hasTop = 'top';
203 $this->hasTransactions = false;
204 $this->_canPrepareSP = true; // For MS Access only.
205 break;
206 case 'visual foxpro':
207 $this->databaseType = 'odbtp_vfp';
208 $this->fmtDate = "{^Y-m-d}";
209 $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}";
210 $this->sysDate = 'date()';
211 $this->sysTimeStamp = 'datetime()';
212 $this->ansiOuter = true;
213 $this->hasTop = 'top';
214 $this->hasTransactions = false;
215 $this->replaceQuote = "'+chr(39)+'";
216 $this->true = '.T.';
217 $this->false = '.F.';
218 break;
219 case 'oracle':
220 $this->databaseType = 'odbtp_oci8';
221 $this->fmtDate = "'Y-m-d 00:00:00'";
222 $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
223 $this->sysDate = 'TRUNC(SYSDATE)';
224 $this->sysTimeStamp = 'SYSDATE';
225 $this->hasTransactions = true;
226 $this->_bindInputArray = true;
227 $this->concat_operator = '||';
228 break;
229 case 'sybase':
230 $this->databaseType = 'odbtp_sybase';
231 $this->fmtDate = "'Y-m-d'";
232 $this->fmtTimeStamp = "'Y-m-d H:i:s'";
233 $this->sysDate = 'GetDate()';
234 $this->sysTimeStamp = 'GetDate()';
235 $this->leftOuter = '*=';
236 $this->rightOuter = '=*';
237 $this->hasInsertID = true;
238 $this->hasTransactions = true;
239 $this->identitySQL = 'select @@IDENTITY';
240 break;
241 default:
242 $this->databaseType = 'odbtp';
243 if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) )
244 $this->hasTransactions = true;
245 else
246 $this->hasTransactions = false;
247 }
248 @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID );
249
250 if ($this->_useUnicodeSQL )
251 @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID);
252
253 return true;
254 }
255
256 function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
257 {
258 $this->_dontPoolDBC = false;
259 return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase);
260 }
261
262 function SelectDB($dbName)
263 {
264 if (!@odbtp_select_db($dbName, $this->_connectionID)) {
265 return false;
266 }
267 $this->database = $dbName;
268 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
269 return true;
270 }
271
272 function &MetaTables($ttype='',$showSchema=false,$mask=false)
273 {
274 global $ADODB_FETCH_MODE;
275
276 $savem = $ADODB_FETCH_MODE;
277 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
278 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
279
280 $arr =& $this->GetArray("||SQLTables||||$ttype");
281
282 if (isset($savefm)) $this->SetFetchMode($savefm);
283 $ADODB_FETCH_MODE = $savem;
284
285 $arr2 = array();
286 for ($i=0; $i < sizeof($arr); $i++) {
287 if ($arr[$i][3] == 'SYSTEM TABLE' ) continue;
288 if ($arr[$i][2])
289 $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];
290 }
291 return $arr2;
292 }
293
294 function &MetaColumns($table,$upper=true)
295 {
296 global $ADODB_FETCH_MODE;
297
298 $schema = false;
299 $this->_findschema($table,$schema);
300 if ($upper) $table = strtoupper($table);
301
302 $savem = $ADODB_FETCH_MODE;
303 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
304 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
305
306 $rs = $this->Execute( "||SQLColumns||$schema|$table" );
307
308 if (isset($savefm)) $this->SetFetchMode($savefm);
309 $ADODB_FETCH_MODE = $savem;
310
311 if (!$rs || $rs->EOF) {
312 $false = false;
313 return $false;
314 }
315 $retarr = array();
316 while (!$rs->EOF) {
317 //print_r($rs->fields);
318 if (strtoupper($rs->fields[2]) == $table) {
319 $fld = new ADOFieldObject();
320 $fld->name = $rs->fields[3];
321 $fld->type = $rs->fields[5];
322 $fld->max_length = $rs->fields[6];
323 $fld->not_null = !empty($rs->fields[9]);
324 $fld->scale = $rs->fields[7];
325 if (!is_null($rs->fields[12])) {
326 $fld->has_default = true;
327 $fld->default_value = $rs->fields[12];
328 }
329 $retarr[strtoupper($fld->name)] = $fld;
330 } else if (!empty($retarr))
331 break;
332 $rs->MoveNext();
333 }
334 $rs->Close();
335
336 return $retarr;
337 }
338
339 function &MetaPrimaryKeys($table, $owner='')
340 {
341 global $ADODB_FETCH_MODE;
342
343 $savem = $ADODB_FETCH_MODE;
344 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
345 $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table");
346 $ADODB_FETCH_MODE = $savem;
347
348 //print_r($arr);
349 $arr2 = array();
350 for ($i=0; $i < sizeof($arr); $i++) {
351 if ($arr[$i][3]) $arr2[] = $arr[$i][3];
352 }
353 return $arr2;
354 }
355
356 function &MetaForeignKeys($table, $owner='', $upper=false)
357 {
358 global $ADODB_FETCH_MODE;
359
360 $savem = $ADODB_FETCH_MODE;
361 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
362 $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table");
363 $ADODB_FETCH_MODE = $savem;
364
365 $arr = false;
366 foreach($constraints as $constr) {
367 //print_r($constr);
368 $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3];
369 }
370 if (!$arr) {
371 $false = false;
372 return $false;
373 }
374
375 $arr2 = array();
376
377 foreach($arr as $k => $v) {
378 foreach($v as $a => $b) {
379 if ($upper) $a = strtoupper($a);
380 $arr2[$a] = $b;
381 }
382 }
383 return $arr2;
384 }
385
386 function BeginTrans()
387 {
388 if (!$this->hasTransactions) return false;
389 if ($this->transOff) return true;
390 $this->transCnt += 1;
391 $this->autoCommit = false;
392 if (defined('ODB_TXN_DEFAULT'))
393 $txn = ODB_TXN_DEFAULT;
394 else
395 $txn = ODB_TXN_READUNCOMMITTED;
396 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID);
397 if(!$rs) return false;
398 return true;
399 }
400
401 function CommitTrans($ok=true)
402 {
403 if ($this->transOff) return true;
404 if (!$ok) return $this->RollbackTrans();
405 if ($this->transCnt) $this->transCnt -= 1;
406 $this->autoCommit = true;
407 if( ($ret = @odbtp_commit($this->_connectionID)) )
408 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
409 return $ret;
410 }
411
412 function RollbackTrans()
413 {
414 if ($this->transOff) return true;
415 if ($this->transCnt) $this->transCnt -= 1;
416 $this->autoCommit = true;
417 if( ($ret = @odbtp_rollback($this->_connectionID)) )
418 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
419 return $ret;
420 }
421
422 function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
423 {
424 // TOP requires ORDER BY for Visual FoxPro
425 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
426 if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1';
427 }
428 $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
429 return $ret;
430 }
431
432 function Prepare($sql)
433 {
434 if (! $this->_bindInputArray) return $sql; // no binding
435 $stmt = @odbtp_prepare($sql,$this->_connectionID);
436 if (!$stmt) {
437 // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>";
438 return $sql;
439 }
440 return array($sql,$stmt,false);
441 }
442
443 function PrepareSP($sql)
444 {
445 if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures
446
447 $stmt = @odbtp_prepare_proc($sql,$this->_connectionID);
448 if (!$stmt) return false;
449 return array($sql,$stmt);
450 }
451
452 /*
453 Usage:
454 $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group
455
456 # note that the parameter does not have @ in front!
457 $db->Parameter($stmt,$id,'myid');
458 $db->Parameter($stmt,$group,'group',false,64);
459 $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY);
460 $db->Execute($stmt);
461
462 @param $stmt Statement returned by Prepare() or PrepareSP().
463 @param $var PHP variable to bind to. Can set to null (for isNull support).
464 @param $name Name of stored procedure variable name to bind to.
465 @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp.
466 @param [$maxLen] Holds an maximum length of the variable.
467 @param [$type] The data type of $var. Legal values depend on driver.
468
469 See odbtp_attach_param documentation at http://odbtp.sourceforge.net.
470 */
471 function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0)
472 {
473 if ( $this->odbc_driver == ODB_DRIVER_JET ) {
474 $name = '['.$name.']';
475 if( !$type && $this->_useUnicodeSQL
476 && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR )
477 {
478 $type = ODB_WCHAR;
479 }
480 }
481 else {
482 $name = '@'.$name;
483 }
484 return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen);
485 }
486
487 /*
488 Insert a null into the blob field of the table first.
489 Then use UpdateBlob to store the blob.
490
491 Usage:
492
493 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
494 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
495 */
496
497 function UpdateBlob($table,$column,$val,$where,$blobtype='image')
498 {
499 $sql = "UPDATE $table SET $column = ? WHERE $where";
500 if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) )
501 return false;
502 if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) )
503 return false;
504 if( !@odbtp_set( $stmt, 1, $val ) )
505 return false;
506 return @odbtp_execute( $stmt ) != false;
507 }
508
509 function IfNull( $field, $ifNull )
510 {
511 switch( $this->odbc_driver ) {
512 case ODB_DRIVER_MSSQL:
513 return " ISNULL($field, $ifNull) ";
514 case ODB_DRIVER_JET:
515 return " IIF(IsNull($field), $ifNull, $field) ";
516 }
517 return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
518 }
519
520 function _query($sql,$inputarr=false)
521 {
522 global $php_errormsg;
523
524 if ($inputarr) {
525 if (is_array($sql)) {
526 $stmtid = $sql[1];
527 } else {
528 $stmtid = @odbtp_prepare($sql,$this->_connectionID);
529 if ($stmtid == false) {
530 $this->_errorMsg = $php_errormsg;
531 return false;
532 }
533 }
534 $num_params = @odbtp_num_params( $stmtid );
535 for( $param = 1; $param <= $num_params; $param++ ) {
536 @odbtp_input( $stmtid, $param );
537 @odbtp_set( $stmtid, $param, $inputarr[$param-1] );
538 }
539 if (!@odbtp_execute($stmtid) ) {
540 return false;
541 }
542 } else if (is_array($sql)) {
543 $stmtid = $sql[1];
544 if (!@odbtp_execute($stmtid)) {
545 return false;
546 }
547 } else {
548 $stmtid = @odbtp_query($sql,$this->_connectionID);
549 }
550 $this->_lastAffectedRows = 0;
551 if ($stmtid) {
552 $this->_lastAffectedRows = @odbtp_affected_rows($stmtid);
553 }
554 return $stmtid;
555 }
556
557 function _close()
558 {
559 $ret = @odbtp_close($this->_connectionID);
560 $this->_connectionID = false;
561 return $ret;
562 }
563 }
564
565 class ADORecordSet_odbtp extends ADORecordSet {
566
567 var $databaseType = 'odbtp';
568 var $canSeek = true;
569
570 function ADORecordSet_odbtp($queryID,$mode=false)
571 {
572 if ($mode === false) {
573 global $ADODB_FETCH_MODE;
574 $mode = $ADODB_FETCH_MODE;
575 }
576 $this->fetchMode = $mode;
577 $this->ADORecordSet($queryID);
578 }
579
580 function _initrs()
581 {
582 $this->_numOfFields = @odbtp_num_fields($this->_queryID);
583 if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID)))
584 $this->_numOfRows = -1;
585
586 if (!$this->connection->_useUnicodeSQL) return;
587
588 if ($this->connection->odbc_driver == ODB_DRIVER_JET) {
589 if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR,
590 $this->connection->_connectionID))
591 {
592 for ($f = 0; $f < $this->_numOfFields; $f++) {
593 if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR)
594 @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR);
595 }
596 }
597 }
598 }
599
600 function &FetchField($fieldOffset = 0)
601 {
602 $off=$fieldOffset; // offsets begin at 0
603 $o= new ADOFieldObject();
604 $o->name = @odbtp_field_name($this->_queryID,$off);
605 $o->type = @odbtp_field_type($this->_queryID,$off);
606 $o->max_length = @odbtp_field_length($this->_queryID,$off);
607 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
608 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
609 return $o;
610 }
611
612 function _seek($row)
613 {
614 return @odbtp_data_seek($this->_queryID, $row);
615 }
616
617 function fields($colname)
618 {
619 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
620
621 if (!$this->bind) {
622 $this->bind = array();
623 for ($i=0; $i < $this->_numOfFields; $i++) {
624 $name = @odbtp_field_name( $this->_queryID, $i );
625 $this->bind[strtoupper($name)] = $i;
626 }
627 }
628 return $this->fields[$this->bind[strtoupper($colname)]];
629 }
630
631 function _fetch_odbtp($type=0)
632 {
633 switch ($this->fetchMode) {
634 case ADODB_FETCH_NUM:
635 $this->fields = @odbtp_fetch_row($this->_queryID, $type);
636 break;
637 case ADODB_FETCH_ASSOC:
638 $this->fields = @odbtp_fetch_assoc($this->_queryID, $type);
639 break;
640 default:
641 $this->fields = @odbtp_fetch_array($this->_queryID, $type);
642 }
643 return is_array($this->fields);
644 }
645
646 function _fetch()
647 {
648 return $this->_fetch_odbtp();
649 }
650
651 function MoveFirst()
652 {
653 if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false;
654 $this->EOF = false;
655 $this->_currentRow = 0;
656 return true;
657 }
658
659 function MoveLast()
660 {
661 if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false;
662 $this->EOF = false;
663 $this->_currentRow = $this->_numOfRows - 1;
664 return true;
665 }
666
667 function NextRecordSet()
668 {
669 if (!@odbtp_next_result($this->_queryID)) return false;
670 $this->_inited = false;
671 $this->bind = false;
672 $this->_currentRow = -1;
673 $this->Init();
674 return true;
675 }
676
677 function _close()
678 {
679 return @odbtp_free_query($this->_queryID);
680 }
681 }
682
683 class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp {
684
685 var $databaseType = 'odbtp_mssql';
686
687 function ADORecordSet_odbtp_mssql($id,$mode=false)
688 {
689 return $this->ADORecordSet_odbtp($id,$mode);
690 }
691 }
692
693 class ADORecordSet_odbtp_access extends ADORecordSet_odbtp {
694
695 var $databaseType = 'odbtp_access';
696
697 function ADORecordSet_odbtp_access($id,$mode=false)
698 {
699 return $this->ADORecordSet_odbtp($id,$mode);
700 }
701 }
702
703 class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp {
704
705 var $databaseType = 'odbtp_vfp';
706
707 function ADORecordSet_odbtp_vfp($id,$mode=false)
708 {
709 return $this->ADORecordSet_odbtp($id,$mode);
710 }
711 }
712
713 class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp {
714
715 var $databaseType = 'odbtp_oci8';
716
717 function ADORecordSet_odbtp_oci8($id,$mode=false)
718 {
719 return $this->ADORecordSet_odbtp($id,$mode);
720 }
721 }
722
723 class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp {
724
725 var $databaseType = 'odbtp_sybase';
726
727 function ADORecordSet_odbtp_sybase($id,$mode=false)
728 {
729 return $this->ADORecordSet_odbtp($id,$mode);
730 }
731 }
732 ?>