PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/concrete/libraries/3rdparty/adodb/drivers/adodb-odbtp.inc.php

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