Direct Messaging update: add CCR transmit, more meaningful attachment filenames
[openemr.git] / library / adodb / drivers / adodb-fbsql.inc.php
blobba6da84d268805633533e72c73bc50d15dbbb187
1 <?php
2 /*
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>.
8 Set tabs to 8.
9 */
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()
30 function _insertid()
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);
43 $arr = array();
44 $i = 0;
45 $max = fbsql_num_rows($qid);
46 while ($i < $max) {
47 $arr[] = fbsql_tablename($qid,$i);
48 $i += 1;
50 return $arr;
53 // returns concatenated string
54 function Concat()
56 $s = "";
57 $arr = func_get_args();
58 $first = true;
60 $s = implode(',',$arr);
61 if (sizeof($arr) > 0) return "CONCAT($s)";
62 else return '';
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);
71 return true;
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);
80 return true;
83 function MetaColumns($table, $normalize=true)
85 if ($this->metaColumnsSQL) {
87 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
89 if ($rs === false) return false;
91 $retarr = array();
92 while (!$rs->EOF){
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];
101 } else {
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;
110 $rs->MoveNext();
112 $rs->Close();
113 return $retarr;
115 return false;
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);
125 else return false;
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 */
136 function ErrorMsg()
138 $this->_errorMsg = @fbsql_error($this->_connectionID);
139 return $this->_errorMsg;
142 /* Returns: the last error number from previous database operation */
143 function ErrorNo()
145 return @fbsql_errno($this->_connectionID);
148 // returns true or false
149 function _close()
151 return @fbsql_close($this->_connectionID);
156 /*--------------------------------------------------------------------------------------
157 Class Name: Recordset
158 --------------------------------------------------------------------------------------*/
160 class ADORecordSet_fbsql extends ADORecordSet{
162 var $databaseType = "fbsql";
163 var $canSeek = true;
165 function ADORecordSet_fbsql($queryID,$mode=false)
167 if (!$mode) {
168 global $ADODB_FETCH_MODE;
169 $mode = $ADODB_FETCH_MODE;
171 switch ($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:
175 default:
176 $this->fetchMode = FBSQL_BOTH; break;
178 return $this->ADORecordSet($queryID);
181 function _initrs()
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;
202 return $o;
205 function _seek($row)
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);
216 function _close() {
217 return @fbsql_free_result($this->_queryID);
220 function MetaType($t,$len=-1,$fieldobj=false)
222 if (is_object($t)) {
223 $fieldobj = $t;
224 $t = $fieldobj->type;
225 $len = $fieldobj->max_length;
227 $len = -1; // fbsql max_length is not accurate
228 switch (strtoupper($t)) {
229 case 'CHARACTER':
230 case 'CHARACTER VARYING':
231 case 'BLOB':
232 case 'CLOB':
233 case 'BIT':
234 case 'BIT VARYING':
235 if ($len <= $this->blobSize) return 'C';
237 // so we have to check whether binary...
238 case 'IMAGE':
239 case 'LONGBLOB':
240 case 'BLOB':
241 case 'MEDIUMBLOB':
242 return !empty($fieldobj->binary) ? 'B' : 'X';
244 case 'DATE': return 'D';
246 case 'TIME':
247 case 'TIME WITH TIME ZONE':
248 case 'TIMESTAMP':
249 case 'TIMESTAMP WITH TIME ZONE': return 'T';
251 case 'PRIMARY_KEY':
252 return 'R';
253 case 'INTEGER':
254 case 'SMALLINT':
255 case 'BOOLEAN':
257 if (!empty($fieldobj->primary_key)) return 'R';
258 else return 'I';
260 default: return 'N';
264 } //class
265 } // defined