3 @version V5.14 8 Sept 2011 (c) 2000-2011 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 Contribution by Frank M. Kromann <frank@frontbase.com>.
11 // security - hide paths
12 if (!defined('ADODB_DIR')) die();
14 if (! defined("_ADODB_FBSQL_LAYER")) {
15 define("_ADODB_FBSQL_LAYER", 1 );
17 class ADODB_fbsql
extends ADOConnection
{
18 var $databaseType = 'fbsql';
19 var $hasInsertID = true;
20 var $hasAffectedRows = true;
21 var $metaTablesSQL = "SHOW TABLES";
22 var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
23 var $fmtTimeStamp = "'Y-m-d H:i:s'";
24 var $hasLimit = false;
26 function ADODB_fbsql()
32 return fbsql_insert_id($this->_connectionID
);
35 function _affectedrows()
37 return fbsql_affected_rows($this->_connectionID
);
40 function MetaDatabases()
42 $qid = fbsql_list_dbs($this->_connectionID
);
45 $max = fbsql_num_rows($qid);
47 $arr[] = fbsql_tablename($qid,$i);
53 // returns concatenated string
57 $arr = func_get_args();
60 $s = implode(',',$arr);
61 if (sizeof($arr) > 0) return "CONCAT($s)";
65 // returns true or false
66 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
68 $this->_connectionID
= fbsql_connect($argHostname,$argUsername,$argPassword);
69 if ($this->_connectionID
=== false) return false;
70 if ($argDatabasename) return $this->SelectDB($argDatabasename);
74 // returns true or false
75 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
77 $this->_connectionID
= fbsql_pconnect($argHostname,$argUsername,$argPassword);
78 if ($this->_connectionID
=== false) return false;
79 if ($argDatabasename) return $this->SelectDB($argDatabasename);
83 function MetaColumns($table, $normalize=true)
85 if ($this->metaColumnsSQL
) {
87 $rs = $this->Execute(sprintf($this->metaColumnsSQL
,$table));
89 if ($rs === false) return false;
93 $fld = new ADOFieldObject();
94 $fld->name
= $rs->fields
[0];
95 $fld->type
= $rs->fields
[1];
97 // split type into type(length):
98 if (preg_match("/^(.+)\((\d+)\)$/", $fld->type
, $query_array)) {
99 $fld->type
= $query_array[1];
100 $fld->max_length
= $query_array[2];
102 $fld->max_length
= -1;
104 $fld->not_null
= ($rs->fields
[2] != 'YES');
105 $fld->primary_key
= ($rs->fields
[3] == 'PRI');
106 $fld->auto_increment
= (strpos($rs->fields
[5], 'auto_increment') !== false);
107 $fld->binary
= (strpos($fld->type
,'blob') !== false);
109 $retarr[strtoupper($fld->name
)] = $fld;
118 // returns true or false
119 function SelectDB($dbName)
121 $this->database
= $dbName;
122 if ($this->_connectionID
) {
123 return @fbsql_select_db
($dbName,$this->_connectionID
);
129 // returns queryID or false
130 function _query($sql,$inputarr=false)
132 return fbsql_query("$sql;",$this->_connectionID
);
135 /* Returns: the last error message from previous database operation */
138 $this->_errorMsg
= @fbsql_error
($this->_connectionID
);
139 return $this->_errorMsg
;
142 /* Returns: the last error number from previous database operation */
145 return @fbsql_errno
($this->_connectionID
);
148 // returns true or false
151 return @fbsql_close
($this->_connectionID
);
156 /*--------------------------------------------------------------------------------------
157 Class Name: Recordset
158 --------------------------------------------------------------------------------------*/
160 class ADORecordSet_fbsql
extends ADORecordSet
{
162 var $databaseType = "fbsql";
165 function ADORecordSet_fbsql($queryID,$mode=false)
168 global $ADODB_FETCH_MODE;
169 $mode = $ADODB_FETCH_MODE;
172 case ADODB_FETCH_NUM
: $this->fetchMode
= FBSQL_NUM
; break;
173 case ADODB_FETCH_ASSOC
: $this->fetchMode
= FBSQL_ASSOC
; break;
174 case ADODB_FETCH_BOTH
:
176 $this->fetchMode
= FBSQL_BOTH
; break;
178 return $this->ADORecordSet($queryID);
183 GLOBAL $ADODB_COUNTRECS;
184 $this->_numOfRows
= ($ADODB_COUNTRECS) ? @fbsql_num_rows
($this->_queryID
):-1;
185 $this->_numOfFields
= @fbsql_num_fields
($this->_queryID
);
190 function FetchField($fieldOffset = -1) {
191 if ($fieldOffset != -1) {
192 $o = @fbsql_fetch_field
($this->_queryID
, $fieldOffset);
193 //$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable
194 $f = @fbsql_field_flags
($this->_queryID
,$fieldOffset);
195 $o->binary
= (strpos($f,'binary')!== false);
197 else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
198 $o = @fbsql_fetch_field
($this->_queryID
);// fbsql returns the max length less spaces -- so it is unrealiable
199 //$o->max_length = -1;
207 return @fbsql_data_seek
($this->_queryID
,$row);
210 function _fetch($ignore_fields=false)
212 $this->fields
= @fbsql_fetch_array
($this->_queryID
,$this->fetchMode
);
213 return ($this->fields
== true);
217 return @fbsql_free_result
($this->_queryID
);
220 function MetaType($t,$len=-1,$fieldobj=false)
224 $t = $fieldobj->type
;
225 $len = $fieldobj->max_length
;
227 $len = -1; // fbsql max_length is not accurate
228 switch (strtoupper($t)) {
230 case 'CHARACTER VARYING':
235 if ($len <= $this->blobSize
) return 'C';
237 // so we have to check whether binary...
242 return !empty($fieldobj->binary
) ?
'B' : 'X';
244 case 'DATE': return 'D';
247 case 'TIME WITH TIME ZONE':
249 case 'TIMESTAMP WITH TIME ZONE': return 'T';
257 if (!empty($fieldobj->primary_key
)) return 'R';