PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/synergylearning/campusconnect
PHP | 748 lines | 514 code | 110 blank | 124 comment | 146 complexity | cfb0ac245f211624a12f05241e96a924 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. /*
  3. V5.18 3 Sep 2012 (c) 2000-2012 John Lim (jlim#natsoft.com). 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.
  7. Set tabs to 4 for best viewing.
  8. Latest version is available at http://adodb.sourceforge.net
  9. Requires ODBC. Works on Windows and Unix.
  10. */
  11. // security - hide paths
  12. if (!defined('ADODB_DIR')) die();
  13. define("_ADODB_ODBC_LAYER", 2 );
  14. /*--------------------------------------------------------------------------------------
  15. --------------------------------------------------------------------------------------*/
  16. class ADODB_odbc extends ADOConnection {
  17. var $databaseType = "odbc";
  18. var $fmtDate = "'Y-m-d'";
  19. var $fmtTimeStamp = "'Y-m-d, h:i:sA'";
  20. var $replaceQuote = "''"; // string to use to replace quotes
  21. var $dataProvider = "odbc";
  22. var $hasAffectedRows = true;
  23. var $binmode = ODBC_BINMODE_RETURN;
  24. var $useFetchArray = false; // setting this to true will make array elements in FETCH_ASSOC mode case-sensitive
  25. // breaking backward-compat
  26. //var $longreadlen = 8000; // default number of chars to return for a Blob/Long field
  27. var $_bindInputArray = false;
  28. var $curmode = SQL_CUR_USE_DRIVER; // See sqlext.h, SQL_CUR_DEFAULT == SQL_CUR_USE_DRIVER == 2L
  29. var $_genSeqSQL = "create table %s (id integer)";
  30. var $_autocommit = true;
  31. var $_haserrorfunctions = true;
  32. var $_has_stupid_odbc_fetch_api_change = true;
  33. var $_lastAffectedRows = 0;
  34. var $uCaseTables = true; // for meta* functions, uppercase table names
  35. function ADODB_odbc()
  36. {
  37. $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050;
  38. $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
  39. }
  40. // returns true or false
  41. function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
  42. {
  43. global $php_errormsg;
  44. if (!function_exists('odbc_connect')) return null;
  45. if (!empty($argDatabasename) && stristr($argDSN, 'Database=') === false) {
  46. $argDSN = trim($argDSN);
  47. $endDSN = substr($argDSN, strlen($argDSN) - 1);
  48. if ($endDSN != ';') $argDSN .= ';';
  49. $argDSN .= 'Database='.$argDatabasename;
  50. }
  51. if (isset($php_errormsg)) $php_errormsg = '';
  52. if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
  53. else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
  54. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  55. if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
  56. return $this->_connectionID != false;
  57. }
  58. // returns true or false
  59. function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
  60. {
  61. global $php_errormsg;
  62. if (!function_exists('odbc_connect')) return null;
  63. if (isset($php_errormsg)) $php_errormsg = '';
  64. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  65. if ($this->debug && $argDatabasename) {
  66. ADOConnection::outp("For odbc PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
  67. }
  68. // print "dsn=$argDSN u=$argUsername p=$argPassword<br>"; flush();
  69. if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
  70. else $this->_connectionID = odbc_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
  71. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  72. if ($this->_connectionID && $this->autoRollback) @odbc_rollback($this->_connectionID);
  73. if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
  74. return $this->_connectionID != false;
  75. }
  76. function ServerInfo()
  77. {
  78. if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
  79. $dsn = strtoupper($this->host);
  80. $first = true;
  81. $found = false;
  82. if (!function_exists('odbc_data_source')) return false;
  83. while(true) {
  84. $rez = @odbc_data_source($this->_connectionID,
  85. $first ? SQL_FETCH_FIRST : SQL_FETCH_NEXT);
  86. $first = false;
  87. if (!is_array($rez)) break;
  88. if (strtoupper($rez['server']) == $dsn) {
  89. $found = true;
  90. break;
  91. }
  92. }
  93. if (!$found) return ADOConnection::ServerInfo();
  94. if (!isset($rez['version'])) $rez['version'] = '';
  95. return $rez;
  96. } else {
  97. return ADOConnection::ServerInfo();
  98. }
  99. }
  100. function CreateSequence($seqname='adodbseq',$start=1)
  101. {
  102. if (empty($this->_genSeqSQL)) return false;
  103. $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  104. if (!$ok) return false;
  105. $start -= 1;
  106. return $this->Execute("insert into $seqname values($start)");
  107. }
  108. var $_dropSeqSQL = 'drop table %s';
  109. function DropSequence($seqname)
  110. {
  111. if (empty($this->_dropSeqSQL)) return false;
  112. return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
  113. }
  114. /*
  115. This algorithm is not very efficient, but works even if table locking
  116. is not available.
  117. Will return false if unable to generate an ID after $MAXLOOPS attempts.
  118. */
  119. function GenID($seq='adodbseq',$start=1)
  120. {
  121. // if you have to modify the parameter below, your database is overloaded,
  122. // or you need to implement generation of id's yourself!
  123. $MAXLOOPS = 100;
  124. //$this->debug=1;
  125. while (--$MAXLOOPS>=0) {
  126. $num = $this->GetOne("select id from $seq");
  127. if ($num === false) {
  128. $this->Execute(sprintf($this->_genSeqSQL ,$seq));
  129. $start -= 1;
  130. $num = '0';
  131. $ok = $this->Execute("insert into $seq values($start)");
  132. if (!$ok) return false;
  133. }
  134. $this->Execute("update $seq set id=id+1 where id=$num");
  135. if ($this->affected_rows() > 0) {
  136. $num += 1;
  137. $this->genID = $num;
  138. return $num;
  139. } elseif ($this->affected_rows() == 0) {
  140. // some drivers do not return a valid value => try with another method
  141. $value = $this->GetOne("select id from $seq");
  142. if ($value == $num + 1) {
  143. return $value;
  144. }
  145. }
  146. }
  147. if ($fn = $this->raiseErrorFn) {
  148. $fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
  149. }
  150. return false;
  151. }
  152. function ErrorMsg()
  153. {
  154. if ($this->_haserrorfunctions) {
  155. if ($this->_errorMsg !== false) return $this->_errorMsg;
  156. if (empty($this->_connectionID)) return @odbc_errormsg();
  157. return @odbc_errormsg($this->_connectionID);
  158. } else return ADOConnection::ErrorMsg();
  159. }
  160. function ErrorNo()
  161. {
  162. if ($this->_haserrorfunctions) {
  163. if ($this->_errorCode !== false) {
  164. // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
  165. return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode;
  166. }
  167. if (empty($this->_connectionID)) $e = @odbc_error();
  168. else $e = @odbc_error($this->_connectionID);
  169. // bug in 4.0.6, error number can be corrupted string (should be 6 digits)
  170. // so we check and patch
  171. if (strlen($e)<=2) return 0;
  172. return $e;
  173. } else return ADOConnection::ErrorNo();
  174. }
  175. function BeginTrans()
  176. {
  177. if (!$this->hasTransactions) return false;
  178. if ($this->transOff) return true;
  179. $this->transCnt += 1;
  180. $this->_autocommit = false;
  181. return odbc_autocommit($this->_connectionID,false);
  182. }
  183. function CommitTrans($ok=true)
  184. {
  185. if ($this->transOff) return true;
  186. if (!$ok) return $this->RollbackTrans();
  187. if ($this->transCnt) $this->transCnt -= 1;
  188. $this->_autocommit = true;
  189. $ret = odbc_commit($this->_connectionID);
  190. odbc_autocommit($this->_connectionID,true);
  191. return $ret;
  192. }
  193. function RollbackTrans()
  194. {
  195. if ($this->transOff) return true;
  196. if ($this->transCnt) $this->transCnt -= 1;
  197. $this->_autocommit = true;
  198. $ret = odbc_rollback($this->_connectionID);
  199. odbc_autocommit($this->_connectionID,true);
  200. return $ret;
  201. }
  202. function MetaPrimaryKeys($table)
  203. {
  204. global $ADODB_FETCH_MODE;
  205. if ($this->uCaseTables) $table = strtoupper($table);
  206. $schema = '';
  207. $this->_findschema($table,$schema);
  208. $savem = $ADODB_FETCH_MODE;
  209. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  210. $qid = @odbc_primarykeys($this->_connectionID,'',$schema,$table);
  211. if (!$qid) {
  212. $ADODB_FETCH_MODE = $savem;
  213. return false;
  214. }
  215. $rs = new ADORecordSet_odbc($qid);
  216. $ADODB_FETCH_MODE = $savem;
  217. if (!$rs) return false;
  218. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  219. $arr = $rs->GetArray();
  220. $rs->Close();
  221. //print_r($arr);
  222. $arr2 = array();
  223. for ($i=0; $i < sizeof($arr); $i++) {
  224. if ($arr[$i][3]) $arr2[] = $arr[$i][3];
  225. }
  226. return $arr2;
  227. }
  228. function MetaTables($ttype=false)
  229. {
  230. global $ADODB_FETCH_MODE;
  231. $savem = $ADODB_FETCH_MODE;
  232. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  233. $qid = odbc_tables($this->_connectionID);
  234. $rs = new ADORecordSet_odbc($qid);
  235. $ADODB_FETCH_MODE = $savem;
  236. if (!$rs) {
  237. $false = false;
  238. return $false;
  239. }
  240. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  241. $arr = $rs->GetArray();
  242. //print_r($arr);
  243. $rs->Close();
  244. $arr2 = array();
  245. if ($ttype) {
  246. $isview = strncmp($ttype,'V',1) === 0;
  247. }
  248. for ($i=0; $i < sizeof($arr); $i++) {
  249. if (!$arr[$i][2]) continue;
  250. $type = $arr[$i][3];
  251. if ($ttype) {
  252. if ($isview) {
  253. if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2];
  254. } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
  255. } else if (strncmp($type,'SYS',3) !== 0) $arr2[] = $arr[$i][2];
  256. }
  257. return $arr2;
  258. }
  259. /*
  260. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcdatetime_data_type_changes.asp
  261. / SQL data type codes /
  262. #define SQL_UNKNOWN_TYPE 0
  263. #define SQL_CHAR 1
  264. #define SQL_NUMERIC 2
  265. #define SQL_DECIMAL 3
  266. #define SQL_INTEGER 4
  267. #define SQL_SMALLINT 5
  268. #define SQL_FLOAT 6
  269. #define SQL_REAL 7
  270. #define SQL_DOUBLE 8
  271. #if (ODBCVER >= 0x0300)
  272. #define SQL_DATETIME 9
  273. #endif
  274. #define SQL_VARCHAR 12
  275. / One-parameter shortcuts for date/time data types /
  276. #if (ODBCVER >= 0x0300)
  277. #define SQL_TYPE_DATE 91
  278. #define SQL_TYPE_TIME 92
  279. #define SQL_TYPE_TIMESTAMP 93
  280. #define SQL_UNICODE (-95)
  281. #define SQL_UNICODE_VARCHAR (-96)
  282. #define SQL_UNICODE_LONGVARCHAR (-97)
  283. */
  284. function ODBCTypes($t)
  285. {
  286. switch ((integer)$t) {
  287. case 1:
  288. case 12:
  289. case 0:
  290. case -95:
  291. case -96:
  292. return 'C';
  293. case -97:
  294. case -1: //text
  295. return 'X';
  296. case -4: //image
  297. return 'B';
  298. case 9:
  299. case 91:
  300. return 'D';
  301. case 10:
  302. case 11:
  303. case 92:
  304. case 93:
  305. return 'T';
  306. case 4:
  307. case 5:
  308. case -6:
  309. return 'I';
  310. case -11: // uniqidentifier
  311. return 'R';
  312. case -7: //bit
  313. return 'L';
  314. default:
  315. return 'N';
  316. }
  317. }
  318. function MetaColumns($table, $normalize=true)
  319. {
  320. global $ADODB_FETCH_MODE;
  321. $false = false;
  322. if ($this->uCaseTables) $table = strtoupper($table);
  323. $schema = '';
  324. $this->_findschema($table,$schema);
  325. $savem = $ADODB_FETCH_MODE;
  326. $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  327. /*if (false) { // after testing, confirmed that the following does not work becoz of a bug
  328. $qid2 = odbc_tables($this->_connectionID);
  329. $rs = new ADORecordSet_odbc($qid2);
  330. $ADODB_FETCH_MODE = $savem;
  331. if (!$rs) return false;
  332. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  333. $rs->_fetch();
  334. while (!$rs->EOF) {
  335. if ($table == strtoupper($rs->fields[2])) {
  336. $q = $rs->fields[0];
  337. $o = $rs->fields[1];
  338. break;
  339. }
  340. $rs->MoveNext();
  341. }
  342. $rs->Close();
  343. $qid = odbc_columns($this->_connectionID,$q,$o,strtoupper($table),'%');
  344. } */
  345. switch ($this->databaseType) {
  346. case 'access':
  347. case 'vfp':
  348. $qid = odbc_columns($this->_connectionID);#,'%','',strtoupper($table),'%');
  349. break;
  350. case 'db2':
  351. $colname = "%";
  352. $qid = odbc_columns($this->_connectionID, "", $schema, $table, $colname);
  353. break;
  354. default:
  355. $qid = @odbc_columns($this->_connectionID,'%','%',strtoupper($table),'%');
  356. if (empty($qid)) $qid = odbc_columns($this->_connectionID);
  357. break;
  358. }
  359. if (empty($qid)) return $false;
  360. $rs = new ADORecordSet_odbc($qid);
  361. $ADODB_FETCH_MODE = $savem;
  362. if (!$rs) return $false;
  363. $rs->_has_stupid_odbc_fetch_api_change = $this->_has_stupid_odbc_fetch_api_change;
  364. $rs->_fetch();
  365. $retarr = array();
  366. /*
  367. $rs->fields indices
  368. 0 TABLE_QUALIFIER
  369. 1 TABLE_SCHEM
  370. 2 TABLE_NAME
  371. 3 COLUMN_NAME
  372. 4 DATA_TYPE
  373. 5 TYPE_NAME
  374. 6 PRECISION
  375. 7 LENGTH
  376. 8 SCALE
  377. 9 RADIX
  378. 10 NULLABLE
  379. 11 REMARKS
  380. */
  381. while (!$rs->EOF) {
  382. // adodb_pr($rs->fields);
  383. if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
  384. $fld = new ADOFieldObject();
  385. $fld->name = $rs->fields[3];
  386. $fld->type = $this->ODBCTypes($rs->fields[4]);
  387. // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
  388. // access uses precision to store length for char/varchar
  389. if ($fld->type == 'C' or $fld->type == 'X') {
  390. if ($this->databaseType == 'access')
  391. $fld->max_length = $rs->fields[6];
  392. else if ($rs->fields[4] <= -95) // UNICODE
  393. $fld->max_length = $rs->fields[7]/2;
  394. else
  395. $fld->max_length = $rs->fields[7];
  396. } else
  397. $fld->max_length = $rs->fields[7];
  398. $fld->not_null = !empty($rs->fields[10]);
  399. $fld->scale = $rs->fields[8];
  400. $retarr[strtoupper($fld->name)] = $fld;
  401. } else if (sizeof($retarr)>0)
  402. break;
  403. $rs->MoveNext();
  404. }
  405. $rs->Close(); //-- crashes 4.03pl1 -- why?
  406. if (empty($retarr)) $retarr = false;
  407. return $retarr;
  408. }
  409. function Prepare($sql)
  410. {
  411. if (! $this->_bindInputArray) return $sql; // no binding
  412. $stmt = odbc_prepare($this->_connectionID,$sql);
  413. if (!$stmt) {
  414. // we don't know whether odbc driver is parsing prepared stmts, so just return sql
  415. return $sql;
  416. }
  417. return array($sql,$stmt,false);
  418. }
  419. /* returns queryID or false */
  420. function _query($sql,$inputarr=false)
  421. {
  422. GLOBAL $php_errormsg;
  423. if (isset($php_errormsg)) $php_errormsg = '';
  424. $this->_error = '';
  425. if ($inputarr) {
  426. if (is_array($sql)) {
  427. $stmtid = $sql[1];
  428. } else {
  429. $stmtid = odbc_prepare($this->_connectionID,$sql);
  430. if ($stmtid == false) {
  431. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  432. return false;
  433. }
  434. }
  435. if (! odbc_execute($stmtid,$inputarr)) {
  436. //@odbc_free_result($stmtid);
  437. if ($this->_haserrorfunctions) {
  438. $this->_errorMsg = odbc_errormsg();
  439. $this->_errorCode = odbc_error();
  440. }
  441. return false;
  442. }
  443. } else if (is_array($sql)) {
  444. $stmtid = $sql[1];
  445. if (!odbc_execute($stmtid)) {
  446. //@odbc_free_result($stmtid);
  447. if ($this->_haserrorfunctions) {
  448. $this->_errorMsg = odbc_errormsg();
  449. $this->_errorCode = odbc_error();
  450. }
  451. return false;
  452. }
  453. } else
  454. $stmtid = odbc_exec($this->_connectionID,$sql);
  455. $this->_lastAffectedRows = 0;
  456. if ($stmtid) {
  457. if (@odbc_num_fields($stmtid) == 0) {
  458. $this->_lastAffectedRows = odbc_num_rows($stmtid);
  459. $stmtid = true;
  460. } else {
  461. $this->_lastAffectedRows = 0;
  462. odbc_binmode($stmtid,$this->binmode);
  463. odbc_longreadlen($stmtid,$this->maxblobsize);
  464. }
  465. if ($this->_haserrorfunctions) {
  466. $this->_errorMsg = '';
  467. $this->_errorCode = 0;
  468. } else
  469. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  470. } else {
  471. if ($this->_haserrorfunctions) {
  472. $this->_errorMsg = odbc_errormsg();
  473. $this->_errorCode = odbc_error();
  474. } else
  475. $this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
  476. }
  477. return $stmtid;
  478. }
  479. /*
  480. Insert a null into the blob field of the table first.
  481. Then use UpdateBlob to store the blob.
  482. Usage:
  483. $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
  484. $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
  485. */
  486. function UpdateBlob($table,$column,$val,$where,$blobtype='BLOB')
  487. {
  488. return $this->Execute("UPDATE $table SET $column=? WHERE $where",array($val)) != false;
  489. }
  490. // returns true or false
  491. function _close()
  492. {
  493. $ret = @odbc_close($this->_connectionID);
  494. $this->_connectionID = false;
  495. return $ret;
  496. }
  497. function _affectedrows()
  498. {
  499. return $this->_lastAffectedRows;
  500. }
  501. }
  502. /*--------------------------------------------------------------------------------------
  503. Class Name: Recordset
  504. --------------------------------------------------------------------------------------*/
  505. class ADORecordSet_odbc extends ADORecordSet {
  506. var $bind = false;
  507. var $databaseType = "odbc";
  508. var $dataProvider = "odbc";
  509. var $useFetchArray;
  510. var $_has_stupid_odbc_fetch_api_change;
  511. function ADORecordSet_odbc($id,$mode=false)
  512. {
  513. if ($mode === false) {
  514. global $ADODB_FETCH_MODE;
  515. $mode = $ADODB_FETCH_MODE;
  516. }
  517. $this->fetchMode = $mode;
  518. $this->_queryID = $id;
  519. // the following is required for mysql odbc driver in 4.3.1 -- why?
  520. $this->EOF = false;
  521. $this->_currentRow = -1;
  522. //$this->ADORecordSet($id);
  523. }
  524. // returns the field object
  525. function FetchField($fieldOffset = -1)
  526. {
  527. $off=$fieldOffset+1; // offsets begin at 1
  528. $o= new ADOFieldObject();
  529. $o->name = @odbc_field_name($this->_queryID,$off);
  530. $o->type = @odbc_field_type($this->_queryID,$off);
  531. $o->max_length = @odbc_field_len($this->_queryID,$off);
  532. if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
  533. else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
  534. return $o;
  535. }
  536. /* Use associative array to get fields array */
  537. function Fields($colname)
  538. {
  539. if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
  540. if (!$this->bind) {
  541. $this->bind = array();
  542. for ($i=0; $i < $this->_numOfFields; $i++) {
  543. $o = $this->FetchField($i);
  544. $this->bind[strtoupper($o->name)] = $i;
  545. }
  546. }
  547. return $this->fields[$this->bind[strtoupper($colname)]];
  548. }
  549. function _initrs()
  550. {
  551. global $ADODB_COUNTRECS;
  552. $this->_numOfRows = ($ADODB_COUNTRECS) ? @odbc_num_rows($this->_queryID) : -1;
  553. $this->_numOfFields = @odbc_num_fields($this->_queryID);
  554. // some silly drivers such as db2 as/400 and intersystems cache return _numOfRows = 0
  555. if ($this->_numOfRows == 0) $this->_numOfRows = -1;
  556. //$this->useFetchArray = $this->connection->useFetchArray;
  557. $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
  558. }
  559. function _seek($row)
  560. {
  561. return false;
  562. }
  563. // speed up SelectLimit() by switching to ADODB_FETCH_NUM as ADODB_FETCH_ASSOC is emulated
  564. function GetArrayLimit($nrows,$offset=-1)
  565. {
  566. if ($offset <= 0) {
  567. $rs = $this->GetArray($nrows);
  568. return $rs;
  569. }
  570. $savem = $this->fetchMode;
  571. $this->fetchMode = ADODB_FETCH_NUM;
  572. $this->Move($offset);
  573. $this->fetchMode = $savem;
  574. if ($this->fetchMode & ADODB_FETCH_ASSOC) {
  575. $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
  576. }
  577. $results = array();
  578. $cnt = 0;
  579. while (!$this->EOF && $nrows != $cnt) {
  580. $results[$cnt++] = $this->fields;
  581. $this->MoveNext();
  582. }
  583. return $results;
  584. }
  585. function MoveNext()
  586. {
  587. if ($this->_numOfRows != 0 && !$this->EOF) {
  588. $this->_currentRow++;
  589. if ($this->_has_stupid_odbc_fetch_api_change)
  590. $rez = @odbc_fetch_into($this->_queryID,$this->fields);
  591. else {
  592. $row = 0;
  593. $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
  594. }
  595. if ($rez) {
  596. if ($this->fetchMode & ADODB_FETCH_ASSOC) {
  597. $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
  598. }
  599. return true;
  600. }
  601. }
  602. $this->fields = false;
  603. $this->EOF = true;
  604. return false;
  605. }
  606. function _fetch()
  607. {
  608. if ($this->_has_stupid_odbc_fetch_api_change)
  609. $rez = @odbc_fetch_into($this->_queryID,$this->fields);
  610. else {
  611. $row = 0;
  612. $rez = @odbc_fetch_into($this->_queryID,$row,$this->fields);
  613. }
  614. if ($rez) {
  615. if ($this->fetchMode & ADODB_FETCH_ASSOC) {
  616. $this->fields = $this->GetRowAssoc(ADODB_ASSOC_CASE);
  617. }
  618. return true;
  619. }
  620. $this->fields = false;
  621. return false;
  622. }
  623. function _close()
  624. {
  625. return @odbc_free_result($this->_queryID);
  626. }
  627. }
  628. ?>