Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. See License.txt. 00007 Set tabs to 4 for best viewing. 00008 Latest version is available at http://adodb.sourceforge.net 00009 */ 00010 // Code contributed by "stefan bogdan" <sbogdan#rsb.ro> 00011 00012 // security - hide paths 00013 if (!defined('ADODB_DIR')) die(); 00014 00015 define("_ADODB_ODBTP_LAYER", 2 ); 00016 00017 class ADODB_odbtp extends ADOConnection{ 00018 var $databaseType = "odbtp"; 00019 var $dataProvider = "odbtp"; 00020 var $fmtDate = "'Y-m-d'"; 00021 var $fmtTimeStamp = "'Y-m-d, h:i:sA'"; 00022 var $replaceQuote = "''"; // string to use to replace quotes 00023 var $odbc_driver = 0; 00024 var $hasAffectedRows = true; 00025 var $hasInsertID = false; 00026 var $hasGenID = true; 00027 var $hasMoveFirst = true; 00028 00029 var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)"; 00030 var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'"; 00031 var $_bindInputArray = false; 00032 var $_useUnicodeSQL = false; 00033 var $_canPrepareSP = false; 00034 var $_dontPoolDBC = true; 00035 00036 function ADODB_odbtp() 00037 { 00038 } 00039 00040 function ServerInfo() 00041 { 00042 return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID), 00043 'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID)); 00044 } 00045 00046 function ErrorMsg() 00047 { 00048 if (empty($this->_connectionID)) return @odbtp_last_error(); 00049 return @odbtp_last_error($this->_connectionID); 00050 } 00051 00052 function ErrorNo() 00053 { 00054 if (empty($this->_connectionID)) return @odbtp_last_error_state(); 00055 return @odbtp_last_error_state($this->_connectionID); 00056 } 00057 00058 function _insertid() 00059 { 00060 // SCOPE_IDENTITY() 00061 // Returns the last IDENTITY value inserted into an IDENTITY column in 00062 // the same scope. A scope is a module -- a stored procedure, trigger, 00063 // function, or batch. Thus, two statements are in the same scope if 00064 // they are in the same stored procedure, function, or batch. 00065 return $this->GetOne($this->identitySQL); 00066 } 00067 00068 function _affectedrows() 00069 { 00070 if ($this->_queryID) { 00071 return @odbtp_affected_rows ($this->_queryID); 00072 } else 00073 return 0; 00074 } 00075 00076 function CreateSequence($seqname='adodbseq',$start=1) 00077 { 00078 //verify existence 00079 $num = $this->GetOne("select seq_value from adodb_seq"); 00080 $seqtab='adodb_seq'; 00081 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { 00082 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); 00083 //if using vfp dbc file 00084 if( !strcasecmp(strrchr($path, '.'), '.dbc') ) 00085 $path = substr($path,0,strrpos($path,'\/')); 00086 $seqtab = $path . '/' . $seqtab; 00087 } 00088 if($num == false) { 00089 if (empty($this->_genSeqSQL)) return false; 00090 $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); 00091 } 00092 $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'"); 00093 if ($num) { 00094 return false; 00095 } 00096 $start -= 1; 00097 return $this->Execute("insert into adodb_seq values('$seqname',$start)"); 00098 } 00099 00100 function DropSequence($seqname) 00101 { 00102 if (empty($this->_dropSeqSQL)) return false; 00103 return $this->Execute(sprintf($this->_dropSeqSQL,$seqname)); 00104 } 00105 00106 function GenID($seq='adodbseq',$start=1) 00107 { 00108 $seqtab='adodb_seq'; 00109 if( $this->odbc_driver == ODB_DRIVER_FOXPRO) { 00110 $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID ); 00111 //if using vfp dbc file 00112 if( !strcasecmp(strrchr($path, '.'), '.dbc') ) 00113 $path = substr($path,0,strrpos($path,'\/')); 00114 $seqtab = $path . '/' . $seqtab; 00115 } 00116 $MAXLOOPS = 100; 00117 while (--$MAXLOOPS>=0) { 00118 $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'"); 00119 if ($num === false) { 00120 //verify if abodb_seq table exist 00121 $ok = $this->GetOne("select seq_value from adodb_seq "); 00122 if(!$ok) { 00123 //creating the sequence table adodb_seq 00124 $this->Execute(sprintf($this->_genSeqSQL ,$seqtab)); 00125 } 00126 $start -= 1; 00127 $num = '0'; 00128 $ok = $this->Execute("insert into adodb_seq values('$seq',$start)"); 00129 if (!$ok) return false; 00130 } 00131 $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'"); 00132 if($ok) { 00133 $num += 1; 00134 $this->genID = $num; 00135 return $num; 00136 } 00137 } 00138 if ($fn = $this->raiseErrorFn) { 00139 $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num); 00140 } 00141 return false; 00142 } 00143 00144 //example for $UserOrDSN 00145 //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO; 00146 //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO; 00147 //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=; 00148 //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest; 00149 //if uid & pwd can be separate 00150 function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 00151 { 00152 $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase); 00153 if ($this->_connectionID === false) { 00154 $this->_errorMsg = $this->ErrorMsg() ; 00155 return false; 00156 } 00157 if ($this->_dontPoolDBC) { 00158 if (function_exists('odbtp_dont_pool_dbc')) 00159 @odbtp_dont_pool_dbc($this->_connectionID); 00160 } 00161 else { 00162 $this->_dontPoolDBC = true; 00163 } 00164 $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); 00165 $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID)); 00166 $this->odbc_name = $dbms; 00167 00168 // Account for inconsistent DBMS names 00169 if( $this->odbc_driver == ODB_DRIVER_ORACLE ) 00170 $dbms = 'oracle'; 00171 else if( $this->odbc_driver == ODB_DRIVER_SYBASE ) 00172 $dbms = 'sybase'; 00173 00174 // Set DBMS specific attributes 00175 switch( $dbms ) { 00176 case 'microsoft sql server': 00177 $this->databaseType = 'odbtp_mssql'; 00178 $this->fmtDate = "'Y-m-d'"; 00179 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 00180 $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; 00181 $this->sysTimeStamp = 'GetDate()'; 00182 $this->ansiOuter = true; 00183 $this->leftOuter = '*='; 00184 $this->rightOuter = '=*'; 00185 $this->hasTop = 'top'; 00186 $this->hasInsertID = true; 00187 $this->hasTransactions = true; 00188 $this->_bindInputArray = true; 00189 $this->_canSelectDb = true; 00190 $this->substr = "substring"; 00191 $this->length = 'len'; 00192 $this->identitySQL = 'select @@IDENTITY'; 00193 $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; 00194 $this->_canPrepareSP = true; 00195 break; 00196 case 'access': 00197 $this->databaseType = 'odbtp_access'; 00198 $this->fmtDate = "#Y-m-d#"; 00199 $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; 00200 $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; 00201 $this->sysTimeStamp = 'NOW'; 00202 $this->hasTop = 'top'; 00203 $this->hasTransactions = false; 00204 $this->_canPrepareSP = true; // For MS Access only. 00205 break; 00206 case 'visual foxpro': 00207 $this->databaseType = 'odbtp_vfp'; 00208 $this->fmtDate = "{^Y-m-d}"; 00209 $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; 00210 $this->sysDate = 'date()'; 00211 $this->sysTimeStamp = 'datetime()'; 00212 $this->ansiOuter = true; 00213 $this->hasTop = 'top'; 00214 $this->hasTransactions = false; 00215 $this->replaceQuote = "'+chr(39)+'"; 00216 $this->true = '.T.'; 00217 $this->false = '.F.'; 00218 break; 00219 case 'oracle': 00220 $this->databaseType = 'odbtp_oci8'; 00221 $this->fmtDate = "'Y-m-d 00:00:00'"; 00222 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 00223 $this->sysDate = 'TRUNC(SYSDATE)'; 00224 $this->sysTimeStamp = 'SYSDATE'; 00225 $this->hasTransactions = true; 00226 $this->_bindInputArray = true; 00227 $this->concat_operator = '||'; 00228 break; 00229 case 'sybase': 00230 $this->databaseType = 'odbtp_sybase'; 00231 $this->fmtDate = "'Y-m-d'"; 00232 $this->fmtTimeStamp = "'Y-m-d H:i:s'"; 00233 $this->sysDate = 'GetDate()'; 00234 $this->sysTimeStamp = 'GetDate()'; 00235 $this->leftOuter = '*='; 00236 $this->rightOuter = '=*'; 00237 $this->hasInsertID = true; 00238 $this->hasTransactions = true; 00239 $this->identitySQL = 'select @@IDENTITY'; 00240 break; 00241 default: 00242 $this->databaseType = 'odbtp'; 00243 if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) 00244 $this->hasTransactions = true; 00245 else 00246 $this->hasTransactions = false; 00247 } 00248 @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID ); 00249 00250 if ($this->_useUnicodeSQL ) 00251 @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); 00252 00253 return true; 00254 } 00255 00256 function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 00257 { 00258 $this->_dontPoolDBC = false; 00259 return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); 00260 } 00261 00262 function SelectDB($dbName) 00263 { 00264 if (!@odbtp_select_db($dbName, $this->_connectionID)) { 00265 return false; 00266 } 00267 $this->database = $dbName; 00268 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions 00269 return true; 00270 } 00271 00272 function &MetaTables($ttype='',$showSchema=false,$mask=false) 00273 { 00274 global $ADODB_FETCH_MODE; 00275 00276 $savem = $ADODB_FETCH_MODE; 00277 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00278 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 00279 00280 $arr =& $this->GetArray("||SQLTables||||$ttype"); 00281 00282 if (isset($savefm)) $this->SetFetchMode($savefm); 00283 $ADODB_FETCH_MODE = $savem; 00284 00285 $arr2 = array(); 00286 for ($i=0; $i < sizeof($arr); $i++) { 00287 if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; 00288 if ($arr[$i][2]) 00289 $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; 00290 } 00291 return $arr2; 00292 } 00293 00294 function &MetaColumns($table,$upper=true) 00295 { 00296 global $ADODB_FETCH_MODE; 00297 00298 $schema = false; 00299 $this->_findschema($table,$schema); 00300 if ($upper) $table = strtoupper($table); 00301 00302 $savem = $ADODB_FETCH_MODE; 00303 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00304 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 00305 00306 $rs = $this->Execute( "||SQLColumns||$schema|$table" ); 00307 00308 if (isset($savefm)) $this->SetFetchMode($savefm); 00309 $ADODB_FETCH_MODE = $savem; 00310 00311 if (!$rs || $rs->EOF) { 00312 $false = false; 00313 return $false; 00314 } 00315 $retarr = array(); 00316 while (!$rs->EOF) { 00317 //print_r($rs->fields); 00318 if (strtoupper($rs->fields[2]) == $table) { 00319 $fld = new ADOFieldObject(); 00320 $fld->name = $rs->fields[3]; 00321 $fld->type = $rs->fields[5]; 00322 $fld->max_length = $rs->fields[6]; 00323 $fld->not_null = !empty($rs->fields[9]); 00324 $fld->scale = $rs->fields[7]; 00325 if (!is_null($rs->fields[12])) { 00326 $fld->has_default = true; 00327 $fld->default_value = $rs->fields[12]; 00328 } 00329 $retarr[strtoupper($fld->name)] = $fld; 00330 } else if (!empty($retarr)) 00331 break; 00332 $rs->MoveNext(); 00333 } 00334 $rs->Close(); 00335 00336 return $retarr; 00337 } 00338 00339 function &MetaPrimaryKeys($table, $owner='') 00340 { 00341 global $ADODB_FETCH_MODE; 00342 00343 $savem = $ADODB_FETCH_MODE; 00344 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00345 $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table"); 00346 $ADODB_FETCH_MODE = $savem; 00347 00348 //print_r($arr); 00349 $arr2 = array(); 00350 for ($i=0; $i < sizeof($arr); $i++) { 00351 if ($arr[$i][3]) $arr2[] = $arr[$i][3]; 00352 } 00353 return $arr2; 00354 } 00355 00356 function &MetaForeignKeys($table, $owner='', $upper=false) 00357 { 00358 global $ADODB_FETCH_MODE; 00359 00360 $savem = $ADODB_FETCH_MODE; 00361 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00362 $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table"); 00363 $ADODB_FETCH_MODE = $savem; 00364 00365 $arr = false; 00366 foreach($constraints as $constr) { 00367 //print_r($constr); 00368 $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; 00369 } 00370 if (!$arr) { 00371 $false = false; 00372 return $false; 00373 } 00374 00375 $arr2 = array(); 00376 00377 foreach($arr as $k => $v) { 00378 foreach($v as $a => $b) { 00379 if ($upper) $a = strtoupper($a); 00380 $arr2[$a] = $b; 00381 } 00382 } 00383 return $arr2; 00384 } 00385 00386 function BeginTrans() 00387 { 00388 if (!$this->hasTransactions) return false; 00389 if ($this->transOff) return true; 00390 $this->transCnt += 1; 00391 $this->autoCommit = false; 00392 if (defined('ODB_TXN_DEFAULT')) 00393 $txn = ODB_TXN_DEFAULT; 00394 else 00395 $txn = ODB_TXN_READUNCOMMITTED; 00396 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID); 00397 if(!$rs) return false; 00398 return true; 00399 } 00400 00401 function CommitTrans($ok=true) 00402 { 00403 if ($this->transOff) return true; 00404 if (!$ok) return $this->RollbackTrans(); 00405 if ($this->transCnt) $this->transCnt -= 1; 00406 $this->autoCommit = true; 00407 if( ($ret = @odbtp_commit($this->_connectionID)) ) 00408 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 00409 return $ret; 00410 } 00411 00412 function RollbackTrans() 00413 { 00414 if ($this->transOff) return true; 00415 if ($this->transCnt) $this->transCnt -= 1; 00416 $this->autoCommit = true; 00417 if( ($ret = @odbtp_rollback($this->_connectionID)) ) 00418 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 00419 return $ret; 00420 } 00421 00422 function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 00423 { 00424 // TOP requires ORDER BY for Visual FoxPro 00425 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { 00426 if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; 00427 } 00428 $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 00429 return $ret; 00430 } 00431 00432 function Prepare($sql) 00433 { 00434 if (! $this->_bindInputArray) return $sql; // no binding 00435 $stmt = @odbtp_prepare($sql,$this->_connectionID); 00436 if (!$stmt) { 00437 // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>"; 00438 return $sql; 00439 } 00440 return array($sql,$stmt,false); 00441 } 00442 00443 function PrepareSP($sql) 00444 { 00445 if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures 00446 00447 $stmt = @odbtp_prepare_proc($sql,$this->_connectionID); 00448 if (!$stmt) return false; 00449 return array($sql,$stmt); 00450 } 00451 00452 /* 00453 Usage: 00454 $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group 00455 00456 # note that the parameter does not have @ in front! 00457 $db->Parameter($stmt,$id,'myid'); 00458 $db->Parameter($stmt,$group,'group',false,64); 00459 $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY); 00460 $db->Execute($stmt); 00461 00462 @param $stmt Statement returned by Prepare() or PrepareSP(). 00463 @param $var PHP variable to bind to. Can set to null (for isNull support). 00464 @param $name Name of stored procedure variable name to bind to. 00465 @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp. 00466 @param [$maxLen] Holds an maximum length of the variable. 00467 @param [$type] The data type of $var. Legal values depend on driver. 00468 00469 See odbtp_attach_param documentation at http://odbtp.sourceforge.net. 00470 */ 00471 function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0) 00472 { 00473 if ( $this->odbc_driver == ODB_DRIVER_JET ) { 00474 $name = '['.$name.']'; 00475 if( !$type && $this->_useUnicodeSQL 00476 && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR ) 00477 { 00478 $type = ODB_WCHAR; 00479 } 00480 } 00481 else { 00482 $name = '@'.$name; 00483 } 00484 return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); 00485 } 00486 00487 /* 00488 Insert a null into the blob field of the table first. 00489 Then use UpdateBlob to store the blob. 00490 00491 Usage: 00492 00493 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 00494 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 00495 */ 00496 00497 function UpdateBlob($table,$column,$val,$where,$blobtype='image') 00498 { 00499 $sql = "UPDATE $table SET $column = ? WHERE $where"; 00500 if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) ) 00501 return false; 00502 if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) 00503 return false; 00504 if( !@odbtp_set( $stmt, 1, $val ) ) 00505 return false; 00506 return @odbtp_execute( $stmt ) != false; 00507 } 00508 00509 function IfNull( $field, $ifNull ) 00510 { 00511 switch( $this->odbc_driver ) { 00512 case ODB_DRIVER_MSSQL: 00513 return " ISNULL($field, $ifNull) "; 00514 case ODB_DRIVER_JET: 00515 return " IIF(IsNull($field), $ifNull, $field) "; 00516 } 00517 return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; 00518 } 00519 00520 function _query($sql,$inputarr=false) 00521 { 00522 global $php_errormsg; 00523 00524 if ($inputarr) { 00525 if (is_array($sql)) { 00526 $stmtid = $sql[1]; 00527 } else { 00528 $stmtid = @odbtp_prepare($sql,$this->_connectionID); 00529 if ($stmtid == false) { 00530 $this->_errorMsg = $php_errormsg; 00531 return false; 00532 } 00533 } 00534 $num_params = @odbtp_num_params( $stmtid ); 00535 for( $param = 1; $param <= $num_params; $param++ ) { 00536 @odbtp_input( $stmtid, $param ); 00537 @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); 00538 } 00539 if (!@odbtp_execute($stmtid) ) { 00540 return false; 00541 } 00542 } else if (is_array($sql)) { 00543 $stmtid = $sql[1]; 00544 if (!@odbtp_execute($stmtid)) { 00545 return false; 00546 } 00547 } else { 00548 $stmtid = @odbtp_query($sql,$this->_connectionID); 00549 } 00550 $this->_lastAffectedRows = 0; 00551 if ($stmtid) { 00552 $this->_lastAffectedRows = @odbtp_affected_rows($stmtid); 00553 } 00554 return $stmtid; 00555 } 00556 00557 function _close() 00558 { 00559 $ret = @odbtp_close($this->_connectionID); 00560 $this->_connectionID = false; 00561 return $ret; 00562 } 00563 } 00564 00565 class ADORecordSet_odbtp extends ADORecordSet { 00566 00567 var $databaseType = 'odbtp'; 00568 var $canSeek = true; 00569 00570 function ADORecordSet_odbtp($queryID,$mode=false) 00571 { 00572 if ($mode === false) { 00573 global $ADODB_FETCH_MODE; 00574 $mode = $ADODB_FETCH_MODE; 00575 } 00576 $this->fetchMode = $mode; 00577 $this->ADORecordSet($queryID); 00578 } 00579 00580 function _initrs() 00581 { 00582 $this->_numOfFields = @odbtp_num_fields($this->_queryID); 00583 if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) 00584 $this->_numOfRows = -1; 00585 00586 if (!$this->connection->_useUnicodeSQL) return; 00587 00588 if ($this->connection->odbc_driver == ODB_DRIVER_JET) { 00589 if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR, 00590 $this->connection->_connectionID)) 00591 { 00592 for ($f = 0; $f < $this->_numOfFields; $f++) { 00593 if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) 00594 @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); 00595 } 00596 } 00597 } 00598 } 00599 00600 function &FetchField($fieldOffset = 0) 00601 { 00602 $off=$fieldOffset; // offsets begin at 0 00603 $o= new ADOFieldObject(); 00604 $o->name = @odbtp_field_name($this->_queryID,$off); 00605 $o->type = @odbtp_field_type($this->_queryID,$off); 00606 $o->max_length = @odbtp_field_length($this->_queryID,$off); 00607 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); 00608 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); 00609 return $o; 00610 } 00611 00612 function _seek($row) 00613 { 00614 return @odbtp_data_seek($this->_queryID, $row); 00615 } 00616 00617 function fields($colname) 00618 { 00619 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 00620 00621 if (!$this->bind) { 00622 $this->bind = array(); 00623 for ($i=0; $i < $this->_numOfFields; $i++) { 00624 $name = @odbtp_field_name( $this->_queryID, $i ); 00625 $this->bind[strtoupper($name)] = $i; 00626 } 00627 } 00628 return $this->fields[$this->bind[strtoupper($colname)]]; 00629 } 00630 00631 function _fetch_odbtp($type=0) 00632 { 00633 switch ($this->fetchMode) { 00634 case ADODB_FETCH_NUM: 00635 $this->fields = @odbtp_fetch_row($this->_queryID, $type); 00636 break; 00637 case ADODB_FETCH_ASSOC: 00638 $this->fields = @odbtp_fetch_assoc($this->_queryID, $type); 00639 break; 00640 default: 00641 $this->fields = @odbtp_fetch_array($this->_queryID, $type); 00642 } 00643 return is_array($this->fields); 00644 } 00645 00646 function _fetch() 00647 { 00648 return $this->_fetch_odbtp(); 00649 } 00650 00651 function MoveFirst() 00652 { 00653 if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; 00654 $this->EOF = false; 00655 $this->_currentRow = 0; 00656 return true; 00657 } 00658 00659 function MoveLast() 00660 { 00661 if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; 00662 $this->EOF = false; 00663 $this->_currentRow = $this->_numOfRows - 1; 00664 return true; 00665 } 00666 00667 function NextRecordSet() 00668 { 00669 if (!@odbtp_next_result($this->_queryID)) return false; 00670 $this->_inited = false; 00671 $this->bind = false; 00672 $this->_currentRow = -1; 00673 $this->Init(); 00674 return true; 00675 } 00676 00677 function _close() 00678 { 00679 return @odbtp_free_query($this->_queryID); 00680 } 00681 } 00682 00683 class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp { 00684 00685 var $databaseType = 'odbtp_mssql'; 00686 00687 function ADORecordSet_odbtp_mssql($id,$mode=false) 00688 { 00689 return $this->ADORecordSet_odbtp($id,$mode); 00690 } 00691 } 00692 00693 class ADORecordSet_odbtp_access extends ADORecordSet_odbtp { 00694 00695 var $databaseType = 'odbtp_access'; 00696 00697 function ADORecordSet_odbtp_access($id,$mode=false) 00698 { 00699 return $this->ADORecordSet_odbtp($id,$mode); 00700 } 00701 } 00702 00703 class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp { 00704 00705 var $databaseType = 'odbtp_vfp'; 00706 00707 function ADORecordSet_odbtp_vfp($id,$mode=false) 00708 { 00709 return $this->ADORecordSet_odbtp($id,$mode); 00710 } 00711 } 00712 00713 class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp { 00714 00715 var $databaseType = 'odbtp_oci8'; 00716 00717 function ADORecordSet_odbtp_oci8($id,$mode=false) 00718 { 00719 return $this->ADORecordSet_odbtp($id,$mode); 00720 } 00721 } 00722 00723 class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp { 00724 00725 var $databaseType = 'odbtp_sybase'; 00726 00727 function ADORecordSet_odbtp_sybase($id,$mode=false) 00728 { 00729 return $this->ADORecordSet_odbtp($id,$mode); 00730 } 00731 } 00732 ?>