modified: messages.php
[openemr.git] / library / adodb / drivers / adodb-fbsql.inc.php
blob4221070cd2e046e2601cad977c1e961557967ec4
1 <?php
2 /*
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>.
8 Set tabs to 8.
9 */
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()
27 function _insertid()
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);
40 $arr = array();
41 $i = 0;
42 $max = fbsql_num_rows($qid);
43 while ($i < $max) {
44 $arr[] = fbsql_tablename($qid,$i);
45 $i += 1;
47 return $arr;
50 // returns concatenated string
51 function Concat()
53 $s = "";
54 $arr = func_get_args();
55 $first = true;
57 $s = implode(',',$arr);
58 if (sizeof($arr) > 0) return "CONCAT($s)";
59 else return '';
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);
68 return true;
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);
77 return true;
80 function &MetaColumns($table)
82 if ($this->metaColumnsSQL) {
84 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
86 if ($rs === false) return false;
88 $retarr = array();
89 while (!$rs->EOF){
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];
98 } else {
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;
107 $rs->MoveNext();
109 $rs->Close();
110 return $retarr;
112 return false;
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);
122 else return false;
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 */
133 function ErrorMsg()
135 $this->_errorMsg = @fbsql_error($this->_connectionID);
136 return $this->_errorMsg;
139 /* Returns: the last error number from previous database operation */
140 function ErrorNo()
142 return @fbsql_errno($this->_connectionID);
145 // returns true or false
146 function _close()
148 return @fbsql_close($this->_connectionID);
153 /*--------------------------------------------------------------------------------------
154 Class Name: Recordset
155 --------------------------------------------------------------------------------------*/
157 class ADORecordSet_fbsql extends ADORecordSet{
159 var $databaseType = "fbsql";
160 var $canSeek = true;
162 function ADORecordSet_fbsql($queryID,$mode=false)
164 if (!$mode) {
165 global $ADODB_FETCH_MODE;
166 $mode = $ADODB_FETCH_MODE;
168 switch ($mode) {
169 case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;
170 default:
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);
177 function _initrs()
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;
198 return $o;
201 function _seek($row)
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);
212 function _close() {
213 return @fbsql_free_result($this->_queryID);
216 function MetaType($t,$len=-1,$fieldobj=false)
218 if (is_object($t)) {
219 $fieldobj = $t;
220 $t = $fieldobj->type;
221 $len = $fieldobj->max_length;
223 $len = -1; // fbsql max_length is not accurate
224 switch (strtoupper($t)) {
225 case 'CHARACTER':
226 case 'CHARACTER VARYING':
227 case 'BLOB':
228 case 'CLOB':
229 case 'BIT':
230 case 'BIT VARYING':
231 if ($len <= $this->blobSize) return 'C';
233 // so we have to check whether binary...
234 case 'IMAGE':
235 case 'LONGBLOB':
236 case 'BLOB':
237 case 'MEDIUMBLOB':
238 return !empty($fieldobj->binary) ? 'B' : 'X';
240 case 'DATE': return 'D';
242 case 'TIME':
243 case 'TIME WITH TIME ZONE':
244 case 'TIMESTAMP':
245 case 'TIMESTAMP WITH TIME ZONE': return 'T';
247 case 'PRIMARY_KEY':
248 return 'R';
249 case 'INTEGER':
250 case 'SMALLINT':
251 case 'BOOLEAN':
253 if (!empty($fieldobj->primary_key)) return 'R';
254 else return 'I';
256 default: return 'N';
260 } //class
261 } // defined