c054a9ec539efd8c3405623b5b9cb646db18d8ee
[Packages/TYPO3.CMS.git] / typo3 / sysext / adodb / adodb / drivers / adodb-fbsql.inc.php
1 <?php
2 /*
3 @version V4.81 3 May 2006 (c) 2000-2006 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 */
10
11 // security - hide paths
12 if (!defined('ADODB_DIR')) die();
13
14 if (! defined("_ADODB_FBSQL_LAYER")) {
15 define("_ADODB_FBSQL_LAYER", 1 );
16
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;
25
26 function ADODB_fbsql()
27 {
28 }
29
30 function _insertid()
31 {
32 return fbsql_insert_id($this->_connectionID);
33 }
34
35 function _affectedrows()
36 {
37 return fbsql_affected_rows($this->_connectionID);
38 }
39
40 function &MetaDatabases()
41 {
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;
49 }
50 return $arr;
51 }
52
53 // returns concatenated string
54 function Concat()
55 {
56 $s = "";
57 $arr = func_get_args();
58 $first = true;
59
60 $s = implode(',',$arr);
61 if (sizeof($arr) > 0) return "CONCAT($s)";
62 else return '';
63 }
64
65 // returns true or false
66 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
67 {
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;
72 }
73
74 // returns true or false
75 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
76 {
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;
81 }
82
83 function &MetaColumns($table)
84 {
85 if ($this->metaColumnsSQL) {
86
87 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
88
89 if ($rs === false) return false;
90
91 $retarr = array();
92 while (!$rs->EOF){
93 $fld = new ADOFieldObject();
94 $fld->name = $rs->fields[0];
95 $fld->type = $rs->fields[1];
96
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;
103 }
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);
108
109 $retarr[strtoupper($fld->name)] = $fld;
110 $rs->MoveNext();
111 }
112 $rs->Close();
113 return $retarr;
114 }
115 return false;
116 }
117
118 // returns true or false
119 function SelectDB($dbName)
120 {
121 $this->database = $dbName;
122 if ($this->_connectionID) {
123 return @fbsql_select_db($dbName,$this->_connectionID);
124 }
125 else return false;
126 }
127
128
129 // returns queryID or false
130 function _query($sql,$inputarr)
131 {
132 return fbsql_query("$sql;",$this->_connectionID);
133 }
134
135 /* Returns: the last error message from previous database operation */
136 function ErrorMsg()
137 {
138 $this->_errorMsg = @fbsql_error($this->_connectionID);
139 return $this->_errorMsg;
140 }
141
142 /* Returns: the last error number from previous database operation */
143 function ErrorNo()
144 {
145 return @fbsql_errno($this->_connectionID);
146 }
147
148 // returns true or false
149 function _close()
150 {
151 return @fbsql_close($this->_connectionID);
152 }
153
154 }
155
156 /*--------------------------------------------------------------------------------------
157 Class Name: Recordset
158 --------------------------------------------------------------------------------------*/
159
160 class ADORecordSet_fbsql extends ADORecordSet{
161
162 var $databaseType = "fbsql";
163 var $canSeek = true;
164
165 function ADORecordSet_fbsql($queryID,$mode=false)
166 {
167 if (!$mode) {
168 global $ADODB_FETCH_MODE;
169 $mode = $ADODB_FETCH_MODE;
170 }
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;
177 }
178 return $this->ADORecordSet($queryID);
179 }
180
181 function _initrs()
182 {
183 GLOBAL $ADODB_COUNTRECS;
184 $this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1;
185 $this->_numOfFields = @fbsql_num_fields($this->_queryID);
186 }
187
188
189
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);
196 }
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;
200 }
201
202 return $o;
203 }
204
205 function _seek($row)
206 {
207 return @fbsql_data_seek($this->_queryID,$row);
208 }
209
210 function _fetch($ignore_fields=false)
211 {
212 $this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode);
213 return ($this->fields == true);
214 }
215
216 function _close() {
217 return @fbsql_free_result($this->_queryID);
218 }
219
220 function MetaType($t,$len=-1,$fieldobj=false)
221 {
222 if (is_object($t)) {
223 $fieldobj = $t;
224 $t = $fieldobj->type;
225 $len = $fieldobj->max_length;
226 }
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';
236
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';
243
244 case 'DATE': return 'D';
245
246 case 'TIME':
247 case 'TIME WITH TIME ZONE':
248 case 'TIMESTAMP':
249 case 'TIMESTAMP WITH TIME ZONE': return 'T';
250
251 case 'PRIMARY_KEY':
252 return 'R';
253 case 'INTEGER':
254 case 'SMALLINT':
255 case 'BOOLEAN':
256
257 if (!empty($fieldobj->primary_key)) return 'R';
258 else return 'I';
259
260 default: return 'N';
261 }
262 }
263
264 } //class
265 } // defined
266 ?>