39 if (!defined(
'ADODB_DIR'))
die();
41 define(
"_ADODB_ADS_LAYER", 2 );
71 $this->_haserrorfunctions = ADODB_PHPVER >= 0x4050;
72 $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
76 function _connect($argDSN, $argUsername, $argPassword, $argDatabasename)
80 if (!function_exists(
'ads_connect'))
return null;
82 if ($this->
debug && $argDatabasename && $this->databaseType !=
'vfp') {
83 ADOConnection::outp(
"For Advantage Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
85 if (isset($php_errormsg)) $php_errormsg =
'';
86 if ($this->curmode ===
false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword);
87 else $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword,$this->curmode);
88 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
89 if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
91 return $this->_connectionID !=
false;
95 function _pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
99 if (!function_exists(
'ads_connect'))
return null;
101 if (isset($php_errormsg)) $php_errormsg =
'';
102 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
103 if ($this->
debug && $argDatabasename) {
104 ADOConnection::outp(
"For PConnect(), $argDatabasename is not used. Place dsn in 1st parameter.");
107 if ($this->curmode ===
false) $this->_connectionID = ads_connect($argDSN,$argUsername,$argPassword);
108 else $this->_connectionID = ads_pconnect($argDSN,$argUsername,$argPassword,$this->curmode);
110 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
111 if ($this->_connectionID && $this->autoRollback) @ads_rollback($this->_connectionID);
112 if (isset($this->connectStmt)) $this->Execute($this->connectStmt);
114 return $this->_connectionID !=
false;
121 if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
122 $stmt = $this->
Prepare(
'EXECUTE PROCEDURE sp_mgGetInstallInfo()');
123 $res = $this->Execute($stmt);
127 $ret[
"version"]= $res->fields[3];
128 $ret[
"description"]=
"Advantage Database Server";
133 return ADOConnection::ServerInfo();
141 $res = $this->Execute(
"CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE");
154 $res = $this->Execute(
"DROP TABLE $seqname");
169 $go = $this->Execute(
"select * from $seqname");
171 $res = $this->Execute(
"CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE");
177 $res = $this->Execute(
"INSERT INTO $seqname VALUES( DEFAULT )");
183 $gen = $this->Execute(
"SELECT LastAutoInc( STATEMENT ) FROM system.iota");
184 $ret = $gen->fields[0];
195 if ($this->_haserrorfunctions) {
196 if ($this->_errorMsg !==
false)
return $this->_errorMsg;
197 if (empty($this->_connectionID))
return @ads_errormsg();
198 return @ads_errormsg($this->_connectionID);
199 }
else return ADOConnection::ErrorMsg();
206 if ($this->_haserrorfunctions) {
207 if ($this->_errorCode !==
false) {
209 return (strlen($this->_errorCode)<=2) ? 0 : $this->_errorCode;
212 if (empty($this->_connectionID)) $e = @ads_error();
213 else $e = @ads_error($this->_connectionID);
217 if (strlen($e)<=2)
return 0;
219 }
else return ADOConnection::ErrorNo();
226 if (!$this->hasTransactions)
return false;
227 if ($this->transOff)
return true;
228 $this->transCnt += 1;
229 $this->_autocommit =
false;
230 return ads_autocommit($this->_connectionID,
false);
235 if ($this->transOff)
return true;
237 if ($this->transCnt) $this->transCnt -= 1;
238 $this->_autocommit =
true;
239 $ret = ads_commit($this->_connectionID);
240 ads_autocommit($this->_connectionID,
true);
246 if ($this->transOff)
return true;
247 if ($this->transCnt) $this->transCnt -= 1;
248 $this->_autocommit =
true;
249 $ret = ads_rollback($this->_connectionID);
250 ads_autocommit($this->_connectionID,
true);
259 $recordSet1 = $this->Execute(
"select * from system.tables");
264 $recordSet2 = $this->Execute(
"select * from system.views");
270 while (!$recordSet1->EOF){
271 $arr[
"$i"] = $recordSet1->fields[0];
272 $recordSet1->MoveNext();
276 while (!$recordSet2->EOF){
277 $arr[
"$i"] = $recordSet2->fields[0];
278 $recordSet2->MoveNext();
283 elseif($ttype==
'VIEWS'){
284 while (!$recordSet2->EOF){
285 $arrV[
"$i"] = $recordSet2->fields[0];
286 $recordSet2->MoveNext();
299 $recordSet = $this->Execute(
"select table_primary_key from system.tables where name='$table'");
305 while (!$recordSet->EOF){
306 $arr[
"$i"] = $recordSet->fields[0];
307 $recordSet->MoveNext();
343 switch ((integer)$t) {
383 global $ADODB_FETCH_MODE;
386 if ($this->uCaseTables) $table = strtoupper($table);
388 $this->_findschema($table,$schema);
390 $savem = $ADODB_FETCH_MODE;
391 $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
414 switch ($this->databaseType) {
417 $qid = ads_columns($this->_connectionID);#,
'%',
'',strtoupper($table),
'%');
423 $qid = ads_columns($this->_connectionID,
"", $schema, $table, $colname);
427 $qid = @ads_columns($this->_connectionID,
'%',
'%',strtoupper($table),
'%');
428 if (empty($qid)) $qid = ads_columns($this->_connectionID);
431 if (empty($qid))
return $false;
434 $ADODB_FETCH_MODE = $savem;
436 if (!
$rs)
return $false;
459 if (strtoupper(trim(
$rs->fields[2])) == $table && (!$schema || strtoupper(
$rs->fields[1]) == $schema)) {
460 $fld =
new ADOFieldObject();
461 $fld->name =
$rs->fields[3];
466 if ($fld->type ==
'C' or $fld->type ==
'X') {
467 if ($this->databaseType ==
'access')
468 $fld->max_length =
$rs->fields[6];
469 else if (
$rs->fields[4] <= -95)
470 $fld->max_length =
$rs->fields[7]/2;
472 $fld->max_length =
$rs->fields[7];
474 $fld->max_length =
$rs->fields[7];
475 $fld->not_null = !empty(
$rs->fields[10]);
476 $fld->scale =
$rs->fields[8];
477 $retarr[strtoupper($fld->name)] = $fld;
478 }
else if (
sizeof($retarr)>0)
484 if (empty($retarr)) $retarr =
false;
491 $recordSet = $this->Execute(
"select name from system.columns where parent='$table'");
498 while (!$recordSet->EOF){
499 $arr[
"FIELD$i"] = $recordSet->fields[0];
500 $recordSet->MoveNext();
510 if (! $this->_bindInputArray)
return $sql;
511 $stmt = ads_prepare($this->_connectionID,
$sql);
516 return array(
$sql,$stmt,
false);
522 GLOBAL $php_errormsg;
523 if (isset($php_errormsg)) $php_errormsg =
'';
527 if (is_array(
$sql)) {
530 $stmtid = ads_prepare($this->_connectionID,
$sql);
532 if ($stmtid ==
false) {
533 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
538 if (! ads_execute($stmtid,$inputarr)) {
540 if ($this->_haserrorfunctions) {
541 $this->_errorMsg = ads_errormsg();
542 $this->_errorCode = ads_error();
547 }
else if (is_array(
$sql)) {
549 if (!ads_execute($stmtid)) {
551 if ($this->_haserrorfunctions) {
552 $this->_errorMsg = ads_errormsg();
553 $this->_errorCode = ads_error();
560 $stmtid = ads_exec($this->_connectionID,
$sql);
564 $this->_lastAffectedRows = 0;
569 if (@ads_num_fields($stmtid) == 0) {
570 $this->_lastAffectedRows = ads_num_rows($stmtid);
575 $this->_lastAffectedRows = 0;
576 ads_binmode($stmtid,$this->binmode);
577 ads_longreadlen($stmtid,$this->maxblobsize);
581 if ($this->_haserrorfunctions)
584 $this->_errorMsg =
'';
585 $this->_errorCode = 0;
588 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
592 if ($this->_haserrorfunctions) {
593 $this->_errorMsg = ads_errormsg();
594 $this->_errorCode = ads_error();
596 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
612 function UpdateBlob($table,$column,$val,$where,$blobtype=
'BLOB')
614 $sql =
"UPDATE $table SET $column=? WHERE $where";
615 $stmtid = ads_prepare($this->_connectionID,
$sql);
616 if ($stmtid ==
false){
617 $this->_errorMsg = isset($php_errormsg) ? $php_errormsg :
'';
620 if (! ads_execute($stmtid,array($val),array(SQL_BINARY) )){
621 if ($this->_haserrorfunctions){
622 $this->_errorMsg = ads_errormsg();
623 $this->_errorCode = ads_error();
633 $ret = @ads_close($this->_connectionID);
634 $this->_connectionID =
false;
659 if ($mode ===
false) {
660 global $ADODB_FETCH_MODE;
661 $mode = $ADODB_FETCH_MODE;
663 $this->fetchMode = $mode;
665 $this->_queryID = $id;
669 $this->_currentRow = -1;
680 $o=
new ADOFieldObject();
681 $o->name = @ads_field_name($this->_queryID,$off);
682 $o->type = @ads_field_type($this->_queryID,$off);
683 $o->max_length = @ads_field_len($this->_queryID,$off);
684 if (ADODB_ASSOC_CASE == 0) $o->name = strtolower($o->name);
685 else if (ADODB_ASSOC_CASE == 1) $o->name = strtoupper($o->name);
692 if ($this->fetchMode & ADODB_FETCH_ASSOC)
return $this->fields[$colname];
694 $this->bind = array();
695 for ($i=0; $i < $this->_numOfFields; $i++) {
696 $o = $this->FetchField($i);
697 $this->bind[strtoupper($o->name)] = $i;
701 return $this->fields[$this->bind[strtoupper($colname)]];
707 global $ADODB_COUNTRECS;
708 $this->_numOfRows = ($ADODB_COUNTRECS) ? @ads_num_rows($this->_queryID) : -1;
709 $this->_numOfFields = @ads_num_fields($this->_queryID);
711 if ($this->_numOfRows == 0) $this->_numOfRows = -1;
713 $this->_has_stupid_odbc_fetch_api_change = ADODB_PHPVER >= 0x4200;
725 $rs =& $this->GetArray($nrows);
728 $savem = $this->fetchMode;
729 $this->fetchMode = ADODB_FETCH_NUM;
730 $this->Move($offset);
731 $this->fetchMode = $savem;
733 if ($this->fetchMode & ADODB_FETCH_ASSOC) {
734 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
739 while (!$this->EOF && $nrows != $cnt) {
740 $results[$cnt++] = $this->fields;
750 if ($this->_numOfRows != 0 && !$this->EOF) {
751 $this->_currentRow++;
752 if( $this->_fetch() ) {
756 $this->fields =
false;
763 $this->fields =
false;
764 if ($this->_has_stupid_odbc_fetch_api_change)
765 $rez = @ads_fetch_into($this->_queryID,$this->fields);
768 $rez = @ads_fetch_into($this->_queryID,$row,$this->fields);
771 if ($this->fetchMode & ADODB_FETCH_ASSOC) {
772 $this->fields =& $this->GetRowAssoc(ADODB_ASSOC_CASE);
781 return @ads_free_result($this->_queryID);
UpdateBlob($table, $column, $val, $where, $blobtype='BLOB')
if(isset($_REQUEST['nrows'])) else $rs
& MetaPrimaryKeys($table)
& MetaColumnNames($table)
_connect($argDSN, $argUsername, $argPassword, $argDatabasename)
$_has_stupid_odbc_fetch_api_change
& FetchField($fieldOffset=-1)
_query($sql, $inputarr=false)
CreateSequence( $seqname, $start=1)
ADORecordSet_ads($id, $mode=false)
$_has_stupid_odbc_fetch_api_change
& GetArrayLimit($nrows, $offset=-1)
_pconnect($argDSN, $argUsername, $argPassword, $argDatabasename)
GenID($seqname, $start=1)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)