3 @version V4.20 22 Feb 2004 (c) 2000-2004 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.
7 Contribution by Frank M. Kromann <frank@frontbase.com>.
11 if (! defined("_ADODB_FBSQL_LAYER")) {
12 define("_ADODB_FBSQL_LAYER", 1 );
14 class ADODB_fbsql
extends ADOConnection
{
15 var $databaseType = 'fbsql';
16 var $hasInsertID = true;
17 var $hasAffectedRows = true;
18 var $metaTablesSQL = "SHOW TABLES";
19 var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
20 var $fmtTimeStamp = "'Y-m-d H:i:s'";
21 var $hasLimit = false;
23 function ADODB_fbsql()
29 return fbsql_insert_id($this->_connectionID
);
32 function _affectedrows()
34 return fbsql_affected_rows($this->_connectionID
);
37 function &MetaDatabases()
39 $qid = fbsql_list_dbs($this->_connectionID
);
42 $max = fbsql_num_rows($qid);
44 $arr[] = fbsql_tablename($qid,$i);
50 // returns concatenated string
54 $arr = func_get_args();
57 $s = implode(',',$arr);
58 if (sizeof($arr) > 0) return "CONCAT($s)";
62 // returns true or false
63 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
65 $this->_connectionID
= fbsql_connect($argHostname,$argUsername,$argPassword);
66 if ($this->_connectionID
=== false) return false;
67 if ($argDatabasename) return $this->SelectDB($argDatabasename);
71 // returns true or false
72 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
74 $this->_connectionID
= fbsql_pconnect($argHostname,$argUsername,$argPassword);
75 if ($this->_connectionID
=== false) return false;
76 if ($argDatabasename) return $this->SelectDB($argDatabasename);
80 function &MetaColumns($table)
82 if ($this->metaColumnsSQL
) {
84 $rs = $this->Execute(sprintf($this->metaColumnsSQL
,$table));
86 if ($rs === false) return false;
90 $fld = new ADOFieldObject();
91 $fld->name
= $rs->fields
[0];
92 $fld->type
= $rs->fields
[1];
94 // split type into type(length):
95 if (preg_match("/^(.+)\((\d+)\)$/", $fld->type
, $query_array)) {
96 $fld->type
= $query_array[1];
97 $fld->max_length
= $query_array[2];
99 $fld->max_length
= -1;
101 $fld->not_null
= ($rs->fields
[2] != 'YES');
102 $fld->primary_key
= ($rs->fields
[3] == 'PRI');
103 $fld->auto_increment
= (strpos($rs->fields
[5], 'auto_increment') !== false);
104 $fld->binary
= (strpos($fld->type
,'blob') !== false);
106 $retarr[strtoupper($fld->name
)] = $fld;
115 // returns true or false
116 function SelectDB($dbName)
118 $this->databaseName
= $dbName;
119 if ($this->_connectionID
) {
120 return @fbsql_select_db
($dbName,$this->_connectionID
);
126 // returns queryID or false
127 function _query($sql,$inputarr)
129 return fbsql_query("$sql;",$this->_connectionID
);
132 /* Returns: the last error message from previous database operation */
135 $this->_errorMsg
= @fbsql_error
($this->_connectionID
);
136 return $this->_errorMsg
;
139 /* Returns: the last error number from previous database operation */
142 return @fbsql_errno
($this->_connectionID
);
145 // returns true or false
148 return @fbsql_close
($this->_connectionID
);
153 /*--------------------------------------------------------------------------------------
154 Class Name: Recordset
155 --------------------------------------------------------------------------------------*/
157 class ADORecordSet_fbsql
extends ADORecordSet
{
159 var $databaseType = "fbsql";
162 function ADORecordSet_fbsql($queryID,$mode=false)
165 global $ADODB_FETCH_MODE;
166 $mode = $ADODB_FETCH_MODE;
169 case ADODB_FETCH_NUM
: $this->fetchMode
= FBSQL_NUM
; break;
171 case ADODB_FETCH_BOTH
: $this->fetchMode
= FBSQL_BOTH
; break;
172 case ADODB_FETCH_ASSOC
: $this->fetchMode
= FBSQL_ASSOC
; break;
174 return $this->ADORecordSet($queryID);
179 GLOBAL $ADODB_COUNTRECS;
180 $this->_numOfRows
= ($ADODB_COUNTRECS) ? @fbsql_num_rows
($this->_queryID
):-1;
181 $this->_numOfFields
= @fbsql_num_fields
($this->_queryID
);
186 function &FetchField($fieldOffset = -1) {
187 if ($fieldOffset != -1) {
188 $o = @fbsql_fetch_field
($this->_queryID
, $fieldOffset);
189 //$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable
190 $f = @fbsql_field_flags
($this->_queryID
,$fieldOffset);
191 $o->binary
= (strpos($f,'binary')!== false);
193 else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
194 $o = @fbsql_fetch_field
($this->_queryID
);// fbsql returns the max length less spaces -- so it is unrealiable
195 //$o->max_length = -1;
203 return @fbsql_data_seek
($this->_queryID
,$row);
206 function _fetch($ignore_fields=false)
208 $this->fields
= @fbsql_fetch_array
($this->_queryID
,$this->fetchMode
);
209 return ($this->fields
== true);
213 return @fbsql_free_result
($this->_queryID
);
216 function MetaType($t,$len=-1,$fieldobj=false)
220 $t = $fieldobj->type
;
221 $len = $fieldobj->max_length
;
223 $len = -1; // fbsql max_length is not accurate
224 switch (strtoupper($t)) {
226 case 'CHARACTER VARYING':
231 if ($len <= $this->blobSize
) return 'C';
233 // so we have to check whether binary...
238 return !empty($fieldobj->binary
) ?
'B' : 'X';
240 case 'DATE': return 'D';
243 case 'TIME WITH TIME ZONE':
245 case 'TIMESTAMP WITH TIME ZONE': return 'T';
253 if (!empty($fieldobj->primary_key
)) return 'R';