PHPOpenChat PHP Cross Reference Customer Relationship Management

Source: /include/adodb/drivers/adodb-odbtp.inc.php - 727 lines - 21257 bytes - Summary - Text - Print

   1  <?php
   2  /*

   3    V4.61 24 Feb 2005  (c) 2000-2005 John Lim (jlim@natsoft.com.my). All rights reserved.

   4    Released under both BSD license and Lesser GPL library license.

   5    Whenever there is any discrepancy between the two licenses,

   6    the BSD license will take precedence. See License.txt.

   7    Set tabs to 4 for best viewing.

   8    Latest version is available at http://adodb.sourceforge.net

   9  */
  10  // Code contributed by "stefan bogdan" <sbogdan#rsb.ro>

  11  
  12  // security - hide paths

  13  if (!defined('ADODB_DIR')) die();
  14  
  15  define("_ADODB_ODBTP_LAYER", 2 );
  16  
  17  class ADODB_odbtp extends ADOConnection{
  18      var $databaseType = "odbtp";
  19      var $dataProvider = "odbtp";
  20      var $fmtDate = "'Y-m-d'";
  21      var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  22      var $replaceQuote = "''"; // string to use to replace quotes

  23      var $odbc_driver = 0;
  24      var $hasAffectedRows = true;
  25      var $hasInsertID = false;
  26      var $hasGenID = true;
  27      var $hasMoveFirst = true;
  28  
  29      var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)";
  30      var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'";
  31      var $_bindInputArray = false;
  32      var $_useUnicodeSQL = false;
  33      var $_canPrepareSP = false;
  34      var $_dontPoolDBC = true;
  35  
  36  	function ADODB_odbtp()
  37      {
  38      }
  39  
  40  	function ServerInfo()
  41      {
  42          return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID),
  43                       'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID));
  44      }
  45  
  46  	function ErrorMsg()
  47      {
  48          if (empty($this->_connectionID)) return @odbtp_last_error();
  49          return @odbtp_last_error($this->_connectionID);
  50      }
  51  
  52  	function ErrorNo()
  53      {
  54          if (empty($this->_connectionID)) return @odbtp_last_error_state();
  55              return @odbtp_last_error_state($this->_connectionID);
  56      }
  57  
  58  	function _insertid()
  59      {
  60      // SCOPE_IDENTITY()

  61      // Returns the last IDENTITY value inserted into an IDENTITY column in

  62      // the same scope. A scope is a module -- a stored procedure, trigger,

  63      // function, or batch. Thus, two statements are in the same scope if

  64      // they are in the same stored procedure, function, or batch.

  65              return $this->GetOne($this->identitySQL);
  66      }
  67  
  68  	function _affectedrows()
  69      {
  70          if ($this->_queryID) {
  71              return @odbtp_affected_rows ($this->_queryID);
  72         } else
  73          return 0;
  74      }
  75  
  76  	function CreateSequence($seqname='adodbseq',$start=1)
  77      {
  78          //verify existence

  79          $num = $this->GetOne("select seq_value from adodb_seq");
  80          $seqtab='adodb_seq';
  81          if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
  82              $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID );
  83              //if using vfp dbc file

  84              if( !strcasecmp(strrchr($path, '.'), '.dbc') )
  85                  $path = substr($path,0,strrpos($path,'\/'));
  86                 $seqtab = $path . '/' . $seqtab;
  87          }
  88          if($num == false) {
  89              if (empty($this->_genSeqSQL)) return false;
  90              $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab));
  91          }
  92          $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'");
  93          if ($num) {
  94              return false;
  95          }
  96          $start -= 1;
  97          return $this->Execute("insert into adodb_seq values('$seqname',$start)");
  98      }
  99  
 100  	function DropSequence($seqname)
 101      {
 102          if (empty($this->_dropSeqSQL)) return false;
 103          return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
 104      }
 105  
 106  	function GenID($seq='adodbseq',$start=1)
 107      {
 108          $seqtab='adodb_seq';
 109          if( $this->odbc_driver == ODB_DRIVER_FOXPRO) {
 110              $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID );
 111              //if using vfp dbc file

 112              if( !strcasecmp(strrchr($path, '.'), '.dbc') )
 113                  $path = substr($path,0,strrpos($path,'\/'));
 114                 $seqtab = $path . '/' . $seqtab;
 115          }
 116          $MAXLOOPS = 100;
 117          while (--$MAXLOOPS>=0) {
 118              $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'");
 119              if ($num === false) {
 120                  //verify if abodb_seq table exist

 121                  $ok = $this->GetOne("select seq_value from adodb_seq ");
 122                  if(!$ok) {
 123                      //creating the sequence table adodb_seq

 124                      $this->Execute(sprintf($this->_genSeqSQL ,$seqtab));
 125                  }
 126                  $start -= 1;
 127                  $num = '0';
 128                  $ok = $this->Execute("insert into adodb_seq values('$seq',$start)");
 129                  if (!$ok) return false;
 130              }
 131              $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'");
 132              if($ok) {
 133                  $num += 1;
 134                  $this->genID = $num;
 135                  return $num;
 136              }
 137          }
 138      if ($fn = $this->raiseErrorFn) {
 139          $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
 140      }
 141          return false;
 142      }
 143  
 144      //example for $UserOrDSN

 145      //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO;

 146      //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO;

 147      //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=;

 148      //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest;

 149      //if uid & pwd can be separate

 150      function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
 151      {
 152          $this->_connectionID = @odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase);
 153          if ($this->_connectionID === false) {
 154              $this->_errorMsg = $this->ErrorMsg() ;
 155              return false;
 156          }
 157          if ($this->_dontPoolDBC) {
 158              if (function_exists('odbtp_dont_pool_dbc'))
 159                  @odbtp_dont_pool_dbc($this->_connectionID);
 160          }
 161          else {
 162              $this->_dontPoolDBC = true;
 163          }
 164          $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID);
 165          $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID));
 166          $this->odbc_name = $dbms;
 167          
 168          // Account for inconsistent DBMS names

 169          if( $this->odbc_driver == ODB_DRIVER_ORACLE )
 170              $dbms = 'oracle';
 171          else if( $this->odbc_driver == ODB_DRIVER_SYBASE )
 172              $dbms = 'sybase';
 173  
 174          // Set DBMS specific attributes

 175          switch( $dbms ) {
 176              case 'microsoft sql server':
 177                  $this->databaseType = 'odbtp_mssql';
 178                  $this->fmtDate = "'Y-m-d'";
 179                  $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
 180                  $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
 181                  $this->sysTimeStamp = 'GetDate()';
 182                  $this->ansiOuter = true;
 183                  $this->leftOuter = '*=';
 184                  $this->rightOuter = '=*';
 185                  $this->hasTop = 'top';
 186                  $this->hasInsertID = true;
 187                  $this->hasTransactions = true;
 188                  $this->_bindInputArray = true;
 189                  $this->_canSelectDb = true;
 190                  $this->substr = "substring";
 191                  $this->length = 'len';
 192                  $this->identitySQL = 'select @@IDENTITY';
 193                  $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'";
 194                  $this->_canPrepareSP = true;
 195                  break;
 196              case 'access':
 197                  $this->databaseType = 'odbtp_access';
 198                  $this->fmtDate = "#Y-m-d#";
 199                  $this->fmtTimeStamp = "#Y-m-d h:i:sA#";
 200                  $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
 201                  $this->sysTimeStamp = 'NOW';
 202                  $this->hasTop = 'top';
 203                  $this->hasTransactions = false;
 204                  $this->_canPrepareSP = true;  // For MS Access only.

 205                  break;
 206              case 'visual foxpro':
 207                  $this->databaseType = 'odbtp_vfp';
 208                  $this->fmtDate = "{^Y-m-d}";
 209                  $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}";
 210                  $this->sysDate = 'date()';
 211                  $this->sysTimeStamp = 'datetime()';
 212                  $this->ansiOuter = true;
 213                  $this->hasTop = 'top';
 214                  $this->hasTransactions = false;
 215                  $this->replaceQuote = "'+chr(39)+'";
 216                  $this->true = '.T.';
 217                  $this->false = '.F.';
 218                  break;
 219              case 'oracle':
 220                  $this->databaseType = 'odbtp_oci8';
 221                  $this->fmtDate = "'Y-m-d 00:00:00'";
 222                  $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
 223                  $this->sysDate = 'TRUNC(SYSDATE)';
 224                  $this->sysTimeStamp = 'SYSDATE';
 225                  $this->hasTransactions = true;
 226                  $this->_bindInputArray = true;
 227                  $this->concat_operator = '||';
 228                  break;
 229              case 'sybase':
 230                  $this->databaseType = 'odbtp_sybase';
 231                  $this->fmtDate = "'Y-m-d'";
 232                  $this->fmtTimeStamp = "'Y-m-d H:i:s'";
 233                  $this->sysDate = 'GetDate()';
 234                  $this->sysTimeStamp = 'GetDate()';
 235                  $this->leftOuter = '*=';
 236                  $this->rightOuter = '=*';
 237                  $this->hasInsertID = true;
 238                  $this->hasTransactions = true;
 239                  $this->identitySQL = 'select @@IDENTITY';
 240                  break;
 241              default:
 242                  $this->databaseType = 'odbtp';
 243                  if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) )
 244                      $this->hasTransactions = true;
 245                  else
 246                      $this->hasTransactions = false;
 247          }
 248          @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID );
 249  
 250          if ($this->_useUnicodeSQL )
 251              @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID);
 252  
 253          return true;
 254      }
 255  
 256  	function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
 257      {
 258          $this->_dontPoolDBC = false;
 259            return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase);
 260      }
 261  
 262  	function SelectDB($dbName)
 263      {
 264          if (!@odbtp_select_db($dbName, $this->_connectionID)) {
 265              return false;
 266          }
 267          $this->databaseName = $dbName;
 268          return true;
 269      }
 270      
 271      function &MetaTables($ttype='',$showSchema=false,$mask=false)
 272      {
 273      global $ADODB_FETCH_MODE;
 274  
 275          $savem = $ADODB_FETCH_MODE;
 276          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 277          if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
 278          
 279          $arr =& $this->GetArray("||SQLTables||||$ttype");
 280          
 281          if (isset($savefm)) $this->SetFetchMode($savefm);
 282          $ADODB_FETCH_MODE = $savem;
 283  
 284          $arr2 = array();
 285          for ($i=0; $i < sizeof($arr); $i++) {
 286              if ($arr[$i][3] == 'SYSTEM TABLE' )    continue;
 287              if ($arr[$i][2])
 288                  $arr2[] = $showSchema ? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];
 289          }
 290          return $arr2;
 291      }
 292      
 293      function &MetaColumns($table,$upper=true)
 294      {
 295      global $ADODB_FETCH_MODE;
 296  
 297          $schema = false;
 298          $this->_findschema($table,$schema);
 299          if ($upper) $table = strtoupper($table);
 300  
 301          $savem = $ADODB_FETCH_MODE;
 302          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 303          if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
 304          
 305          $rs = $this->Execute( "||SQLColumns||$schema|$table" );
 306          
 307          if (isset($savefm)) $this->SetFetchMode($savefm);
 308          $ADODB_FETCH_MODE = $savem;
 309  
 310          if (!$rs || $rs->EOF) {
 311              $false = false;
 312              return $false;
 313          }
 314          while (!$rs->EOF) {
 315              //print_r($rs->fields);

 316              if (strtoupper($rs->fields[2]) == $table) {
 317                  $fld = new ADOFieldObject();
 318                  $fld->name = $rs->fields[3];
 319                  $fld->type = $rs->fields[5];
 320                  $fld->max_length = $rs->fields[6];
 321                  $fld->not_null = !empty($rs->fields[9]);
 322                   $fld->scale = $rs->fields[7];
 323                   if (!is_null($rs->fields[12])) {
 324                       $fld->has_default = true;
 325                       $fld->default_value = $rs->fields[12];
 326                  }
 327                  $retarr[strtoupper($fld->name)] = $fld;
 328              } else if (sizeof($retarr)>0)
 329                  break;
 330              $rs->MoveNext();
 331          }
 332          $rs->Close();
 333  
 334          return $retarr;
 335      }
 336  
 337      function &MetaPrimaryKeys($table, $owner='')
 338      {
 339      global $ADODB_FETCH_MODE;
 340  
 341          $savem = $ADODB_FETCH_MODE;
 342          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 343          $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table");
 344          $ADODB_FETCH_MODE = $savem;
 345  
 346          //print_r($arr);

 347          $arr2 = array();
 348          for ($i=0; $i < sizeof($arr); $i++) {
 349              if ($arr[$i][3]) $arr2[] = $arr[$i][3];
 350          }
 351          return $arr2;
 352      }
 353  
 354      function &MetaForeignKeys($table, $owner='', $upper=false)
 355      {
 356      global $ADODB_FETCH_MODE;
 357  
 358          $savem = $ADODB_FETCH_MODE;
 359          $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
 360          $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table");
 361          $ADODB_FETCH_MODE = $savem;
 362  
 363          $arr = false;
 364          foreach($constraints as $constr) {
 365              //print_r($constr);

 366              $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3];
 367          }
 368          if (!$arr) {
 369              $false = false;
 370              return $false;
 371          }
 372          
 373          $arr2 = array();
 374  
 375          foreach($arr as $k => $v) {
 376              foreach($v as $a => $b) {
 377                  if ($upper) $a = strtoupper($a);
 378                  $arr2[$a] = $b;
 379              }
 380          }
 381          return $arr2;
 382      }
 383  
 384  	function BeginTrans()
 385      {
 386          if (!$this->hasTransactions) return false;
 387          if ($this->transOff) return true;
 388          $this->transCnt += 1;
 389          $this->autoCommit = false;
 390          if (defined('ODB_TXN_DEFAULT'))
 391              $txn = ODB_TXN_DEFAULT;
 392          else
 393              $txn = ODB_TXN_READUNCOMMITTED;
 394          $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID);
 395          if(!$rs) return false;
 396          return true;
 397      }
 398  
 399  	function CommitTrans($ok=true)
 400      {
 401          if ($this->transOff) return true;
 402          if (!$ok) return $this->RollbackTrans();
 403          if ($this->transCnt) $this->transCnt -= 1;
 404          $this->autoCommit = true;
 405          if( ($ret = @odbtp_commit($this->_connectionID)) )
 406              $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off

 407          return $ret;
 408      }
 409  
 410  	function RollbackTrans()
 411      {
 412          if ($this->transOff) return true;
 413          if ($this->transCnt) $this->transCnt -= 1;
 414          $this->autoCommit = true;
 415          if( ($ret = @odbtp_rollback($this->_connectionID)) )
 416              $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off

 417          return $ret;
 418      }
 419  
 420      function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
 421      {
 422          // TOP requires ORDER BY for Visual FoxPro

 423          if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
 424              if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1';
 425          }
 426          return ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
 427      }
 428  
 429  	function Prepare($sql)
 430      {
 431          if (! $this->_bindInputArray) return $sql; // no binding

 432          $stmt = @odbtp_prepare($sql,$this->_connectionID);
 433          if (!$stmt) {
 434          //    print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>";

 435              return $sql;
 436          }
 437          return array($sql,$stmt,false);
 438      }
 439  
 440  	function PrepareSP($sql)
 441      {
 442          if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures

 443  
 444          $stmt = @odbtp_prepare_proc($sql,$this->_connectionID);
 445          if (!$stmt) return false;
 446          return array($sql,$stmt);
 447      }
 448  
 449      /*

 450      Usage:

 451          $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group

 452  

 453          # note that the parameter does not have @ in front!

 454          $db->Parameter($stmt,$id,'myid');

 455          $db->Parameter($stmt,$group,'group',false,64);

 456          $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY);

 457          $db->Execute($stmt);

 458  

 459          @param $stmt Statement returned by Prepare() or PrepareSP().

 460          @param $var PHP variable to bind to. Can set to null (for isNull support).

 461          @param $name Name of stored procedure variable name to bind to.

 462          @param [$isOutput] Indicates direction of parameter 0/false=IN  1=OUT  2= IN/OUT. This is ignored in odbtp.

 463          @param [$maxLen] Holds an maximum length of the variable.

 464          @param [$type] The data type of $var. Legal values depend on driver.

 465  

 466          See odbtp_attach_param documentation at http://odbtp.sourceforge.net.

 467      */
 468  	function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0)
 469      {
 470          if ( $this->odbc_driver == ODB_DRIVER_JET ) {
 471              $name = '['.$name.']';
 472              if( !$type && $this->_useUnicodeSQL
 473                  && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR )
 474              {
 475                  $type = ODB_WCHAR;
 476              }
 477          }
 478          else {
 479              $name = '@'.$name;
 480          }
 481          return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen);
 482      }
 483  
 484      /*

 485          Insert a null into the blob field of the table first.

 486          Then use UpdateBlob to store the blob.

 487  

 488          Usage:

 489  

 490          $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');

 491          $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');

 492      */
 493  
 494  	function UpdateBlob($table,$column,$val,$where,$blobtype='image')
 495      {
 496          $sql = "UPDATE $table SET $column = ? WHERE $where";
 497          if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) )
 498              return false;
 499          if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) )
 500              return false;
 501          if( !@odbtp_set( $stmt, 1, $val ) )
 502              return false;
 503          return @odbtp_execute( $stmt ) != false;
 504      }
 505  
 506  	function IfNull( $field, $ifNull )
 507      {
 508          switch( $this->odbc_driver ) {
 509              case ODB_DRIVER_MSSQL:
 510                  return " ISNULL($field, $ifNull) ";
 511              case ODB_DRIVER_JET:
 512                  return " IIF(IsNull($field), $ifNull, $field) ";
 513          }
 514          return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
 515      }
 516  
 517  	function _query($sql,$inputarr=false)
 518      {
 519           if ($inputarr) {
 520              if (is_array($sql)) {
 521                  $stmtid = $sql[1];
 522              } else {
 523                  $stmtid = @odbtp_prepare($sql,$this->_connectionID);
 524                  if ($stmtid == false) {
 525                      $this->_errorMsg = $php_errormsg;
 526                      return false;
 527                  }
 528              }
 529              $num_params = @odbtp_num_params( $stmtid );
 530              for( $param = 1; $param <= $num_params; $param++ ) {
 531                  @odbtp_input( $stmtid, $param );
 532                  @odbtp_set( $stmtid, $param, $inputarr[$param-1] );
 533              }
 534              if (!@odbtp_execute($stmtid) ) {
 535                  return false;
 536              }
 537          } else if (is_array($sql)) {
 538              $stmtid = $sql[1];
 539              if (!@odbtp_execute($stmtid)) {
 540                  return false;
 541              }
 542          } else {
 543              $stmtid = @odbtp_query($sql,$this->_connectionID);
 544             }
 545          $this->_lastAffectedRows = 0;
 546          if ($stmtid) {
 547                  $this->_lastAffectedRows = @odbtp_affected_rows($stmtid);
 548          }
 549          return $stmtid;
 550      }
 551  
 552  	function _close()
 553      {
 554          $ret = @odbtp_close($this->_connectionID);
 555          $this->_connectionID = false;
 556          return $ret;
 557      }
 558  }
 559  
 560  class ADORecordSet_odbtp extends ADORecordSet {
 561  
 562      var $databaseType = 'odbtp';
 563      var $canSeek = true;
 564  
 565  	function ADORecordSet_odbtp($queryID,$mode=false)
 566      {
 567          if ($mode === false) {
 568              global $ADODB_FETCH_MODE;
 569              $mode = $ADODB_FETCH_MODE;
 570          }
 571          $this->fetchMode = $mode;
 572          $this->ADORecordSet($queryID);
 573      }
 574  
 575  	function _initrs()
 576      {
 577          $this->_numOfFields = @odbtp_num_fields($this->_queryID);
 578          if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID)))
 579              $this->_numOfRows = -1;
 580  
 581          if (!$this->connection->_useUnicodeSQL) return;
 582  
 583          if ($this->connection->odbc_driver == ODB_DRIVER_JET) {
 584              if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR,
 585                                   $this->connection->_connectionID))
 586              {
 587                  for ($f = 0; $f < $this->_numOfFields; $f++) {
 588                      if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR)
 589                          @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR);
 590                  }
 591              }
 592          }
 593      }
 594  
 595      function &FetchField($fieldOffset = 0)
 596      {
 597          $off=$fieldOffset; // offsets begin at 0

 598          $o= new ADOFieldObject();
 599          $o->name = @odbtp_field_name($this->_queryID,$off);
 600          $o->type = @odbtp_field_type($this->_queryID,$off);
 601          $o->max_length = @odbtp_field_length($this->_queryID,$off);
 602          if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
 603          else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
 604          return $o;
 605      }
 606  
 607  	function _seek($row)
 608      {
 609          return @odbtp_data_seek($this->_queryID, $row);
 610      }
 611  
 612  	function fields($colname)
 613      {
 614          if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
 615  
 616          if (!$this->bind) {
 617              $this->bind = array();
 618              for ($i=0; $i < $this->_numOfFields; $i++) {
 619                  $name = @odbtp_field_name( $this->_queryID, $i );
 620                  $this->bind[strtoupper($name)] = $i;
 621              }
 622          }
 623          return $this->fields[$this->bind[strtoupper($colname)]];
 624      }
 625  
 626  	function _fetch_odbtp($type=0)
 627      {
 628          switch ($this->fetchMode) {
 629              case ADODB_FETCH_NUM:
 630                  $this->fields = @odbtp_fetch_row($this->_queryID, $type);
 631                  break;
 632              case ADODB_FETCH_ASSOC:
 633                  $this->fields = @odbtp_fetch_assoc($this->_queryID, $type);
 634                  break;
 635              default:
 636                  $this->fields = @odbtp_fetch_array($this->_queryID, $type);
 637          }
 638          return is_array($this->fields);
 639      }
 640  
 641  	function _fetch()
 642      {
 643          return $this->_fetch_odbtp();
 644      }
 645  
 646  	function MoveFirst()
 647      {
 648          if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false;
 649          $this->EOF = false;
 650          $this->_currentRow = 0;
 651          return true;
 652      }
 653  
 654  	function MoveLast()
 655      {
 656          if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false;
 657          $this->EOF = false;
 658          $this->_currentRow = $this->_numOfRows - 1;
 659          return true;
 660      }
 661  
 662  	function NextRecordSet()
 663      {
 664          if (!@odbtp_next_result($this->_queryID)) return false;
 665          $this->_inited = false;
 666          $this->bind = false;
 667          $this->_currentRow = -1;
 668          $this->Init();
 669          return true;
 670      }
 671  
 672  	function _close()
 673      {
 674          return @odbtp_free_query($this->_queryID);
 675      }
 676  }
 677  
 678  class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp {
 679  
 680      var $databaseType = 'odbtp_mssql';
 681  
 682  	function ADORecordSet_odbtp_mssql($id,$mode=false)
 683      {
 684          return $this->ADORecordSet_odbtp($id,$mode);
 685      }
 686  }
 687  
 688  class ADORecordSet_odbtp_access extends ADORecordSet_odbtp {
 689  
 690      var $databaseType = 'odbtp_access';
 691  
 692  	function ADORecordSet_odbtp_access($id,$mode=false)
 693      {
 694          return $this->ADORecordSet_odbtp($id,$mode);
 695      }
 696  }
 697  
 698  class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp {
 699  
 700      var $databaseType = 'odbtp_vfp';
 701  
 702  	function ADORecordSet_odbtp_vfp($id,$mode=false)
 703      {
 704          return $this->ADORecordSet_odbtp($id,$mode);
 705      }
 706  }
 707  
 708  class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp {
 709  
 710      var $databaseType = 'odbtp_oci8';
 711  
 712  	function ADORecordSet_odbtp_oci8($id,$mode=false)
 713      {
 714          return $this->ADORecordSet_odbtp($id,$mode);
 715      }
 716  }
 717  
 718  class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp {
 719  
 720      var $databaseType = 'odbtp_sybase';
 721  
 722  	function ADORecordSet_odbtp_sybase($id,$mode=false)
 723      {
 724          return $this->ADORecordSet_odbtp($id,$mode);
 725      }
 726  }
 727  ?>

title

Description

title

Description

title

Description

title

title

Body