PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/adodb/drivers/adodb-pdo.inc.php

https://bitbucket.org/moodle/moodle
PHP | 900 lines | 696 code | 83 blank | 121 comment | 68 complexity | d1efd7dd978cbc392a054f46359e7934 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. /**
  3. @version v5.21.0 2021-02-27
  4. @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
  5. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community
  6. Released under both BSD license and Lesser GPL library license.
  7. Whenever there is any discrepancy between the two licenses,
  8. the BSD license will take precedence.
  9. Set tabs to 4 for best viewing.
  10. Latest version is available at https://adodb.org/
  11. Requires ODBC. Works on Windows and Unix.
  12. Problems:
  13. Where is float/decimal type in pdo_param_type
  14. LOB handling for CLOB/BLOB differs significantly
  15. */
  16. // security - hide paths
  17. if (!defined('ADODB_DIR')) die();
  18. /*
  19. enum pdo_param_type {
  20. PDO::PARAM_NULL, 0
  21. /* int as in long (the php native int type).
  22. * If you mark a column as an int, PDO expects get_col to return
  23. * a pointer to a long
  24. PDO::PARAM_INT, 1
  25. /* get_col ptr should point to start of the string buffer
  26. PDO::PARAM_STR, 2
  27. /* get_col: when len is 0 ptr should point to a php_stream *,
  28. * otherwise it should behave like a string. Indicate a NULL field
  29. * value by setting the ptr to NULL
  30. PDO::PARAM_LOB, 3
  31. /* get_col: will expect the ptr to point to a new PDOStatement object handle,
  32. * but this isn't wired up yet
  33. PDO::PARAM_STMT, 4 /* hierarchical result set
  34. /* get_col ptr should point to a zend_bool
  35. PDO::PARAM_BOOL, 5
  36. /* magic flag to denote a parameter as being input/output
  37. PDO::PARAM_INPUT_OUTPUT = 0x80000000
  38. };
  39. */
  40. function adodb_pdo_type($t)
  41. {
  42. switch($t) {
  43. case 2: return 'VARCHAR';
  44. case 3: return 'BLOB';
  45. default: return 'NUMERIC';
  46. }
  47. }
  48. /*----------------------------------------------------------------------------*/
  49. class ADODB_pdo extends ADOConnection {
  50. var $databaseType = "pdo";
  51. var $dataProvider = "pdo";
  52. var $fmtDate = "'Y-m-d'";
  53. var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  54. var $replaceQuote = "''"; // string to use to replace quotes
  55. var $hasAffectedRows = true;
  56. var $_bindInputArray = true;
  57. var $_genIDSQL;
  58. var $_genSeqSQL = "create table %s (id integer)";
  59. var $_dropSeqSQL;
  60. var $_autocommit = true;
  61. var $_lastAffectedRows = 0;
  62. var $_errormsg = false;
  63. var $_errorno = false;
  64. var $dsnType = '';
  65. var $stmt = false;
  66. var $_driver;
  67. /*
  68. * Describe parameters passed directly to the PDO driver
  69. *
  70. * @example $db->pdoOptions = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION];
  71. */
  72. public $pdoParameters = array();
  73. function _UpdatePDO()
  74. {
  75. $d = $this->_driver;
  76. $this->fmtDate = $d->fmtDate;
  77. $this->fmtTimeStamp = $d->fmtTimeStamp;
  78. $this->replaceQuote = $d->replaceQuote;
  79. $this->sysDate = $d->sysDate;
  80. $this->sysTimeStamp = $d->sysTimeStamp;
  81. $this->random = $d->random;
  82. $this->concat_operator = $d->concat_operator;
  83. $this->nameQuote = $d->nameQuote;
  84. $this->arrayClass = $d->arrayClass;
  85. $this->hasGenID = $d->hasGenID;
  86. $this->_genIDSQL = $d->_genIDSQL;
  87. $this->_genSeqSQL = $d->_genSeqSQL;
  88. $this->_dropSeqSQL = $d->_dropSeqSQL;
  89. $d->_init($this);
  90. }
  91. function Time()
  92. {
  93. if (!empty($this->_driver->_hasdual)) {
  94. $sql = "select $this->sysTimeStamp from dual";
  95. }
  96. else {
  97. $sql = "select $this->sysTimeStamp";
  98. }
  99. $rs = $this->_Execute($sql);
  100. if ($rs && !$rs->EOF) {
  101. return $this->UnixTimeStamp(reset($rs->fields));
  102. }
  103. return false;
  104. }
  105. // returns true or false
  106. function _connect($argDSN, $argUsername, $argPassword, $argDatabasename, $persist=false)
  107. {
  108. $at = strpos($argDSN,':');
  109. $this->dsnType = substr($argDSN,0,$at);
  110. if ($argDatabasename) {
  111. switch($this->dsnType){
  112. case 'sqlsrv':
  113. $argDSN .= ';database='.$argDatabasename;
  114. break;
  115. case 'mssql':
  116. case 'mysql':
  117. case 'oci':
  118. case 'pgsql':
  119. case 'sqlite':
  120. case 'firebird':
  121. default:
  122. $argDSN .= ';dbname='.$argDatabasename;
  123. }
  124. }
  125. /*
  126. * Configure for persistent connection if required,
  127. * by adding the the pdo parameter into any provided
  128. * ones
  129. */
  130. if ($persist) {
  131. $this->pdoParameters[\PDO::ATTR_PERSISTENT] = true;
  132. }
  133. try {
  134. $this->_connectionID = new \PDO($argDSN, $argUsername, $argPassword, $this->pdoParameters);
  135. } catch (Exception $e) {
  136. $this->_connectionID = false;
  137. $this->_errorno = -1;
  138. //var_dump($e);
  139. $this->_errormsg = 'Connection attempt failed: '.$e->getMessage();
  140. return false;
  141. }
  142. if ($this->_connectionID) {
  143. switch(ADODB_ASSOC_CASE){
  144. case ADODB_ASSOC_CASE_LOWER:
  145. $m = PDO::CASE_LOWER;
  146. break;
  147. case ADODB_ASSOC_CASE_UPPER:
  148. $m = PDO::CASE_UPPER;
  149. break;
  150. default:
  151. case ADODB_ASSOC_CASE_NATIVE:
  152. $m = PDO::CASE_NATURAL;
  153. break;
  154. }
  155. //$this->_connectionID->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_SILENT );
  156. $this->_connectionID->setAttribute(PDO::ATTR_CASE,$m);
  157. // Now merge in any provided attributes for PDO
  158. foreach ($this->connectionParameters as $options) {
  159. foreach($options as $k=>$v) {
  160. if ($this->debug) {
  161. ADOconnection::outp('Setting attribute: ' . $k . ' to ' . $v);
  162. }
  163. $this->_connectionID->setAttribute($k,$v);
  164. }
  165. }
  166. $class = 'ADODB_pdo_'.$this->dsnType;
  167. //$this->_connectionID->setAttribute(PDO::ATTR_AUTOCOMMIT,true);
  168. switch($this->dsnType) {
  169. case 'mssql':
  170. case 'mysql':
  171. case 'oci':
  172. case 'pgsql':
  173. case 'sqlite':
  174. case 'sqlsrv':
  175. case 'firebird':
  176. case 'dblib':
  177. include_once(ADODB_DIR.'/drivers/adodb-pdo_'.$this->dsnType.'.inc.php');
  178. break;
  179. }
  180. if (class_exists($class)) {
  181. $this->_driver = new $class();
  182. }
  183. else {
  184. $this->_driver = new ADODB_pdo_base();
  185. }
  186. $this->_driver->_connectionID = $this->_connectionID;
  187. $this->_UpdatePDO();
  188. $this->_driver->database = $this->database;
  189. return true;
  190. }
  191. $this->_driver = new ADODB_pdo_base();
  192. return false;
  193. }
  194. function Concat()
  195. {
  196. $args = func_get_args();
  197. if(method_exists($this->_driver, 'Concat')) {
  198. return call_user_func_array(array($this->_driver, 'Concat'), $args);
  199. }
  200. return call_user_func_array('parent::Concat', $args);
  201. }
  202. // returns true or false
  203. function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
  204. {
  205. return $this->_connect($argDSN, $argUsername, $argPassword, $argDatabasename, true);
  206. }
  207. /*------------------------------------------------------------------------------*/
  208. function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
  209. {
  210. $save = $this->_driver->fetchMode;
  211. $this->_driver->fetchMode = $this->fetchMode;
  212. $this->_driver->debug = $this->debug;
  213. $ret = $this->_driver->SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
  214. $this->_driver->fetchMode = $save;
  215. return $ret;
  216. }
  217. function ServerInfo()
  218. {
  219. return $this->_driver->ServerInfo();
  220. }
  221. function MetaTables($ttype=false,$showSchema=false,$mask=false)
  222. {
  223. return $this->_driver->MetaTables($ttype,$showSchema,$mask);
  224. }
  225. function MetaColumns($table,$normalize=true)
  226. {
  227. return $this->_driver->MetaColumns($table,$normalize);
  228. }
  229. public function metaIndexes($table,$normalize=true)
  230. {
  231. if (method_exists($this->_driver,'metaIndexes'))
  232. return $this->_driver->metaIndexes($table,$normalize);
  233. }
  234. /**
  235. * Return a list of Primary Keys for a specified table.
  236. *
  237. * @param string $table
  238. * @param bool $owner (optional) not used in this driver
  239. *
  240. * @return string[] Array of indexes
  241. */
  242. public function metaPrimaryKeys($table,$owner=false)
  243. {
  244. if (method_exists($this->_driver,'metaPrimaryKeys'))
  245. return $this->_driver->metaPrimaryKeys($table,$owner);
  246. }
  247. /**
  248. * Returns a list of Foreign Keys for a specified table.
  249. *
  250. * @param string $table
  251. * @param bool $owner (optional) not used in this driver
  252. * @param bool $upper
  253. * @param bool $associative
  254. *
  255. * @return string[] where keys are tables, and values are foreign keys
  256. */
  257. public function metaForeignKeys($table, $owner=false, $upper=false,$associative=false) {
  258. if (method_exists($this->_driver,'metaForeignKeys'))
  259. return $this->_driver->metaForeignKeys($table,$owner,$upper,$associative);
  260. }
  261. /**
  262. * List procedures or functions in an array.
  263. *
  264. * @param $procedureNamePattern A procedure name pattern; must match the procedure name as it is stored in the database.
  265. * @param $catalog A catalog name; must match the catalog name as it is stored in the database.
  266. * @param $schemaPattern A schema name pattern.
  267. *
  268. * @return false|array false if not supported, or array of procedures on current database with structure below
  269. * Array(
  270. * [name_of_procedure] => Array(
  271. * [type] => PROCEDURE or FUNCTION
  272. * [catalog] => Catalog_name
  273. * [schema] => Schema_name
  274. * [remarks] => explanatory comment on the procedure
  275. * )
  276. * )
  277. */
  278. public function metaProcedures($procedureNamePattern = null, $catalog = null, $schemaPattern = null) {
  279. if (method_exists($this->_driver,'metaProcedures'))
  280. return $this->_driver->metaProcedures($procedureNamePattern,$catalog,$schemaPattern);
  281. return false;
  282. }
  283. function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)
  284. {
  285. $obj = $stmt[1];
  286. if ($type) {
  287. $obj->bindParam($name, $var, $type, $maxLen);
  288. }
  289. else {
  290. $obj->bindParam($name, $var);
  291. }
  292. }
  293. function OffsetDate($dayFraction,$date=false)
  294. {
  295. return $this->_driver->OffsetDate($dayFraction,$date);
  296. }
  297. function SelectDB($dbName)
  298. {
  299. return $this->_driver->SelectDB($dbName);
  300. }
  301. function SQLDate($fmt, $col=false)
  302. {
  303. return $this->_driver->SQLDate($fmt, $col);
  304. }
  305. function ErrorMsg()
  306. {
  307. if ($this->_errormsg !== false) {
  308. return $this->_errormsg;
  309. }
  310. if (!empty($this->_stmt)) {
  311. $arr = $this->_stmt->errorInfo();
  312. }
  313. else if (!empty($this->_connectionID)) {
  314. $arr = $this->_connectionID->errorInfo();
  315. }
  316. else {
  317. return 'No Connection Established';
  318. }
  319. if ($arr) {
  320. if (sizeof($arr)<2) {
  321. return '';
  322. }
  323. if ((integer)$arr[0]) {
  324. return $arr[2];
  325. }
  326. else {
  327. return '';
  328. }
  329. }
  330. else {
  331. return '-1';
  332. }
  333. }
  334. function ErrorNo()
  335. {
  336. if ($this->_errorno !== false) {
  337. return $this->_errorno;
  338. }
  339. if (!empty($this->_stmt)) {
  340. $err = $this->_stmt->errorCode();
  341. }
  342. else if (!empty($this->_connectionID)) {
  343. $arr = $this->_connectionID->errorInfo();
  344. if (isset($arr[0])) {
  345. $err = $arr[0];
  346. }
  347. else {
  348. $err = -1;
  349. }
  350. } else {
  351. return 0;
  352. }
  353. if ($err == '00000') {
  354. return 0; // allows empty check
  355. }
  356. return $err;
  357. }
  358. /**
  359. * @param bool $auto_commit
  360. * @return void
  361. */
  362. function SetAutoCommit($auto_commit)
  363. {
  364. if(method_exists($this->_driver, 'SetAutoCommit')) {
  365. $this->_driver->SetAutoCommit($auto_commit);
  366. }
  367. }
  368. function SetTransactionMode($transaction_mode)
  369. {
  370. if(method_exists($this->_driver, 'SetTransactionMode')) {
  371. return $this->_driver->SetTransactionMode($transaction_mode);
  372. }
  373. return parent::SetTransactionMode($transaction_mode);
  374. }
  375. function beginTrans()
  376. {
  377. if(method_exists($this->_driver, 'beginTrans')) {
  378. return $this->_driver->beginTrans();
  379. }
  380. if (!$this->hasTransactions) {
  381. return false;
  382. }
  383. if ($this->transOff) {
  384. return true;
  385. }
  386. $this->transCnt += 1;
  387. $this->_autocommit = false;
  388. $this->SetAutoCommit(false);
  389. return $this->_connectionID->beginTransaction();
  390. }
  391. function commitTrans($ok=true)
  392. {
  393. if(method_exists($this->_driver, 'commitTrans')) {
  394. return $this->_driver->commitTrans($ok);
  395. }
  396. if (!$this->hasTransactions) {
  397. return false;
  398. }
  399. if ($this->transOff) {
  400. return true;
  401. }
  402. if (!$ok) {
  403. return $this->rollbackTrans();
  404. }
  405. if ($this->transCnt) {
  406. $this->transCnt -= 1;
  407. }
  408. $this->_autocommit = true;
  409. $ret = $this->_connectionID->commit();
  410. $this->SetAutoCommit(true);
  411. return $ret;
  412. }
  413. function RollbackTrans()
  414. {
  415. if(method_exists($this->_driver, 'RollbackTrans')) {
  416. return $this->_driver->RollbackTrans();
  417. }
  418. if (!$this->hasTransactions) {
  419. return false;
  420. }
  421. if ($this->transOff) {
  422. return true;
  423. }
  424. if ($this->transCnt) {
  425. $this->transCnt -= 1;
  426. }
  427. $this->_autocommit = true;
  428. $ret = $this->_connectionID->rollback();
  429. $this->SetAutoCommit(true);
  430. return $ret;
  431. }
  432. function Prepare($sql)
  433. {
  434. $this->_stmt = $this->_connectionID->prepare($sql);
  435. if ($this->_stmt) {
  436. return array($sql,$this->_stmt);
  437. }
  438. return false;
  439. }
  440. function PrepareStmt($sql)
  441. {
  442. $stmt = $this->_connectionID->prepare($sql);
  443. if (!$stmt) {
  444. return false;
  445. }
  446. $obj = new ADOPDOStatement($stmt,$this);
  447. return $obj;
  448. }
  449. public function createSequence($seqname='adodbseq',$startID=1)
  450. {
  451. if(method_exists($this->_driver, 'createSequence')) {
  452. return $this->_driver->createSequence($seqname, $startID);
  453. }
  454. return parent::CreateSequence($seqname, $startID);
  455. }
  456. function DropSequence($seqname='adodbseq')
  457. {
  458. if(method_exists($this->_driver, 'DropSequence')) {
  459. return $this->_driver->DropSequence($seqname);
  460. }
  461. return parent::DropSequence($seqname);
  462. }
  463. function GenID($seqname='adodbseq',$startID=1)
  464. {
  465. if(method_exists($this->_driver, 'GenID')) {
  466. return $this->_driver->GenID($seqname, $startID);
  467. }
  468. return parent::GenID($seqname, $startID);
  469. }
  470. /* returns queryID or false */
  471. function _query($sql,$inputarr=false)
  472. {
  473. $ok = false;
  474. if (is_array($sql)) {
  475. $stmt = $sql[1];
  476. } else {
  477. $stmt = $this->_connectionID->prepare($sql);
  478. }
  479. if ($stmt) {
  480. if ($this->_driver instanceof ADODB_pdo) {
  481. $this->_driver->debug = $this->debug;
  482. }
  483. if ($inputarr) {
  484. $ok = $stmt->execute($inputarr);
  485. }
  486. else {
  487. $ok = $stmt->execute();
  488. }
  489. }
  490. $this->_errormsg = false;
  491. $this->_errorno = false;
  492. if ($ok) {
  493. $this->_stmt = $stmt;
  494. return $stmt;
  495. }
  496. if ($stmt) {
  497. $arr = $stmt->errorinfo();
  498. if ((integer)$arr[1]) {
  499. $this->_errormsg = $arr[2];
  500. $this->_errorno = $arr[1];
  501. }
  502. } else {
  503. $this->_errormsg = false;
  504. $this->_errorno = false;
  505. }
  506. return false;
  507. }
  508. // returns true or false
  509. function _close()
  510. {
  511. $this->_stmt = false;
  512. return true;
  513. }
  514. function _affectedrows()
  515. {
  516. if(method_exists($this->_driver, '_affectedrows'))
  517. return $this->_driver->_affectedrows();
  518. return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
  519. }
  520. function _insertid()
  521. {
  522. return ($this->_connectionID) ? $this->_connectionID->lastInsertId() : 0;
  523. }
  524. /**
  525. * Quotes a string to be sent to the database.
  526. *
  527. * If we have an active connection, delegates quoting to the underlying
  528. * PDO object PDO::quote(). Otherwise, replace "'" by the value of
  529. * $replaceQuote (same behavior as mysqli driver).
  530. *
  531. * @param string $s The string to quote
  532. * @param bool $magic_quotes This param is not used since 5.21.0.
  533. * It remains for backwards compatibility.
  534. *
  535. * @return string Quoted string
  536. */
  537. function qStr($s, $magic_quotes = false)
  538. {
  539. if ($this->_connectionID) {
  540. return $this->_connectionID->quote($s);
  541. }
  542. return "'" . str_replace("'", $this->replaceQuote, $s) . "'";
  543. }
  544. }
  545. class ADODB_pdo_base extends ADODB_pdo {
  546. var $sysDate = "'?'";
  547. var $sysTimeStamp = "'?'";
  548. function _init($parentDriver)
  549. {
  550. $parentDriver->_bindInputArray = true;
  551. #$parentDriver->_connectionID->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY,true);
  552. }
  553. function ServerInfo()
  554. {
  555. return ADOConnection::ServerInfo();
  556. }
  557. function SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
  558. {
  559. $ret = ADOConnection::SelectLimit($sql,$nrows,$offset,$inputarr,$secs2cache);
  560. return $ret;
  561. }
  562. function MetaTables($ttype=false,$showSchema=false,$mask=false)
  563. {
  564. return false;
  565. }
  566. function MetaColumns($table,$normalize=true)
  567. {
  568. return false;
  569. }
  570. }
  571. class ADOPDOStatement {
  572. var $databaseType = "pdo";
  573. var $dataProvider = "pdo";
  574. var $_stmt;
  575. var $_connectionID;
  576. function __construct($stmt,$connection)
  577. {
  578. $this->_stmt = $stmt;
  579. $this->_connectionID = $connection;
  580. }
  581. function Execute($inputArr=false)
  582. {
  583. $savestmt = $this->_connectionID->_stmt;
  584. $rs = $this->_connectionID->Execute(array(false,$this->_stmt),$inputArr);
  585. $this->_connectionID->_stmt = $savestmt;
  586. return $rs;
  587. }
  588. function InParameter(&$var,$name,$maxLen=4000,$type=false)
  589. {
  590. if ($type) {
  591. $this->_stmt->bindParam($name,$var,$type,$maxLen);
  592. }
  593. else {
  594. $this->_stmt->bindParam($name, $var);
  595. }
  596. }
  597. function Affected_Rows()
  598. {
  599. return ($this->_stmt) ? $this->_stmt->rowCount() : 0;
  600. }
  601. function ErrorMsg()
  602. {
  603. if ($this->_stmt) {
  604. $arr = $this->_stmt->errorInfo();
  605. }
  606. else {
  607. $arr = $this->_connectionID->errorInfo();
  608. }
  609. if (is_array($arr)) {
  610. if ((integer) $arr[0] && isset($arr[2])) {
  611. return $arr[2];
  612. }
  613. else {
  614. return '';
  615. }
  616. } else {
  617. return '-1';
  618. }
  619. }
  620. function NumCols()
  621. {
  622. return ($this->_stmt) ? $this->_stmt->columnCount() : 0;
  623. }
  624. function ErrorNo()
  625. {
  626. if ($this->_stmt) {
  627. return $this->_stmt->errorCode();
  628. }
  629. else {
  630. return $this->_connectionID->errorInfo();
  631. }
  632. }
  633. }
  634. /*--------------------------------------------------------------------------------------
  635. Class Name: Recordset
  636. --------------------------------------------------------------------------------------*/
  637. class ADORecordSet_pdo extends ADORecordSet {
  638. var $bind = false;
  639. var $databaseType = "pdo";
  640. var $dataProvider = "pdo";
  641. function __construct($id,$mode=false)
  642. {
  643. if ($mode === false) {
  644. global $ADODB_FETCH_MODE;
  645. $mode = $ADODB_FETCH_MODE;
  646. }
  647. $this->adodbFetchMode = $mode;
  648. switch($mode) {
  649. case ADODB_FETCH_NUM: $mode = PDO::FETCH_NUM; break;
  650. case ADODB_FETCH_ASSOC: $mode = PDO::FETCH_ASSOC; break;
  651. case ADODB_FETCH_BOTH:
  652. default: $mode = PDO::FETCH_BOTH; break;
  653. }
  654. $this->fetchMode = $mode;
  655. $this->_queryID = $id;
  656. parent::__construct($id);
  657. }
  658. function Init()
  659. {
  660. if ($this->_inited) {
  661. return;
  662. }
  663. $this->_inited = true;
  664. if ($this->_queryID) {
  665. @$this->_initrs();
  666. }
  667. else {
  668. $this->_numOfRows = 0;
  669. $this->_numOfFields = 0;
  670. }
  671. if ($this->_numOfRows != 0 && $this->_currentRow == -1) {
  672. $this->_currentRow = 0;
  673. if ($this->EOF = ($this->_fetch() === false)) {
  674. $this->_numOfRows = 0; // _numOfRows could be -1
  675. }
  676. } else {
  677. $this->EOF = true;
  678. }
  679. }
  680. function _initrs()
  681. {
  682. global $ADODB_COUNTRECS;
  683. $this->_numOfRows = ($ADODB_COUNTRECS) ? @$this->_queryID->rowCount() : -1;
  684. if (!$this->_numOfRows) {
  685. $this->_numOfRows = -1;
  686. }
  687. $this->_numOfFields = $this->_queryID->columnCount();
  688. }
  689. // returns the field object
  690. function FetchField($fieldOffset = -1)
  691. {
  692. $off=$fieldOffset+1; // offsets begin at 1
  693. $o= new ADOFieldObject();
  694. $arr = @$this->_queryID->getColumnMeta($fieldOffset);
  695. if (!$arr) {
  696. $o->name = 'bad getColumnMeta()';
  697. $o->max_length = -1;
  698. $o->type = 'VARCHAR';
  699. $o->precision = 0;
  700. # $false = false;
  701. return $o;
  702. }
  703. //adodb_pr($arr);
  704. $o->name = $arr['name'];
  705. if (isset($arr['sqlsrv:decl_type']) && $arr['sqlsrv:decl_type'] <> "null")
  706. {
  707. /*
  708. * If the database is SQL server, use the native built-ins
  709. */
  710. $o->type = $arr['sqlsrv:decl_type'];
  711. }
  712. elseif (isset($arr['native_type']) && $arr['native_type'] <> "null")
  713. {
  714. $o->type = $arr['native_type'];
  715. }
  716. else
  717. {
  718. $o->type = adodb_pdo_type($arr['pdo_type']);
  719. }
  720. $o->max_length = $arr['len'];
  721. $o->precision = $arr['precision'];
  722. switch(ADODB_ASSOC_CASE) {
  723. case ADODB_ASSOC_CASE_LOWER:
  724. $o->name = strtolower($o->name);
  725. break;
  726. case ADODB_ASSOC_CASE_UPPER:
  727. $o->name = strtoupper($o->name);
  728. break;
  729. }
  730. return $o;
  731. }
  732. function _seek($row)
  733. {
  734. return false;
  735. }
  736. function _fetch()
  737. {
  738. if (!$this->_queryID) {
  739. return false;
  740. }
  741. $this->fields = $this->_queryID->fetch($this->fetchMode);
  742. return !empty($this->fields);
  743. }
  744. function _close()
  745. {
  746. $this->_queryID = false;
  747. }
  748. function Fields($colname)
  749. {
  750. if ($this->adodbFetchMode != ADODB_FETCH_NUM) {
  751. return @$this->fields[$colname];
  752. }
  753. if (!$this->bind) {
  754. $this->bind = array();
  755. for ($i=0; $i < $this->_numOfFields; $i++) {
  756. $o = $this->FetchField($i);
  757. $this->bind[strtoupper($o->name)] = $i;
  758. }
  759. }
  760. return $this->fields[$this->bind[strtoupper($colname)]];
  761. }
  762. }
  763. class ADORecordSet_array_pdo extends ADORecordSet_array {}