402b22600fe7a4ffeeec236e44d044094a2dbbc0
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-odbtp.inc.php
1 <?php
2 /*
3 V4.93 10 Oct 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 odbtp_convert_datetime($this->_connectionID,true);
154
155 if ($this->_connectionID === false) {
156 $this->_errorMsg = $this->ErrorMsg() ;
157 return false;
158 }
159 if ($this->_dontPoolDBC) {
160 if (function_exists('odbtp_dont_pool_dbc'))
161 @odbtp_dont_pool_dbc($this->_connectionID);
162 }
163 else {
164 $this->_dontPoolDBC = true;
165 }
166 $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID);
167 $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID));
168 $this->odbc_name = $dbms;
169
170 // Account for inconsistent DBMS names
171 if( $this->odbc_driver == ODB_DRIVER_ORACLE )
172 $dbms = 'oracle';
173 else if( $this->odbc_driver == ODB_DRIVER_SYBASE )
174 $dbms = 'sybase';
175
176 // Set DBMS specific attributes
177 switch( $dbms ) {
178 case 'microsoft sql server':
179 $this->databaseType = 'odbtp_mssql';
180 $this->fmtDate = "'Y-m-d'";
181 $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
182 $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
183 $this->sysTimeStamp = 'GetDate()';
184 $this->ansiOuter = true;
185 $this->leftOuter = '*=';
186 $this->rightOuter = '=*';
187 $this->hasTop = 'top';
188 $this->hasInsertID = true;
189 $this->hasTransactions = true;
190 $this->_bindInputArray = true;
191 $this->_canSelectDb = true;
192 $this->substr = "substring";
193 $this->length = 'len';
194 $this->identitySQL = 'select @@IDENTITY';
195 $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'";
196 $this->_canPrepareSP = true;
197 break;
198 case 'access':
199 $this->databaseType = 'odbtp_access';
200 $this->fmtDate = "#Y-m-d#";
201 $this->fmtTimeStamp = "#Y-m-d h:i:sA#";
202 $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
203 $this->sysTimeStamp = 'NOW';
204 $this->hasTop = 'top';
205 $this->hasTransactions = false;
206 $this->_canPrepareSP = true; // For MS Access only.
207 break;
208 case 'visual foxpro':
209 $this->databaseType = 'odbtp_vfp';
210 $this->fmtDate = "{^Y-m-d}";
211 $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}";
212 $this->sysDate = 'date()';
213 $this->sysTimeStamp = 'datetime()';
214 $this->ansiOuter = true;
215 $this->hasTop = 'top';
216 $this->hasTransactions = false;
217 $this->replaceQuote = "'+chr(39)+'";
218 $this->true = '.T.';
219 $this->false = '.F.';
220 break;
221 case 'oracle':
222 $this->databaseType = 'odbtp_oci8';
223 $this->fmtDate = "'Y-m-d 00:00:00'";
224 $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
225 $this->sysDate = 'TRUNC(SYSDATE)';
226 $this->sysTimeStamp = 'SYSDATE';
227 $this->hasTransactions = true;
228 $this->_bindInputArray = true;
229 $this->concat_operator = '||';
230 break;
231 case 'sybase':
232 $this->databaseType = 'odbtp_sybase';
233 $this->fmtDate = "'Y-m-d'";
234 $this->fmtTimeStamp = "'Y-m-d H:i:s'";
235 $this->sysDate = 'GetDate()';
236 $this->sysTimeStamp = 'GetDate()';
237 $this->leftOuter = '*=';
238 $this->rightOuter = '=*';
239 $this->hasInsertID = true;
240 $this->hasTransactions = true;
241 $this->identitySQL = 'select @@IDENTITY';
242 break;
243 default:
244 $this->databaseType = 'odbtp';
245 if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) )
246 $this->hasTransactions = true;
247 else
248 $this->hasTransactions = false;
249 }
250 @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID );
251
252 if ($this->_useUnicodeSQL )
253 @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID);
254
255 return true;
256 }
257
258 function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
259 {
260 $this->_dontPoolDBC = false;
261 return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase);
262 }
263
264 function SelectDB($dbName)
265 {
266 if (!@odbtp_select_db($dbName, $this->_connectionID)) {
267 return false;
268 }
269 $this->database = $dbName;
270 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
271 return true;
272 }
273
274 function &MetaTables($ttype='',$showSchema=false,$mask=false)
275 {
276 global $ADODB_FETCH_MODE;
277
278 $savem = $ADODB_FETCH_MODE;
279 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
280 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
281
282 $arr =& $this->GetArray("||SQLTables||||$ttype");
283
284 if (isset($savefm)) $this->SetFetchMode($savefm);
285 $ADODB_FETCH_MODE = $savem;
286
287 $arr2 = array();
288 for ($i=0; $i < sizeof($arr); $i++) {
289 if ($arr[$i][3] == 'SYSTEM TABLE' ) continue;
290 if ($arr[$i][2])
291 $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];
292 }
293 return $arr2;
294 }
295
296 function &MetaColumns($table,$upper=true)
297 {
298 global $ADODB_FETCH_MODE;
299
300 $schema = false;
301 $this->_findschema($table,$schema);
302 if ($upper) $table = strtoupper($table);
303
304 $savem = $ADODB_FETCH_MODE;
305 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
306 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
307
308 $rs = $this->Execute( "||SQLColumns||$schema|$table" );
309
310 if (isset($savefm)) $this->SetFetchMode($savefm);
311 $ADODB_FETCH_MODE = $savem;
312
313 if (!$rs || $rs->EOF) {
314 $false = false;
315 return $false;
316 }
317 $retarr = array();
318 while (!$rs->EOF) {
319 //print_r($rs->fields);
320 if (strtoupper($rs->fields[2]) == $table) {
321 $fld = new ADOFieldObject();
322 $fld->name = $rs->fields[3];
323 $fld->type = $rs->fields[5];
324 $fld->max_length = $rs->fields[6];
325 $fld->not_null = !empty($rs->fields[9]);
326 $fld->scale = $rs->fields[7];
327 if (!is_null($rs->fields[12])) {
328 $fld->has_default = true;
329 $fld->default_value = $rs->fields[12];
330 }
331 $retarr[strtoupper($fld->name)] = $fld;
332 } else if (!empty($retarr))
333 break;
334 $rs->MoveNext();
335 }
336 $rs->Close();
337
338 return $retarr;
339 }
340
341 function &MetaPrimaryKeys($table, $owner='')
342 {
343 global $ADODB_FETCH_MODE;
344
345 $savem = $ADODB_FETCH_MODE;
346 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
347 $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table");
348 $ADODB_FETCH_MODE = $savem;
349
350 //print_r($arr);
351 $arr2 = array();
352 for ($i=0; $i < sizeof($arr); $i++) {
353 if ($arr[$i][3]) $arr2[] = $arr[$i][3];
354 }
355 return $arr2;
356 }
357
358 function &MetaForeignKeys($table, $owner='', $upper=false)
359 {
360 global $ADODB_FETCH_MODE;
361
362 $savem = $ADODB_FETCH_MODE;
363 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
364 $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table");
365 $ADODB_FETCH_MODE = $savem;
366
367 $arr = false;
368 foreach($constraints as $constr) {
369 //print_r($constr);
370 $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3];
371 }
372 if (!$arr) {
373 $false = false;
374 return $false;
375 }
376
377 $arr2 = array();
378
379 foreach($arr as $k => $v) {
380 foreach($v as $a => $b) {
381 if ($upper) $a = strtoupper($a);
382 $arr2[$a] = $b;
383 }
384 }
385 return $arr2;
386 }
387
388 function BeginTrans()
389 {
390 if (!$this->hasTransactions) return false;
391 if ($this->transOff) return true;
392 $this->transCnt += 1;
393 $this->autoCommit = false;
394 if (defined('ODB_TXN_DEFAULT'))
395 $txn = ODB_TXN_DEFAULT;
396 else
397 $txn = ODB_TXN_READUNCOMMITTED;
398 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID);
399 if(!$rs) return false;
400 return true;
401 }
402
403 function CommitTrans($ok=true)
404 {
405 if ($this->transOff) return true;
406 if (!$ok) return $this->RollbackTrans();
407 if ($this->transCnt) $this->transCnt -= 1;
408 $this->autoCommit = true;
409 if( ($ret = @odbtp_commit($this->_connectionID)) )
410 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
411 return $ret;
412 }
413
414 function RollbackTrans()
415 {
416 if ($this->transOff) return true;
417 if ($this->transCnt) $this->transCnt -= 1;
418 $this->autoCommit = true;
419 if( ($ret = @odbtp_rollback($this->_connectionID)) )
420 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
421 return $ret;
422 }
423
424 function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
425 {
426 // TOP requires ORDER BY for Visual FoxPro
427 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
428 if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1';
429 }
430 $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
431 return $ret;
432 }
433
434 function Prepare($sql)
435 {
436 if (! $this->_bindInputArray) return $sql; // no binding
437 $stmt = @odbtp_prepare($sql,$this->_connectionID);
438 if (!$stmt) {
439 // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>";
440 return $sql;
441 }
442 return array($sql,$stmt,false);
443 }
444
445 function PrepareSP($sql)
446 {
447 if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures
448
449 $stmt = @odbtp_prepare_proc($sql,$this->_connectionID);
450 if (!$stmt) return false;
451 return array($sql,$stmt);
452 }
453
454 /*
455 Usage:
456 $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group
457
458 # note that the parameter does not have @ in front!
459 $db->Parameter($stmt,$id,'myid');
460 $db->Parameter($stmt,$group,'group',false,64);
461 $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY);
462 $db->Execute($stmt);
463
464 @param $stmt Statement returned by Prepare() or PrepareSP().
465 @param $var PHP variable to bind to. Can set to null (for isNull support).
466 @param $name Name of stored procedure variable name to bind to.
467 @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp.
468 @param [$maxLen] Holds an maximum length of the variable.
469 @param [$type] The data type of $var. Legal values depend on driver.
470
471 See odbtp_attach_param documentation at http://odbtp.sourceforge.net.
472 */
473 function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0)
474 {
475 if ( $this->odbc_driver == ODB_DRIVER_JET ) {
476 $name = '['.$name.']';
477 if( !$type && $this->_useUnicodeSQL
478 && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR )
479 {
480 $type = ODB_WCHAR;
481 }
482 }
483 else {
484 $name = '@'.$name;
485 }
486 return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen);
487 }
488
489 /*
490 Insert a null into the blob field of the table first.
491 Then use UpdateBlob to store the blob.
492
493 Usage:
494
495 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
496 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
497 */
498
499 function UpdateBlob($table,$column,$val,$where,$blobtype='image')
500 {
501 $sql = "UPDATE $table SET $column = ? WHERE $where";
502 if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) )
503 return false;
504 if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) )
505 return false;
506 if( !@odbtp_set( $stmt, 1, $val ) )
507 return false;
508 return @odbtp_execute( $stmt ) != false;
509 }
510
511 function IfNull( $field, $ifNull )
512 {
513 switch( $this->odbc_driver ) {
514 case ODB_DRIVER_MSSQL:
515 return " ISNULL($field, $ifNull) ";
516 case ODB_DRIVER_JET:
517 return " IIF(IsNull($field), $ifNull, $field) ";
518 }
519 return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
520 }
521
522 function _query($sql,$inputarr=false)
523 {
524 global $php_errormsg;
525
526 if ($inputarr) {
527 if (is_array($sql)) {
528 $stmtid = $sql[1];
529 } else {
530 $stmtid = @odbtp_prepare($sql,$this->_connectionID);
531 if ($stmtid == false) {
532 $this->_errorMsg = $php_errormsg;
533 return false;
534 }
535 }
536 $num_params = @odbtp_num_params( $stmtid );
537 for( $param = 1; $param <= $num_params; $param++ ) {
538 @odbtp_input( $stmtid, $param );
539 @odbtp_set( $stmtid, $param, $inputarr[$param-1] );
540 }
541 if (!@odbtp_execute($stmtid) ) {
542 return false;
543 }
544 } else if (is_array($sql)) {
545 $stmtid = $sql[1];
546 if (!@odbtp_execute($stmtid)) {
547 return false;
548 }
549 } else {
550 $stmtid = @odbtp_query($sql,$this->_connectionID);
551 }
552 $this->_lastAffectedRows = 0;
553 if ($stmtid) {
554 $this->_lastAffectedRows = @odbtp_affected_rows($stmtid);
555 }
556 return $stmtid;
557 }
558
559 function _close()
560 {
561 $ret = @odbtp_close($this->_connectionID);
562 $this->_connectionID = false;
563 return $ret;
564 }
565 }
566
567 class ADORecordSet_odbtp extends ADORecordSet {
568
569 var $databaseType = 'odbtp';
570 var $canSeek = true;
571
572 function ADORecordSet_odbtp($queryID,$mode=false)
573 {
574 if ($mode === false) {
575 global $ADODB_FETCH_MODE;
576 $mode = $ADODB_FETCH_MODE;
577 }
578 $this->fetchMode = $mode;
579 $this->ADORecordSet($queryID);
580 }
581
582 function _initrs()
583 {
584 $this->_numOfFields = @odbtp_num_fields($this->_queryID);
585 if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID)))
586 $this->_numOfRows = -1;
587
588 if (!$this->connection->_useUnicodeSQL) return;
589
590 if ($this->connection->odbc_driver == ODB_DRIVER_JET) {
591 if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR,
592 $this->connection->_connectionID))
593 {
594 for ($f = 0; $f < $this->_numOfFields; $f++) {
595 if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR)
596 @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR);
597 }
598 }
599 }
600 }
601
602 function &FetchField($fieldOffset = 0)
603 {
604 $off=$fieldOffset; // offsets begin at 0
605 $o= new ADOFieldObject();
606 $o->name = @odbtp_field_name($this->_queryID,$off);
607 $o->type = @odbtp_field_type($this->_queryID,$off);
608 $o->max_length = @odbtp_field_length($this->_queryID,$off);
609 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
610 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
611 return $o;
612 }
613
614 function _seek($row)
615 {
616 return @odbtp_data_seek($this->_queryID, $row);
617 }
618
619 function fields($colname)
620 {
621 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
622
623 if (!$this->bind) {
624 $this->bind = array();
625 for ($i=0; $i < $this->_numOfFields; $i++) {
626 $name = @odbtp_field_name( $this->_queryID, $i );
627 $this->bind[strtoupper($name)] = $i;
628 }
629 }
630 return $this->fields[$this->bind[strtoupper($colname)]];
631 }
632
633 function _fetch_odbtp($type=0)
634 {
635 switch ($this->fetchMode) {
636 case ADODB_FETCH_NUM:
637 $this->fields = @odbtp_fetch_row($this->_queryID, $type);
638 break;
639 case ADODB_FETCH_ASSOC:
640 $this->fields = @odbtp_fetch_assoc($this->_queryID, $type);
641 break;
642 default:
643 $this->fields = @odbtp_fetch_array($this->_queryID, $type);
644 }
645 return is_array($this->fields);
646 }
647
648 function _fetch()
649 {
650 return $this->_fetch_odbtp();
651 }
652
653 function MoveFirst()
654 {
655 if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false;
656 $this->EOF = false;
657 $this->_currentRow = 0;
658 return true;
659 }
660
661 function MoveLast()
662 {
663 if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false;
664 $this->EOF = false;
665 $this->_currentRow = $this->_numOfRows - 1;
666 return true;
667 }
668
669 function NextRecordSet()
670 {
671 if (!@odbtp_next_result($this->_queryID)) return false;
672 $this->_inited = false;
673 $this->bind = false;
674 $this->_currentRow = -1;
675 $this->Init();
676 return true;
677 }
678
679 function _close()
680 {
681 return @odbtp_free_query($this->_queryID);
682 }
683 }
684
685 class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp {
686
687 var $databaseType = 'odbtp_mssql';
688
689 function ADORecordSet_odbtp_mssql($id,$mode=false)
690 {
691 return $this->ADORecordSet_odbtp($id,$mode);
692 }
693 }
694
695 class ADORecordSet_odbtp_access extends ADORecordSet_odbtp {
696
697 var $databaseType = 'odbtp_access';
698
699 function ADORecordSet_odbtp_access($id,$mode=false)
700 {
701 return $this->ADORecordSet_odbtp($id,$mode);
702 }
703 }
704
705 class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp {
706
707 var $databaseType = 'odbtp_vfp';
708
709 function ADORecordSet_odbtp_vfp($id,$mode=false)
710 {
711 return $this->ADORecordSet_odbtp($id,$mode);
712 }
713 }
714
715 class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp {
716
717 var $databaseType = 'odbtp_oci8';
718
719 function ADORecordSet_odbtp_oci8($id,$mode=false)
720 {
721 return $this->ADORecordSet_odbtp($id,$mode);
722 }
723 }
724
725 class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp {
726
727 var $databaseType = 'odbtp_sybase';
728
729 function ADORecordSet_odbtp_sybase($id,$mode=false)
730 {
731 return $this->ADORecordSet_odbtp($id,$mode);
732 }
733 }
734 ?>