/src/typo3_src-4.2.0alpha1/typo3/sysext/adodb/adodb/drivers/adodb-odbtp.inc.php

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

This documentation has been generated automatically from TYPO3 source code using Doxygen and is provided as is by Cast Iron Coding as a courtesy to other TYPO3 developers and users. Please consider Cast Iron Coding — a full-service web development agency in Portland, Oregon specializing in TYPO3 extension development — for all of your TYPO3 development and consulting needs!