PageRenderTime 93ms CodeModel.GetById 29ms RepoModel.GetById 2ms app.codeStats 0ms

/moodle1917/lib/adodb/drivers/adodb-odbtp.inc.php

https://github.com/gustavoramirezrugerio/moodle1.9.17
PHP | 743 lines | 594 code | 88 blank | 61 comment | 122 complexity | a2eb1485f203b1cba57f352eea89e787 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-2.0, GPL-2.0
  1. <?php
  2. /*
  3. V4.98 13 Feb 2008 (c) 2000-2008 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. // security - hide paths
  12. if (!defined('ADODB_DIR')) die();
  13. define("_ADODB_ODBTP_LAYER", 2 );
  14. class ADODB_odbtp extends ADOConnection{
  15. var $databaseType = "odbtp";
  16. var $dataProvider = "odbtp";
  17. var $fmtDate = "'Y-m-d'";
  18. var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  19. var $replaceQuote = "''"; // string to use to replace quotes
  20. var $odbc_driver = 0;
  21. var $hasAffectedRows = true;
  22. var $hasInsertID = false;
  23. var $hasGenID = true;
  24. var $hasMoveFirst = true;
  25. var $_genSeqSQL = "create table %s (seq_name char(30) not null unique , seq_value integer not null)";
  26. var $_dropSeqSQL = "delete from adodb_seq where seq_name = '%s'";
  27. var $_bindInputArray = false;
  28. var $_useUnicodeSQL = false;
  29. var $_canPrepareSP = false;
  30. var $_dontPoolDBC = true;
  31. function ADODB_odbtp()
  32. {
  33. }
  34. function ServerInfo()
  35. {
  36. return array('description' => @odbtp_get_attr( ODB_ATTR_DBMSNAME, $this->_connectionID),
  37. 'version' => @odbtp_get_attr( ODB_ATTR_DBMSVER, $this->_connectionID));
  38. }
  39. function ErrorMsg()
  40. {
  41. if (empty($this->_connectionID)) return @odbtp_last_error();
  42. return @odbtp_last_error($this->_connectionID);
  43. }
  44. function ErrorNo()
  45. {
  46. if (empty($this->_connectionID)) return @odbtp_last_error_state();
  47. return @odbtp_last_error_state($this->_connectionID);
  48. }
  49. function _insertid()
  50. {
  51. // SCOPE_IDENTITY()
  52. // Returns the last IDENTITY value inserted into an IDENTITY column in
  53. // the same scope. A scope is a module -- a stored procedure, trigger,
  54. // function, or batch. Thus, two statements are in the same scope if
  55. // they are in the same stored procedure, function, or batch.
  56. return $this->GetOne($this->identitySQL);
  57. }
  58. function _affectedrows()
  59. {
  60. if ($this->_queryID) {
  61. return @odbtp_affected_rows ($this->_queryID);
  62. } else
  63. return 0;
  64. }
  65. function CreateSequence($seqname='adodbseq',$start=1)
  66. {
  67. //verify existence
  68. $num = $this->GetOne("select seq_value from adodb_seq");
  69. $seqtab='adodb_seq';
  70. if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
  71. $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID );
  72. //if using vfp dbc file
  73. if( !strcasecmp(strrchr($path, '.'), '.dbc') )
  74. $path = substr($path,0,strrpos($path,'\/'));
  75. $seqtab = $path . '/' . $seqtab;
  76. }
  77. if($num == false) {
  78. if (empty($this->_genSeqSQL)) return false;
  79. $ok = $this->Execute(sprintf($this->_genSeqSQL ,$seqtab));
  80. }
  81. $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seqname'");
  82. if ($num) {
  83. return false;
  84. }
  85. $start -= 1;
  86. return $this->Execute("insert into adodb_seq values('$seqname',$start)");
  87. }
  88. function DropSequence($seqname)
  89. {
  90. if (empty($this->_dropSeqSQL)) return false;
  91. return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
  92. }
  93. function GenID($seq='adodbseq',$start=1)
  94. {
  95. $seqtab='adodb_seq';
  96. if( $this->odbc_driver == ODB_DRIVER_FOXPRO) {
  97. $path = @odbtp_get_attr( ODB_ATTR_DATABASENAME, $this->_connectionID );
  98. //if using vfp dbc file
  99. if( !strcasecmp(strrchr($path, '.'), '.dbc') )
  100. $path = substr($path,0,strrpos($path,'\/'));
  101. $seqtab = $path . '/' . $seqtab;
  102. }
  103. $MAXLOOPS = 100;
  104. while (--$MAXLOOPS>=0) {
  105. $num = $this->GetOne("select seq_value from adodb_seq where seq_name='$seq'");
  106. if ($num === false) {
  107. //verify if abodb_seq table exist
  108. $ok = $this->GetOne("select seq_value from adodb_seq ");
  109. if(!$ok) {
  110. //creating the sequence table adodb_seq
  111. $this->Execute(sprintf($this->_genSeqSQL ,$seqtab));
  112. }
  113. $start -= 1;
  114. $num = '0';
  115. $ok = $this->Execute("insert into adodb_seq values('$seq',$start)");
  116. if (!$ok) return false;
  117. }
  118. $ok = $this->Execute("update adodb_seq set seq_value=seq_value+1 where seq_name='$seq'");
  119. if($ok) {
  120. $num += 1;
  121. $this->genID = $num;
  122. return $num;
  123. }
  124. }
  125. if ($fn = $this->raiseErrorFn) {
  126. $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
  127. }
  128. return false;
  129. }
  130. //example for $UserOrDSN
  131. //for visual fox : DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBF;SOURCEDB=c:\YourDbfFileDir;EXCLUSIVE=NO;
  132. //for visual fox dbc: DRIVER={Microsoft Visual FoxPro Driver};SOURCETYPE=DBC;SOURCEDB=c:\YourDbcFileDir\mydb.dbc;EXCLUSIVE=NO;
  133. //for access : DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\path_to_access_db\base_test.mdb;UID=root;PWD=;
  134. //for mssql : DRIVER={SQL Server};SERVER=myserver;UID=myuid;PWD=mypwd;DATABASE=OdbtpTest;
  135. //if uid & pwd can be separate
  136. function _connect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
  137. {
  138. $this->_connectionID = odbtp_connect($HostOrInterface,$UserOrDSN,$argPassword,$argDatabase);
  139. if ($this->_connectionID === false) {
  140. $this->_errorMsg = $this->ErrorMsg() ;
  141. return false;
  142. }
  143. odbtp_convert_datetime($this->_connectionID,true);
  144. if ($this->_dontPoolDBC) {
  145. if (function_exists('odbtp_dont_pool_dbc'))
  146. @odbtp_dont_pool_dbc($this->_connectionID);
  147. }
  148. else {
  149. $this->_dontPoolDBC = true;
  150. }
  151. $this->odbc_driver = @odbtp_get_attr(ODB_ATTR_DRIVER, $this->_connectionID);
  152. $dbms = strtolower(@odbtp_get_attr(ODB_ATTR_DBMSNAME, $this->_connectionID));
  153. $this->odbc_name = $dbms;
  154. // Account for inconsistent DBMS names
  155. if( $this->odbc_driver == ODB_DRIVER_ORACLE )
  156. $dbms = 'oracle';
  157. else if( $this->odbc_driver == ODB_DRIVER_SYBASE )
  158. $dbms = 'sybase';
  159. // Set DBMS specific attributes
  160. switch( $dbms ) {
  161. case 'microsoft sql server':
  162. $this->databaseType = 'odbtp_mssql';
  163. $this->fmtDate = "'Y-m-d'";
  164. $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
  165. $this->sysDate = 'convert(datetime,convert(char,GetDate(),102),102)';
  166. $this->sysTimeStamp = 'GetDate()';
  167. $this->ansiOuter = true;
  168. $this->leftOuter = '*=';
  169. $this->rightOuter = '=*';
  170. $this->hasTop = 'top';
  171. $this->hasInsertID = true;
  172. $this->hasTransactions = true;
  173. $this->_bindInputArray = true;
  174. $this->_canSelectDb = true;
  175. $this->substr = "substring";
  176. $this->length = 'len';
  177. $this->identitySQL = 'select SCOPE_IDENTITY()';
  178. $this->metaDatabasesSQL = "select name from master..sysdatabases where name <> 'master'";
  179. $this->_canPrepareSP = true;
  180. break;
  181. case 'access':
  182. $this->databaseType = 'odbtp_access';
  183. $this->fmtDate = "#Y-m-d#";
  184. $this->fmtTimeStamp = "#Y-m-d h:i:sA#";
  185. $this->sysDate = "FORMAT(NOW,'yyyy-mm-dd')";
  186. $this->sysTimeStamp = 'NOW';
  187. $this->hasTop = 'top';
  188. $this->hasTransactions = false;
  189. $this->_canPrepareSP = true; // For MS Access only.
  190. break;
  191. case 'visual foxpro':
  192. $this->databaseType = 'odbtp_vfp';
  193. $this->fmtDate = "{^Y-m-d}";
  194. $this->fmtTimeStamp = "{^Y-m-d, h:i:sA}";
  195. $this->sysDate = 'date()';
  196. $this->sysTimeStamp = 'datetime()';
  197. $this->ansiOuter = true;
  198. $this->hasTop = 'top';
  199. $this->hasTransactions = false;
  200. $this->replaceQuote = "'+chr(39)+'";
  201. $this->true = '.T.';
  202. $this->false = '.F.';
  203. break;
  204. case 'oracle':
  205. $this->databaseType = 'odbtp_oci8';
  206. $this->fmtDate = "'Y-m-d 00:00:00'";
  207. $this->fmtTimeStamp = "'Y-m-d h:i:sA'";
  208. $this->sysDate = 'TRUNC(SYSDATE)';
  209. $this->sysTimeStamp = 'SYSDATE';
  210. $this->hasTransactions = true;
  211. $this->_bindInputArray = true;
  212. $this->concat_operator = '||';
  213. break;
  214. case 'sybase':
  215. $this->databaseType = 'odbtp_sybase';
  216. $this->fmtDate = "'Y-m-d'";
  217. $this->fmtTimeStamp = "'Y-m-d H:i:s'";
  218. $this->sysDate = 'GetDate()';
  219. $this->sysTimeStamp = 'GetDate()';
  220. $this->leftOuter = '*=';
  221. $this->rightOuter = '=*';
  222. $this->hasInsertID = true;
  223. $this->hasTransactions = true;
  224. $this->identitySQL = 'select SCOPE_IDENTITY()';
  225. break;
  226. default:
  227. $this->databaseType = 'odbtp';
  228. if( @odbtp_get_attr(ODB_ATTR_TXNCAPABLE, $this->_connectionID) )
  229. $this->hasTransactions = true;
  230. else
  231. $this->hasTransactions = false;
  232. }
  233. @odbtp_set_attr(ODB_ATTR_FULLCOLINFO, TRUE, $this->_connectionID );
  234. if ($this->_useUnicodeSQL )
  235. @odbtp_set_attr(ODB_ATTR_UNICODESQL, TRUE, $this->_connectionID);
  236. return true;
  237. }
  238. function _pconnect($HostOrInterface, $UserOrDSN='', $argPassword='', $argDatabase='')
  239. {
  240. $this->_dontPoolDBC = false;
  241. return $this->_connect($HostOrInterface, $UserOrDSN, $argPassword, $argDatabase);
  242. }
  243. function SelectDB($dbName)
  244. {
  245. if (!@odbtp_select_db($dbName, $this->_connectionID)) {
  246. return false;
  247. }
  248. $this->database = $dbName;
  249. $this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
  250. return true;
  251. }
  252. function &MetaTables($ttype='',$showSchema=false,$mask=false)
  253. {
  254. global $ADODB_FETCH_MODE;
  255. $savem = $ADODB_FETCH_MODE;
  256. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  257. if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
  258. $arr =& $this->GetArray("||SQLTables||||$ttype");
  259. if (isset($savefm)) $this->SetFetchMode($savefm);
  260. $ADODB_FETCH_MODE = $savem;
  261. $arr2 = array();
  262. for ($i=0; $i < sizeof($arr); $i++) {
  263. if ($arr[$i][3] == 'SYSTEM TABLE' ) continue;
  264. if ($arr[$i][2])
  265. $arr2[] = $showSchema && $arr[$i][1]? $arr[$i][1].'.'.$arr[$i][2] : $arr[$i][2];
  266. }
  267. return $arr2;
  268. }
  269. function &MetaColumns($table,$upper=true)
  270. {
  271. global $ADODB_FETCH_MODE;
  272. $schema = false;
  273. $this->_findschema($table,$schema);
  274. if ($upper) $table = strtoupper($table);
  275. $savem = $ADODB_FETCH_MODE;
  276. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  277. if ($this->fetchMode !== false) $savefm = $this->SetFetchMode(false);
  278. $rs = $this->Execute( "||SQLColumns||$schema|$table" );
  279. if (isset($savefm)) $this->SetFetchMode($savefm);
  280. $ADODB_FETCH_MODE = $savem;
  281. if (!$rs || $rs->EOF) {
  282. $false = false;
  283. return $false;
  284. }
  285. $retarr = array();
  286. while (!$rs->EOF) {
  287. //print_r($rs->fields);
  288. if (strtoupper($rs->fields[2]) == $table) {
  289. $fld = new ADOFieldObject();
  290. $fld->name = $rs->fields[3];
  291. $fld->type = $rs->fields[5];
  292. $fld->max_length = $rs->fields[6];
  293. $fld->not_null = !empty($rs->fields[9]);
  294. $fld->scale = $rs->fields[7];
  295. if (isset($rs->fields[12])) // vfp does not have field 12
  296. if (!is_null($rs->fields[12])) {
  297. $fld->has_default = true;
  298. $fld->default_value = $rs->fields[12];
  299. }
  300. $retarr[strtoupper($fld->name)] = $fld;
  301. } else if (!empty($retarr))
  302. break;
  303. $rs->MoveNext();
  304. }
  305. $rs->Close();
  306. return $retarr;
  307. }
  308. function &MetaPrimaryKeys($table, $owner='')
  309. {
  310. global $ADODB_FETCH_MODE;
  311. $savem = $ADODB_FETCH_MODE;
  312. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  313. $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table");
  314. $ADODB_FETCH_MODE = $savem;
  315. //print_r($arr);
  316. $arr2 = array();
  317. for ($i=0; $i < sizeof($arr); $i++) {
  318. if ($arr[$i][3]) $arr2[] = $arr[$i][3];
  319. }
  320. return $arr2;
  321. }
  322. function &MetaForeignKeys($table, $owner='', $upper=false)
  323. {
  324. global $ADODB_FETCH_MODE;
  325. $savem = $ADODB_FETCH_MODE;
  326. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  327. $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table");
  328. $ADODB_FETCH_MODE = $savem;
  329. $arr = false;
  330. foreach($constraints as $constr) {
  331. //print_r($constr);
  332. $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3];
  333. }
  334. if (!$arr) {
  335. $false = false;
  336. return $false;
  337. }
  338. $arr2 = array();
  339. foreach($arr as $k => $v) {
  340. foreach($v as $a => $b) {
  341. if ($upper) $a = strtoupper($a);
  342. $arr2[$a] = $b;
  343. }
  344. }
  345. return $arr2;
  346. }
  347. function BeginTrans()
  348. {
  349. if (!$this->hasTransactions) return false;
  350. if ($this->transOff) return true;
  351. $this->transCnt += 1;
  352. $this->autoCommit = false;
  353. if (defined('ODB_TXN_DEFAULT'))
  354. $txn = ODB_TXN_DEFAULT;
  355. else
  356. $txn = ODB_TXN_READUNCOMMITTED;
  357. $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID);
  358. if(!$rs) return false;
  359. return true;
  360. }
  361. function CommitTrans($ok=true)
  362. {
  363. if ($this->transOff) return true;
  364. if (!$ok) return $this->RollbackTrans();
  365. if ($this->transCnt) $this->transCnt -= 1;
  366. $this->autoCommit = true;
  367. if( ($ret = @odbtp_commit($this->_connectionID)) )
  368. $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
  369. return $ret;
  370. }
  371. function RollbackTrans()
  372. {
  373. if ($this->transOff) return true;
  374. if ($this->transCnt) $this->transCnt -= 1;
  375. $this->autoCommit = true;
  376. if( ($ret = @odbtp_rollback($this->_connectionID)) )
  377. $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
  378. return $ret;
  379. }
  380. function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
  381. {
  382. // TOP requires ORDER BY for Visual FoxPro
  383. if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
  384. if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1';
  385. }
  386. $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
  387. return $ret;
  388. }
  389. function Prepare($sql)
  390. {
  391. if (! $this->_bindInputArray) return $sql; // no binding
  392. $stmt = @odbtp_prepare($sql,$this->_connectionID);
  393. if (!$stmt) {
  394. // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>";
  395. return $sql;
  396. }
  397. return array($sql,$stmt,false);
  398. }
  399. function PrepareSP($sql)
  400. {
  401. if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures
  402. $stmt = @odbtp_prepare_proc($sql,$this->_connectionID);
  403. if (!$stmt) return false;
  404. return array($sql,$stmt);
  405. }
  406. /*
  407. Usage:
  408. $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group
  409. # note that the parameter does not have @ in front!
  410. $db->Parameter($stmt,$id,'myid');
  411. $db->Parameter($stmt,$group,'group',false,64);
  412. $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY);
  413. $db->Execute($stmt);
  414. @param $stmt Statement returned by Prepare() or PrepareSP().
  415. @param $var PHP variable to bind to. Can set to null (for isNull support).
  416. @param $name Name of stored procedure variable name to bind to.
  417. @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp.
  418. @param [$maxLen] Holds an maximum length of the variable.
  419. @param [$type] The data type of $var. Legal values depend on driver.
  420. See odbtp_attach_param documentation at http://odbtp.sourceforge.net.
  421. */
  422. function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0)
  423. {
  424. if ( $this->odbc_driver == ODB_DRIVER_JET ) {
  425. $name = '['.$name.']';
  426. if( !$type && $this->_useUnicodeSQL
  427. && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR )
  428. {
  429. $type = ODB_WCHAR;
  430. }
  431. }
  432. else {
  433. $name = '@'.$name;
  434. }
  435. return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen);
  436. }
  437. /*
  438. Insert a null into the blob field of the table first.
  439. Then use UpdateBlob to store the blob.
  440. Usage:
  441. $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
  442. $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
  443. */
  444. function UpdateBlob($table,$column,$val,$where,$blobtype='image')
  445. {
  446. $sql = "UPDATE $table SET $column = ? WHERE $where";
  447. if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) )
  448. return false;
  449. if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) )
  450. return false;
  451. if( !@odbtp_set( $stmt, 1, $val ) )
  452. return false;
  453. return @odbtp_execute( $stmt ) != false;
  454. }
  455. function IfNull( $field, $ifNull )
  456. {
  457. switch( $this->odbc_driver ) {
  458. case ODB_DRIVER_MSSQL:
  459. return " ISNULL($field, $ifNull) ";
  460. case ODB_DRIVER_JET:
  461. return " IIF(IsNull($field), $ifNull, $field) ";
  462. }
  463. return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
  464. }
  465. function _query($sql,$inputarr=false)
  466. {
  467. global $php_errormsg;
  468. if ($inputarr) {
  469. if (is_array($sql)) {
  470. $stmtid = $sql[1];
  471. } else {
  472. $stmtid = @odbtp_prepare($sql,$this->_connectionID);
  473. if ($stmtid == false) {
  474. $this->_errorMsg = $php_errormsg;
  475. return false;
  476. }
  477. }
  478. $num_params = @odbtp_num_params( $stmtid );
  479. for( $param = 1; $param <= $num_params; $param++ ) {
  480. @odbtp_input( $stmtid, $param );
  481. @odbtp_set( $stmtid, $param, $inputarr[$param-1] );
  482. }
  483. if (!@odbtp_execute($stmtid) ) {
  484. return false;
  485. }
  486. } else if (is_array($sql)) {
  487. $stmtid = $sql[1];
  488. if (!@odbtp_execute($stmtid)) {
  489. return false;
  490. }
  491. } else {
  492. $stmtid = odbtp_query($sql,$this->_connectionID);
  493. }
  494. $this->_lastAffectedRows = 0;
  495. if ($stmtid) {
  496. $this->_lastAffectedRows = @odbtp_affected_rows($stmtid);
  497. }
  498. return $stmtid;
  499. }
  500. function _close()
  501. {
  502. $ret = @odbtp_close($this->_connectionID);
  503. $this->_connectionID = false;
  504. return $ret;
  505. }
  506. }
  507. class ADORecordSet_odbtp extends ADORecordSet {
  508. var $databaseType = 'odbtp';
  509. var $canSeek = true;
  510. function ADORecordSet_odbtp($queryID,$mode=false)
  511. {
  512. if ($mode === false) {
  513. global $ADODB_FETCH_MODE;
  514. $mode = $ADODB_FETCH_MODE;
  515. }
  516. $this->fetchMode = $mode;
  517. $this->ADORecordSet($queryID);
  518. }
  519. function _initrs()
  520. {
  521. $this->_numOfFields = @odbtp_num_fields($this->_queryID);
  522. if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID)))
  523. $this->_numOfRows = -1;
  524. if (!$this->connection->_useUnicodeSQL) return;
  525. if ($this->connection->odbc_driver == ODB_DRIVER_JET) {
  526. if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR,
  527. $this->connection->_connectionID))
  528. {
  529. for ($f = 0; $f < $this->_numOfFields; $f++) {
  530. if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR)
  531. @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR);
  532. }
  533. }
  534. }
  535. }
  536. function &FetchField($fieldOffset = 0)
  537. {
  538. $off=$fieldOffset; // offsets begin at 0
  539. $o= new ADOFieldObject();
  540. $o->name = @odbtp_field_name($this->_queryID,$off);
  541. $o->type = @odbtp_field_type($this->_queryID,$off);
  542. $o->max_length = @odbtp_field_length($this->_queryID,$off);
  543. if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
  544. else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
  545. return $o;
  546. }
  547. function _seek($row)
  548. {
  549. return @odbtp_data_seek($this->_queryID, $row);
  550. }
  551. function fields($colname)
  552. {
  553. if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
  554. if (!$this->bind) {
  555. $this->bind = array();
  556. for ($i=0; $i < $this->_numOfFields; $i++) {
  557. $name = @odbtp_field_name( $this->_queryID, $i );
  558. $this->bind[strtoupper($name)] = $i;
  559. }
  560. }
  561. return $this->fields[$this->bind[strtoupper($colname)]];
  562. }
  563. function _fetch_odbtp($type=0)
  564. {
  565. switch ($this->fetchMode) {
  566. case ADODB_FETCH_NUM:
  567. $this->fields = @odbtp_fetch_row($this->_queryID, $type);
  568. break;
  569. case ADODB_FETCH_ASSOC:
  570. $this->fields = @odbtp_fetch_assoc($this->_queryID, $type);
  571. break;
  572. default:
  573. $this->fields = @odbtp_fetch_array($this->_queryID, $type);
  574. }
  575. if ($this->databaseType = 'odbtp_vfp') {
  576. if ($this->fields)
  577. foreach($this->fields as $k => $v) {
  578. if (strncmp($v,'1899-12-30',10) == 0) $this->fields[$k] = '';
  579. }
  580. }
  581. return is_array($this->fields);
  582. }
  583. function _fetch()
  584. {
  585. return $this->_fetch_odbtp();
  586. }
  587. function MoveFirst()
  588. {
  589. if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false;
  590. $this->EOF = false;
  591. $this->_currentRow = 0;
  592. return true;
  593. }
  594. function MoveLast()
  595. {
  596. if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false;
  597. $this->EOF = false;
  598. $this->_currentRow = $this->_numOfRows - 1;
  599. return true;
  600. }
  601. function NextRecordSet()
  602. {
  603. if (!@odbtp_next_result($this->_queryID)) return false;
  604. $this->_inited = false;
  605. $this->bind = false;
  606. $this->_currentRow = -1;
  607. $this->Init();
  608. return true;
  609. }
  610. function _close()
  611. {
  612. return @odbtp_free_query($this->_queryID);
  613. }
  614. }
  615. class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp {
  616. var $databaseType = 'odbtp_mssql';
  617. function ADORecordSet_odbtp_mssql($id,$mode=false)
  618. {
  619. return $this->ADORecordSet_odbtp($id,$mode);
  620. }
  621. }
  622. class ADORecordSet_odbtp_access extends ADORecordSet_odbtp {
  623. var $databaseType = 'odbtp_access';
  624. function ADORecordSet_odbtp_access($id,$mode=false)
  625. {
  626. return $this->ADORecordSet_odbtp($id,$mode);
  627. }
  628. }
  629. class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp {
  630. var $databaseType = 'odbtp_vfp';
  631. function ADORecordSet_odbtp_vfp($id,$mode=false)
  632. {
  633. return $this->ADORecordSet_odbtp($id,$mode);
  634. }
  635. }
  636. class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp {
  637. var $databaseType = 'odbtp_oci8';
  638. function ADORecordSet_odbtp_oci8($id,$mode=false)
  639. {
  640. return $this->ADORecordSet_odbtp($id,$mode);
  641. }
  642. }
  643. class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp {
  644. var $databaseType = 'odbtp_sybase';
  645. function ADORecordSet_odbtp_sybase($id,$mode=false)
  646. {
  647. return $this->ADORecordSet_odbtp($id,$mode);
  648. }
  649. }
  650. ?>