Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 V4.93 10 Oct 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 odbtp_convert_datetime($this->_connectionID,true); 00154 00155 if ($this->_connectionID === false) { 00156 $this->_errorMsg = $this->ErrorMsg() ; 00157 return false; 00158 } 00159 if ($this->_dontPoolDBC) { 00160 if (function_exists('odbtp_dont_pool_dbc')) 00161 @odbtp_dont_pool_dbc($this->_connectionID); 00162 } 00163 else { 00164 $this->_dontPoolDBC = true; 00165 } 00166 $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID); 00167 $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID)); 00168 $this->odbc_name = $dbms; 00169 00170 // Account for inconsistent DBMS names 00171 if( $this->odbc_driver == ODB_DRIVER_ORACLE ) 00172 $dbms = 'oracle'; 00173 else if( $this->odbc_driver == ODB_DRIVER_SYBASE ) 00174 $dbms = 'sybase'; 00175 00176 // Set DBMS specific attributes 00177 switch( $dbms ) { 00178 case 'microsoft sql server': 00179 $this->databaseType = 'odbtp_mssql'; 00180 $this->fmtDate = "'Y-m-d'"; 00181 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 00182 $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)'; 00183 $this->sysTimeStamp = 'GetDate()'; 00184 $this->ansiOuter = true; 00185 $this->leftOuter = '*='; 00186 $this->rightOuter = '=*'; 00187 $this->hasTop = 'top'; 00188 $this->hasInsertID = true; 00189 $this->hasTransactions = true; 00190 $this->_bindInputArray = true; 00191 $this->_canSelectDb = true; 00192 $this->substr = "substring"; 00193 $this->length = 'len'; 00194 $this->identitySQL = 'select @@IDENTITY'; 00195 $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'"; 00196 $this->_canPrepareSP = true; 00197 break; 00198 case 'access': 00199 $this->databaseType = 'odbtp_access'; 00200 $this->fmtDate = "#Y-m-d#"; 00201 $this->fmtTimeStamp = "#Y-m-d h:i:sA#"; 00202 $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')"; 00203 $this->sysTimeStamp = 'NOW'; 00204 $this->hasTop = 'top'; 00205 $this->hasTransactions = false; 00206 $this->_canPrepareSP = true; // For MS Access only. 00207 break; 00208 case 'visual foxpro': 00209 $this->databaseType = 'odbtp_vfp'; 00210 $this->fmtDate = "{^Y-m-d}"; 00211 $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}"; 00212 $this->sysDate = 'date()'; 00213 $this->sysTimeStamp = 'datetime()'; 00214 $this->ansiOuter = true; 00215 $this->hasTop = 'top'; 00216 $this->hasTransactions = false; 00217 $this->replaceQuote = "'+chr(39)+'"; 00218 $this->true = '.T.'; 00219 $this->false = '.F.'; 00220 break; 00221 case 'oracle': 00222 $this->databaseType = 'odbtp_oci8'; 00223 $this->fmtDate = "'Y-m-d 00:00:00'"; 00224 $this->fmtTimeStamp = "'Y-m-d h:i:sA'"; 00225 $this->sysDate = 'TRUNC(SYSDATE)'; 00226 $this->sysTimeStamp = 'SYSDATE'; 00227 $this->hasTransactions = true; 00228 $this->_bindInputArray = true; 00229 $this->concat_operator = '||'; 00230 break; 00231 case 'sybase': 00232 $this->databaseType = 'odbtp_sybase'; 00233 $this->fmtDate = "'Y-m-d'"; 00234 $this->fmtTimeStamp = "'Y-m-d H:i:s'"; 00235 $this->sysDate = 'GetDate()'; 00236 $this->sysTimeStamp = 'GetDate()'; 00237 $this->leftOuter = '*='; 00238 $this->rightOuter = '=*'; 00239 $this->hasInsertID = true; 00240 $this->hasTransactions = true; 00241 $this->identitySQL = 'select @@IDENTITY'; 00242 break; 00243 default: 00244 $this->databaseType = 'odbtp'; 00245 if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) ) 00246 $this->hasTransactions = true; 00247 else 00248 $this->hasTransactions = false; 00249 } 00250 @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID ); 00251 00252 if ($this->_useUnicodeSQL ) 00253 @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID); 00254 00255 return true; 00256 } 00257 00258 function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='') 00259 { 00260 $this->_dontPoolDBC = false; 00261 return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase); 00262 } 00263 00264 function SelectDB($dbName) 00265 { 00266 if (!@odbtp_select_db($dbName, $this->_connectionID)) { 00267 return false; 00268 } 00269 $this->database = $dbName; 00270 $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions 00271 return true; 00272 } 00273 00274 function &MetaTables($ttype='',$showSchema=false,$mask=false) 00275 { 00276 global $ADODB_FETCH_MODE; 00277 00278 $savem = $ADODB_FETCH_MODE; 00279 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00280 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 00281 00282 $arr =& $this->GetArray("||SQLTables||||$ttype"); 00283 00284 if (isset($savefm)) $this->SetFetchMode($savefm); 00285 $ADODB_FETCH_MODE = $savem; 00286 00287 $arr2 = array(); 00288 for ($i=0; $i < sizeof($arr); $i++) { 00289 if ($arr[$i][3] == 'SYSTEM TABLE' ) continue; 00290 if ($arr[$i][2]) 00291 $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2]; 00292 } 00293 return $arr2; 00294 } 00295 00296 function &MetaColumns($table,$upper=true) 00297 { 00298 global $ADODB_FETCH_MODE; 00299 00300 $schema = false; 00301 $this->_findschema($table,$schema); 00302 if ($upper) $table = strtoupper($table); 00303 00304 $savem = $ADODB_FETCH_MODE; 00305 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00306 if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false); 00307 00308 $rs = $this->Execute( "||SQLColumns||$schema|$table" ); 00309 00310 if (isset($savefm)) $this->SetFetchMode($savefm); 00311 $ADODB_FETCH_MODE = $savem; 00312 00313 if (!$rs || $rs->EOF) { 00314 $false = false; 00315 return $false; 00316 } 00317 $retarr = array(); 00318 while (!$rs->EOF) { 00319 //print_r($rs->fields); 00320 if (strtoupper($rs->fields[2]) == $table) { 00321 $fld = new ADOFieldObject(); 00322 $fld->name = $rs->fields[3]; 00323 $fld->type = $rs->fields[5]; 00324 $fld->max_length = $rs->fields[6]; 00325 $fld->not_null = !empty($rs->fields[9]); 00326 $fld->scale = $rs->fields[7]; 00327 if (!is_null($rs->fields[12])) { 00328 $fld->has_default = true; 00329 $fld->default_value = $rs->fields[12]; 00330 } 00331 $retarr[strtoupper($fld->name)] = $fld; 00332 } else if (!empty($retarr)) 00333 break; 00334 $rs->MoveNext(); 00335 } 00336 $rs->Close(); 00337 00338 return $retarr; 00339 } 00340 00341 function &MetaPrimaryKeys($table, $owner='') 00342 { 00343 global $ADODB_FETCH_MODE; 00344 00345 $savem = $ADODB_FETCH_MODE; 00346 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00347 $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table"); 00348 $ADODB_FETCH_MODE = $savem; 00349 00350 //print_r($arr); 00351 $arr2 = array(); 00352 for ($i=0; $i < sizeof($arr); $i++) { 00353 if ($arr[$i][3]) $arr2[] = $arr[$i][3]; 00354 } 00355 return $arr2; 00356 } 00357 00358 function &MetaForeignKeys($table, $owner='', $upper=false) 00359 { 00360 global $ADODB_FETCH_MODE; 00361 00362 $savem = $ADODB_FETCH_MODE; 00363 $ADODB_FETCH_MODE = ADODB_FETCH_NUM; 00364 $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table"); 00365 $ADODB_FETCH_MODE = $savem; 00366 00367 $arr = false; 00368 foreach($constraints as $constr) { 00369 //print_r($constr); 00370 $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3]; 00371 } 00372 if (!$arr) { 00373 $false = false; 00374 return $false; 00375 } 00376 00377 $arr2 = array(); 00378 00379 foreach($arr as $k => $v) { 00380 foreach($v as $a => $b) { 00381 if ($upper) $a = strtoupper($a); 00382 $arr2[$a] = $b; 00383 } 00384 } 00385 return $arr2; 00386 } 00387 00388 function BeginTrans() 00389 { 00390 if (!$this->hasTransactions) return false; 00391 if ($this->transOff) return true; 00392 $this->transCnt += 1; 00393 $this->autoCommit = false; 00394 if (defined('ODB_TXN_DEFAULT')) 00395 $txn = ODB_TXN_DEFAULT; 00396 else 00397 $txn = ODB_TXN_READUNCOMMITTED; 00398 $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID); 00399 if(!$rs) return false; 00400 return true; 00401 } 00402 00403 function CommitTrans($ok=true) 00404 { 00405 if ($this->transOff) return true; 00406 if (!$ok) return $this->RollbackTrans(); 00407 if ($this->transCnt) $this->transCnt -= 1; 00408 $this->autoCommit = true; 00409 if( ($ret = @odbtp_commit($this->_connectionID)) ) 00410 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 00411 return $ret; 00412 } 00413 00414 function RollbackTrans() 00415 { 00416 if ($this->transOff) return true; 00417 if ($this->transCnt) $this->transCnt -= 1; 00418 $this->autoCommit = true; 00419 if( ($ret = @odbtp_rollback($this->_connectionID)) ) 00420 $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off 00421 return $ret; 00422 } 00423 00424 function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0) 00425 { 00426 // TOP requires ORDER BY for Visual FoxPro 00427 if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) { 00428 if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1'; 00429 } 00430 $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache); 00431 return $ret; 00432 } 00433 00434 function Prepare($sql) 00435 { 00436 if (! $this->_bindInputArray) return $sql; // no binding 00437 $stmt = @odbtp_prepare($sql,$this->_connectionID); 00438 if (!$stmt) { 00439 // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>"; 00440 return $sql; 00441 } 00442 return array($sql,$stmt,false); 00443 } 00444 00445 function PrepareSP($sql) 00446 { 00447 if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures 00448 00449 $stmt = @odbtp_prepare_proc($sql,$this->_connectionID); 00450 if (!$stmt) return false; 00451 return array($sql,$stmt); 00452 } 00453 00454 /* 00455 Usage: 00456 $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group 00457 00458 # note that the parameter does not have @ in front! 00459 $db->Parameter($stmt,$id,'myid'); 00460 $db->Parameter($stmt,$group,'group',false,64); 00461 $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY); 00462 $db->Execute($stmt); 00463 00464 @param $stmt Statement returned by Prepare() or PrepareSP(). 00465 @param $var PHP variable to bind to. Can set to null (for isNull support). 00466 @param $name Name of stored procedure variable name to bind to. 00467 @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp. 00468 @param [$maxLen] Holds an maximum length of the variable. 00469 @param [$type] The data type of $var. Legal values depend on driver. 00470 00471 See odbtp_attach_param documentation at http://odbtp.sourceforge.net. 00472 */ 00473 function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0) 00474 { 00475 if ( $this->odbc_driver == ODB_DRIVER_JET ) { 00476 $name = '['.$name.']'; 00477 if( !$type && $this->_useUnicodeSQL 00478 && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR ) 00479 { 00480 $type = ODB_WCHAR; 00481 } 00482 } 00483 else { 00484 $name = '@'.$name; 00485 } 00486 return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen); 00487 } 00488 00489 /* 00490 Insert a null into the blob field of the table first. 00491 Then use UpdateBlob to store the blob. 00492 00493 Usage: 00494 00495 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)'); 00496 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1'); 00497 */ 00498 00499 function UpdateBlob($table,$column,$val,$where,$blobtype='image') 00500 { 00501 $sql = "UPDATE $table SET $column = ? WHERE $where"; 00502 if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) ) 00503 return false; 00504 if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) ) 00505 return false; 00506 if( !@odbtp_set( $stmt, 1, $val ) ) 00507 return false; 00508 return @odbtp_execute( $stmt ) != false; 00509 } 00510 00511 function IfNull( $field, $ifNull ) 00512 { 00513 switch( $this->odbc_driver ) { 00514 case ODB_DRIVER_MSSQL: 00515 return " ISNULL($field, $ifNull) "; 00516 case ODB_DRIVER_JET: 00517 return " IIF(IsNull($field), $ifNull, $field) "; 00518 } 00519 return " CASE WHEN $field is null THEN $ifNull ELSE $field END "; 00520 } 00521 00522 function _query($sql,$inputarr=false) 00523 { 00524 global $php_errormsg; 00525 00526 if ($inputarr) { 00527 if (is_array($sql)) { 00528 $stmtid = $sql[1]; 00529 } else { 00530 $stmtid = @odbtp_prepare($sql,$this->_connectionID); 00531 if ($stmtid == false) { 00532 $this->_errorMsg = $php_errormsg; 00533 return false; 00534 } 00535 } 00536 $num_params = @odbtp_num_params( $stmtid ); 00537 for( $param = 1; $param <= $num_params; $param++ ) { 00538 @odbtp_input( $stmtid, $param ); 00539 @odbtp_set( $stmtid, $param, $inputarr[$param-1] ); 00540 } 00541 if (!@odbtp_execute($stmtid) ) { 00542 return false; 00543 } 00544 } else if (is_array($sql)) { 00545 $stmtid = $sql[1]; 00546 if (!@odbtp_execute($stmtid)) { 00547 return false; 00548 } 00549 } else { 00550 $stmtid = @odbtp_query($sql,$this->_connectionID); 00551 } 00552 $this->_lastAffectedRows = 0; 00553 if ($stmtid) { 00554 $this->_lastAffectedRows = @odbtp_affected_rows($stmtid); 00555 } 00556 return $stmtid; 00557 } 00558 00559 function _close() 00560 { 00561 $ret = @odbtp_close($this->_connectionID); 00562 $this->_connectionID = false; 00563 return $ret; 00564 } 00565 } 00566 00567 class ADORecordSet_odbtp extends ADORecordSet { 00568 00569 var $databaseType = 'odbtp'; 00570 var $canSeek = true; 00571 00572 function ADORecordSet_odbtp($queryID,$mode=false) 00573 { 00574 if ($mode === false) { 00575 global $ADODB_FETCH_MODE; 00576 $mode = $ADODB_FETCH_MODE; 00577 } 00578 $this->fetchMode = $mode; 00579 $this->ADORecordSet($queryID); 00580 } 00581 00582 function _initrs() 00583 { 00584 $this->_numOfFields = @odbtp_num_fields($this->_queryID); 00585 if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID))) 00586 $this->_numOfRows = -1; 00587 00588 if (!$this->connection->_useUnicodeSQL) return; 00589 00590 if ($this->connection->odbc_driver == ODB_DRIVER_JET) { 00591 if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR, 00592 $this->connection->_connectionID)) 00593 { 00594 for ($f = 0; $f < $this->_numOfFields; $f++) { 00595 if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR) 00596 @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR); 00597 } 00598 } 00599 } 00600 } 00601 00602 function &FetchField($fieldOffset = 0) 00603 { 00604 $off=$fieldOffset; // offsets begin at 0 00605 $o= new ADOFieldObject(); 00606 $o->name = @odbtp_field_name($this->_queryID,$off); 00607 $o->type = @odbtp_field_type($this->_queryID,$off); 00608 $o->max_length = @odbtp_field_length($this->_queryID,$off); 00609 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name); 00610 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name); 00611 return $o; 00612 } 00613 00614 function _seek($row) 00615 { 00616 return @odbtp_data_seek($this->_queryID, $row); 00617 } 00618 00619 function fields($colname) 00620 { 00621 if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname]; 00622 00623 if (!$this->bind) { 00624 $this->bind = array(); 00625 for ($i=0; $i < $this->_numOfFields; $i++) { 00626 $name = @odbtp_field_name( $this->_queryID, $i ); 00627 $this->bind[strtoupper($name)] = $i; 00628 } 00629 } 00630 return $this->fields[$this->bind[strtoupper($colname)]]; 00631 } 00632 00633 function _fetch_odbtp($type=0) 00634 { 00635 switch ($this->fetchMode) { 00636 case ADODB_FETCH_NUM: 00637 $this->fields = @odbtp_fetch_row($this->_queryID, $type); 00638 break; 00639 case ADODB_FETCH_ASSOC: 00640 $this->fields = @odbtp_fetch_assoc($this->_queryID, $type); 00641 break; 00642 default: 00643 $this->fields = @odbtp_fetch_array($this->_queryID, $type); 00644 } 00645 return is_array($this->fields); 00646 } 00647 00648 function _fetch() 00649 { 00650 return $this->_fetch_odbtp(); 00651 } 00652 00653 function MoveFirst() 00654 { 00655 if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false; 00656 $this->EOF = false; 00657 $this->_currentRow = 0; 00658 return true; 00659 } 00660 00661 function MoveLast() 00662 { 00663 if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false; 00664 $this->EOF = false; 00665 $this->_currentRow = $this->_numOfRows - 1; 00666 return true; 00667 } 00668 00669 function NextRecordSet() 00670 { 00671 if (!@odbtp_next_result($this->_queryID)) return false; 00672 $this->_inited = false; 00673 $this->bind = false; 00674 $this->_currentRow = -1; 00675 $this->Init(); 00676 return true; 00677 } 00678 00679 function _close() 00680 { 00681 return @odbtp_free_query($this->_queryID); 00682 } 00683 } 00684 00685 class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp { 00686 00687 var $databaseType = 'odbtp_mssql'; 00688 00689 function ADORecordSet_odbtp_mssql($id,$mode=false) 00690 { 00691 return $this->ADORecordSet_odbtp($id,$mode); 00692 } 00693 } 00694 00695 class ADORecordSet_odbtp_access extends ADORecordSet_odbtp { 00696 00697 var $databaseType = 'odbtp_access'; 00698 00699 function ADORecordSet_odbtp_access($id,$mode=false) 00700 { 00701 return $this->ADORecordSet_odbtp($id,$mode); 00702 } 00703 } 00704 00705 class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp { 00706 00707 var $databaseType = 'odbtp_vfp'; 00708 00709 function ADORecordSet_odbtp_vfp($id,$mode=false) 00710 { 00711 return $this->ADORecordSet_odbtp($id,$mode); 00712 } 00713 } 00714 00715 class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp { 00716 00717 var $databaseType = 'odbtp_oci8'; 00718 00719 function ADORecordSet_odbtp_oci8($id,$mode=false) 00720 { 00721 return $this->ADORecordSet_odbtp($id,$mode); 00722 } 00723 } 00724 00725 class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp { 00726 00727 var $databaseType = 'odbtp_sybase'; 00728 00729 function ADORecordSet_odbtp_sybase($id,$mode=false) 00730 { 00731 return $this->ADORecordSet_odbtp($id,$mode); 00732 } 00733 } 00734 ?>