PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/adodb.493a/drivers/adodb-odbtp.inc.php

https://github.com/infused/retrospect-gds
PHP | 734 lines | 587 code | 86 blank | 61 comment | 116 complexity | d82aacd2c74abe5e20daac226b93c742 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*
  3. V4.93 10 Oct 2006 (c) 2000-2006 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. odbtp_convert_datetime($this->_connectionID,true);
  140. if ($this->_connectionID === false) {
  141. $this->_errorMsg = $this->ErrorMsg() ;
  142. return false;
  143. }
  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 @@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 @@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][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 (!is_null($rs->fields[12])) {
  296. $fld->has_default = true;
  297. $fld->default_value = $rs->fields[12];
  298. }
  299. $retarr[strtoupper($fld->name)] = $fld;
  300. } else if (!empty($retarr))
  301. break;
  302. $rs->MoveNext();
  303. }
  304. $rs->Close();
  305. return $retarr;
  306. }
  307. function &MetaPrimaryKeys($table, $owner='')
  308. {
  309. global $ADODB_FETCH_MODE;
  310. $savem = $ADODB_FETCH_MODE;
  311. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  312. $arr =& $this->GetArray("||SQLPrimaryKeys||$owner|$table");
  313. $ADODB_FETCH_MODE = $savem;
  314. //print_r($arr);
  315. $arr2 = array();
  316. for ($i=0; $i < sizeof($arr); $i++) {
  317. if ($arr[$i][3]) $arr2[] = $arr[$i][3];
  318. }
  319. return $arr2;
  320. }
  321. function &MetaForeignKeys($table, $owner='', $upper=false)
  322. {
  323. global $ADODB_FETCH_MODE;
  324. $savem = $ADODB_FETCH_MODE;
  325. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  326. $constraints =& $this->GetArray("||SQLForeignKeys|||||$owner|$table");
  327. $ADODB_FETCH_MODE = $savem;
  328. $arr = false;
  329. foreach($constraints as $constr) {
  330. //print_r($constr);
  331. $arr[$constr[11]][$constr[2]][] = $constr[7].'='.$constr[3];
  332. }
  333. if (!$arr) {
  334. $false = false;
  335. return $false;
  336. }
  337. $arr2 = array();
  338. foreach($arr as $k => $v) {
  339. foreach($v as $a => $b) {
  340. if ($upper) $a = strtoupper($a);
  341. $arr2[$a] = $b;
  342. }
  343. }
  344. return $arr2;
  345. }
  346. function BeginTrans()
  347. {
  348. if (!$this->hasTransactions) return false;
  349. if ($this->transOff) return true;
  350. $this->transCnt += 1;
  351. $this->autoCommit = false;
  352. if (defined('ODB_TXN_DEFAULT'))
  353. $txn = ODB_TXN_DEFAULT;
  354. else
  355. $txn = ODB_TXN_READUNCOMMITTED;
  356. $rs = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS,$txn,$this->_connectionID);
  357. if(!$rs) return false;
  358. return true;
  359. }
  360. function CommitTrans($ok=true)
  361. {
  362. if ($this->transOff) return true;
  363. if (!$ok) return $this->RollbackTrans();
  364. if ($this->transCnt) $this->transCnt -= 1;
  365. $this->autoCommit = true;
  366. if( ($ret = @odbtp_commit($this->_connectionID)) )
  367. $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
  368. return $ret;
  369. }
  370. function RollbackTrans()
  371. {
  372. if ($this->transOff) return true;
  373. if ($this->transCnt) $this->transCnt -= 1;
  374. $this->autoCommit = true;
  375. if( ($ret = @odbtp_rollback($this->_connectionID)) )
  376. $ret = @odbtp_set_attr(ODB_ATTR_TRANSACTIONS, ODB_TXN_NONE, $this->_connectionID);//set transaction off
  377. return $ret;
  378. }
  379. function &SelectLimit($sql,$nrows=-1,$offset=-1, $inputarr=false,$secs2cache=0)
  380. {
  381. // TOP requires ORDER BY for Visual FoxPro
  382. if( $this->odbc_driver == ODB_DRIVER_FOXPRO ) {
  383. if (!preg_match('/ORDER[ \t\r\n]+BY/is',$sql)) $sql .= ' ORDER BY 1';
  384. }
  385. $ret =& ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
  386. return $ret;
  387. }
  388. function Prepare($sql)
  389. {
  390. if (! $this->_bindInputArray) return $sql; // no binding
  391. $stmt = @odbtp_prepare($sql,$this->_connectionID);
  392. if (!$stmt) {
  393. // print "Prepare Error for ($sql) ".$this->ErrorMsg()."<br>";
  394. return $sql;
  395. }
  396. return array($sql,$stmt,false);
  397. }
  398. function PrepareSP($sql)
  399. {
  400. if (!$this->_canPrepareSP) return $sql; // Can't prepare procedures
  401. $stmt = @odbtp_prepare_proc($sql,$this->_connectionID);
  402. if (!$stmt) return false;
  403. return array($sql,$stmt);
  404. }
  405. /*
  406. Usage:
  407. $stmt = $db->PrepareSP('SP_RUNSOMETHING'); -- takes 2 params, @myid and @group
  408. # note that the parameter does not have @ in front!
  409. $db->Parameter($stmt,$id,'myid');
  410. $db->Parameter($stmt,$group,'group',false,64);
  411. $db->Parameter($stmt,$group,'photo',false,100000,ODB_BINARY);
  412. $db->Execute($stmt);
  413. @param $stmt Statement returned by Prepare() or PrepareSP().
  414. @param $var PHP variable to bind to. Can set to null (for isNull support).
  415. @param $name Name of stored procedure variable name to bind to.
  416. @param [$isOutput] Indicates direction of parameter 0/false=IN 1=OUT 2= IN/OUT. This is ignored in odbtp.
  417. @param [$maxLen] Holds an maximum length of the variable.
  418. @param [$type] The data type of $var. Legal values depend on driver.
  419. See odbtp_attach_param documentation at http://odbtp.sourceforge.net.
  420. */
  421. function Parameter(&$stmt, &$var, $name, $isOutput=false, $maxLen=0, $type=0)
  422. {
  423. if ( $this->odbc_driver == ODB_DRIVER_JET ) {
  424. $name = '['.$name.']';
  425. if( !$type && $this->_useUnicodeSQL
  426. && @odbtp_param_bindtype($stmt[1], $name) == ODB_CHAR )
  427. {
  428. $type = ODB_WCHAR;
  429. }
  430. }
  431. else {
  432. $name = '@'.$name;
  433. }
  434. return @odbtp_attach_param($stmt[1], $name, $var, $type, $maxLen);
  435. }
  436. /*
  437. Insert a null into the blob field of the table first.
  438. Then use UpdateBlob to store the blob.
  439. Usage:
  440. $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
  441. $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
  442. */
  443. function UpdateBlob($table,$column,$val,$where,$blobtype='image')
  444. {
  445. $sql = "UPDATE $table SET $column = ? WHERE $where";
  446. if( !($stmt = @odbtp_prepare($sql, $this->_connectionID)) )
  447. return false;
  448. if( !@odbtp_input( $stmt, 1, ODB_BINARY, 1000000, $blobtype ) )
  449. return false;
  450. if( !@odbtp_set( $stmt, 1, $val ) )
  451. return false;
  452. return @odbtp_execute( $stmt ) != false;
  453. }
  454. function IfNull( $field, $ifNull )
  455. {
  456. switch( $this->odbc_driver ) {
  457. case ODB_DRIVER_MSSQL:
  458. return " ISNULL($field, $ifNull) ";
  459. case ODB_DRIVER_JET:
  460. return " IIF(IsNull($field), $ifNull, $field) ";
  461. }
  462. return " CASE WHEN $field is null THEN $ifNull ELSE $field END ";
  463. }
  464. function _query($sql,$inputarr=false)
  465. {
  466. global $php_errormsg;
  467. if ($inputarr) {
  468. if (is_array($sql)) {
  469. $stmtid = $sql[1];
  470. } else {
  471. $stmtid = @odbtp_prepare($sql,$this->_connectionID);
  472. if ($stmtid == false) {
  473. $this->_errorMsg = $php_errormsg;
  474. return false;
  475. }
  476. }
  477. $num_params = @odbtp_num_params( $stmtid );
  478. for( $param = 1; $param <= $num_params; $param++ ) {
  479. @odbtp_input( $stmtid, $param );
  480. @odbtp_set( $stmtid, $param, $inputarr[$param-1] );
  481. }
  482. if (!@odbtp_execute($stmtid) ) {
  483. return false;
  484. }
  485. } else if (is_array($sql)) {
  486. $stmtid = $sql[1];
  487. if (!@odbtp_execute($stmtid)) {
  488. return false;
  489. }
  490. } else {
  491. $stmtid = @odbtp_query($sql,$this->_connectionID);
  492. }
  493. $this->_lastAffectedRows = 0;
  494. if ($stmtid) {
  495. $this->_lastAffectedRows = @odbtp_affected_rows($stmtid);
  496. }
  497. return $stmtid;
  498. }
  499. function _close()
  500. {
  501. $ret = @odbtp_close($this->_connectionID);
  502. $this->_connectionID = false;
  503. return $ret;
  504. }
  505. }
  506. class ADORecordSet_odbtp extends ADORecordSet {
  507. var $databaseType = 'odbtp';
  508. var $canSeek = true;
  509. function ADORecordSet_odbtp($queryID,$mode=false)
  510. {
  511. if ($mode === false) {
  512. global $ADODB_FETCH_MODE;
  513. $mode = $ADODB_FETCH_MODE;
  514. }
  515. $this->fetchMode = $mode;
  516. $this->ADORecordSet($queryID);
  517. }
  518. function _initrs()
  519. {
  520. $this->_numOfFields = @odbtp_num_fields($this->_queryID);
  521. if (!($this->_numOfRows = @odbtp_num_rows($this->_queryID)))
  522. $this->_numOfRows = -1;
  523. if (!$this->connection->_useUnicodeSQL) return;
  524. if ($this->connection->odbc_driver == ODB_DRIVER_JET) {
  525. if (!@odbtp_get_attr(ODB_ATTR_MAPCHARTOWCHAR,
  526. $this->connection->_connectionID))
  527. {
  528. for ($f = 0; $f < $this->_numOfFields; $f++) {
  529. if (@odbtp_field_bindtype($this->_queryID, $f) == ODB_CHAR)
  530. @odbtp_bind_field($this->_queryID, $f, ODB_WCHAR);
  531. }
  532. }
  533. }
  534. }
  535. function &FetchField($fieldOffset = 0)
  536. {
  537. $off=$fieldOffset; // offsets begin at 0
  538. $o= new ADOFieldObject();
  539. $o->name = @odbtp_field_name($this->_queryID,$off);
  540. $o->type = @odbtp_field_type($this->_queryID,$off);
  541. $o->max_length = @odbtp_field_length($this->_queryID,$off);
  542. if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
  543. else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
  544. return $o;
  545. }
  546. function _seek($row)
  547. {
  548. return @odbtp_data_seek($this->_queryID, $row);
  549. }
  550. function fields($colname)
  551. {
  552. if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
  553. if (!$this->bind) {
  554. $this->bind = array();
  555. for ($i=0; $i < $this->_numOfFields; $i++) {
  556. $name = @odbtp_field_name( $this->_queryID, $i );
  557. $this->bind[strtoupper($name)] = $i;
  558. }
  559. }
  560. return $this->fields[$this->bind[strtoupper($colname)]];
  561. }
  562. function _fetch_odbtp($type=0)
  563. {
  564. switch ($this->fetchMode) {
  565. case ADODB_FETCH_NUM:
  566. $this->fields = @odbtp_fetch_row($this->_queryID, $type);
  567. break;
  568. case ADODB_FETCH_ASSOC:
  569. $this->fields = @odbtp_fetch_assoc($this->_queryID, $type);
  570. break;
  571. default:
  572. $this->fields = @odbtp_fetch_array($this->_queryID, $type);
  573. }
  574. return is_array($this->fields);
  575. }
  576. function _fetch()
  577. {
  578. return $this->_fetch_odbtp();
  579. }
  580. function MoveFirst()
  581. {
  582. if (!$this->_fetch_odbtp(ODB_FETCH_FIRST)) return false;
  583. $this->EOF = false;
  584. $this->_currentRow = 0;
  585. return true;
  586. }
  587. function MoveLast()
  588. {
  589. if (!$this->_fetch_odbtp(ODB_FETCH_LAST)) return false;
  590. $this->EOF = false;
  591. $this->_currentRow = $this->_numOfRows - 1;
  592. return true;
  593. }
  594. function NextRecordSet()
  595. {
  596. if (!@odbtp_next_result($this->_queryID)) return false;
  597. $this->_inited = false;
  598. $this->bind = false;
  599. $this->_currentRow = -1;
  600. $this->Init();
  601. return true;
  602. }
  603. function _close()
  604. {
  605. return @odbtp_free_query($this->_queryID);
  606. }
  607. }
  608. class ADORecordSet_odbtp_mssql extends ADORecordSet_odbtp {
  609. var $databaseType = 'odbtp_mssql';
  610. function ADORecordSet_odbtp_mssql($id,$mode=false)
  611. {
  612. return $this->ADORecordSet_odbtp($id,$mode);
  613. }
  614. }
  615. class ADORecordSet_odbtp_access extends ADORecordSet_odbtp {
  616. var $databaseType = 'odbtp_access';
  617. function ADORecordSet_odbtp_access($id,$mode=false)
  618. {
  619. return $this->ADORecordSet_odbtp($id,$mode);
  620. }
  621. }
  622. class ADORecordSet_odbtp_vfp extends ADORecordSet_odbtp {
  623. var $databaseType = 'odbtp_vfp';
  624. function ADORecordSet_odbtp_vfp($id,$mode=false)
  625. {
  626. return $this->ADORecordSet_odbtp($id,$mode);
  627. }
  628. }
  629. class ADORecordSet_odbtp_oci8 extends ADORecordSet_odbtp {
  630. var $databaseType = 'odbtp_oci8';
  631. function ADORecordSet_odbtp_oci8($id,$mode=false)
  632. {
  633. return $this->ADORecordSet_odbtp($id,$mode);
  634. }
  635. }
  636. class ADORecordSet_odbtp_sybase extends ADORecordSet_odbtp {
  637. var $databaseType = 'odbtp_sybase';
  638. function ADORecordSet_odbtp_sybase($id,$mode=false)
  639. {
  640. return $this->ADORecordSet_odbtp($id,$mode);
  641. }
  642. }
  643. ?>