1 |
efrain |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Frontbase driver.
|
|
|
4 |
*
|
|
|
5 |
* This file is part of ADOdb, a Database Abstraction Layer library for PHP.
|
|
|
6 |
*
|
|
|
7 |
* @package ADOdb
|
|
|
8 |
* @link https://adodb.org Project's web site and documentation
|
|
|
9 |
* @link https://github.com/ADOdb/ADOdb Source code and issue tracker
|
|
|
10 |
*
|
|
|
11 |
* The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
|
|
|
12 |
* and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
|
|
|
13 |
* any later version. This means you can use it in proprietary products.
|
|
|
14 |
* See the LICENSE.md file distributed with this source code for details.
|
|
|
15 |
* @license BSD-3-Clause
|
|
|
16 |
* @license LGPL-2.1-or-later
|
|
|
17 |
*
|
|
|
18 |
* @copyright 2000-2013 John Lim
|
|
|
19 |
* @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
|
|
|
20 |
* @author Frank M. Kromann <frank@frontbase.com>
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
// security - hide paths
|
|
|
24 |
if (!defined('ADODB_DIR')) die();
|
|
|
25 |
|
|
|
26 |
if (! defined("_ADODB_FBSQL_LAYER")) {
|
|
|
27 |
define("_ADODB_FBSQL_LAYER", 1 );
|
|
|
28 |
|
|
|
29 |
class ADODB_fbsql extends ADOConnection {
|
|
|
30 |
var $databaseType = 'fbsql';
|
|
|
31 |
var $hasInsertID = true;
|
|
|
32 |
var $hasAffectedRows = true;
|
|
|
33 |
var $metaTablesSQL = "SHOW TABLES";
|
|
|
34 |
var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
|
|
|
35 |
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
|
|
36 |
var $hasLimit = false;
|
|
|
37 |
|
|
|
38 |
protected function _insertID($table = '', $column = '')
|
|
|
39 |
{
|
|
|
40 |
return fbsql_insert_id($this->_connectionID);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
function _affectedrows()
|
|
|
44 |
{
|
|
|
45 |
return fbsql_affected_rows($this->_connectionID);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
function MetaDatabases()
|
|
|
49 |
{
|
|
|
50 |
$qid = fbsql_list_dbs($this->_connectionID);
|
|
|
51 |
$arr = array();
|
|
|
52 |
$i = 0;
|
|
|
53 |
$max = fbsql_num_rows($qid);
|
|
|
54 |
while ($i < $max) {
|
|
|
55 |
$arr[] = fbsql_tablename($qid,$i);
|
|
|
56 |
$i += 1;
|
|
|
57 |
}
|
|
|
58 |
return $arr;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// returns concatenated string
|
|
|
62 |
function Concat()
|
|
|
63 |
{
|
|
|
64 |
$s = "";
|
|
|
65 |
$arr = func_get_args();
|
|
|
66 |
$first = true;
|
|
|
67 |
|
|
|
68 |
$s = implode(',',$arr);
|
|
|
69 |
if (sizeof($arr) > 0) return "CONCAT($s)";
|
|
|
70 |
else return '';
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
// returns true or false
|
|
|
74 |
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
|
|
75 |
{
|
|
|
76 |
$this->_connectionID = fbsql_connect($argHostname,$argUsername,$argPassword);
|
|
|
77 |
if ($this->_connectionID === false) return false;
|
|
|
78 |
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
|
|
79 |
return true;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
// returns true or false
|
|
|
83 |
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
|
|
84 |
{
|
|
|
85 |
$this->_connectionID = fbsql_pconnect($argHostname,$argUsername,$argPassword);
|
|
|
86 |
if ($this->_connectionID === false) return false;
|
|
|
87 |
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
|
|
88 |
return true;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
function MetaColumns($table, $normalize=true)
|
|
|
92 |
{
|
|
|
93 |
if ($this->metaColumnsSQL) {
|
|
|
94 |
|
|
|
95 |
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
|
|
|
96 |
|
|
|
97 |
if ($rs === false) return false;
|
|
|
98 |
|
|
|
99 |
$retarr = array();
|
|
|
100 |
while (!$rs->EOF){
|
|
|
101 |
$fld = new ADOFieldObject();
|
|
|
102 |
$fld->name = $rs->fields[0];
|
|
|
103 |
$fld->type = $rs->fields[1];
|
|
|
104 |
|
|
|
105 |
// split type into type(length):
|
|
|
106 |
if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) {
|
|
|
107 |
$fld->type = $query_array[1];
|
|
|
108 |
$fld->max_length = $query_array[2];
|
|
|
109 |
} else {
|
|
|
110 |
$fld->max_length = -1;
|
|
|
111 |
}
|
|
|
112 |
$fld->not_null = ($rs->fields[2] != 'YES');
|
|
|
113 |
$fld->primary_key = ($rs->fields[3] == 'PRI');
|
|
|
114 |
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
|
|
|
115 |
$fld->binary = (strpos($fld->type,'blob') !== false);
|
|
|
116 |
|
|
|
117 |
$retarr[strtoupper($fld->name)] = $fld;
|
|
|
118 |
$rs->MoveNext();
|
|
|
119 |
}
|
|
|
120 |
$rs->Close();
|
|
|
121 |
return $retarr;
|
|
|
122 |
}
|
|
|
123 |
return false;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
// returns true or false
|
|
|
127 |
function SelectDB($dbName)
|
|
|
128 |
{
|
|
|
129 |
$this->database = $dbName;
|
|
|
130 |
if ($this->_connectionID) {
|
|
|
131 |
return @fbsql_select_db($dbName,$this->_connectionID);
|
|
|
132 |
}
|
|
|
133 |
else return false;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
function _query($sql,$inputarr=false)
|
|
|
138 |
{
|
|
|
139 |
return fbsql_query("$sql;",$this->_connectionID);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
/* Returns: the last error message from previous database operation */
|
|
|
143 |
function ErrorMsg()
|
|
|
144 |
{
|
|
|
145 |
$this->_errorMsg = @fbsql_error($this->_connectionID);
|
|
|
146 |
return $this->_errorMsg;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/* Returns: the last error number from previous database operation */
|
|
|
150 |
function ErrorNo()
|
|
|
151 |
{
|
|
|
152 |
return @fbsql_errno($this->_connectionID);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
// returns true or false
|
|
|
156 |
function _close()
|
|
|
157 |
{
|
|
|
158 |
return @fbsql_close($this->_connectionID);
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/*--------------------------------------------------------------------------------------
|
|
|
164 |
Class Name: Recordset
|
|
|
165 |
--------------------------------------------------------------------------------------*/
|
|
|
166 |
|
|
|
167 |
class ADORecordSet_fbsql extends ADORecordSet{
|
|
|
168 |
|
|
|
169 |
var $databaseType = "fbsql";
|
|
|
170 |
var $canSeek = true;
|
|
|
171 |
|
|
|
172 |
function __construct($queryID,$mode=false)
|
|
|
173 |
{
|
|
|
174 |
if (!$mode) {
|
|
|
175 |
global $ADODB_FETCH_MODE;
|
|
|
176 |
$mode = $ADODB_FETCH_MODE;
|
|
|
177 |
}
|
|
|
178 |
switch ($mode) {
|
|
|
179 |
case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;
|
|
|
180 |
case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break;
|
|
|
181 |
case ADODB_FETCH_BOTH:
|
|
|
182 |
default:
|
|
|
183 |
$this->fetchMode = FBSQL_BOTH; break;
|
|
|
184 |
}
|
|
|
185 |
parent::__construct($queryID);
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
function _initrs()
|
|
|
189 |
{
|
|
|
190 |
GLOBAL $ADODB_COUNTRECS;
|
|
|
191 |
$this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1;
|
|
|
192 |
$this->_numOfFields = @fbsql_num_fields($this->_queryID);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
function FetchField($fieldOffset = -1) {
|
|
|
198 |
if ($fieldOffset != -1) {
|
|
|
199 |
$o = @fbsql_fetch_field($this->_queryID, $fieldOffset);
|
|
|
200 |
//$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable
|
|
|
201 |
$f = @fbsql_field_flags($this->_queryID,$fieldOffset);
|
|
|
202 |
$o->binary = (strpos($f,'binary')!== false);
|
|
|
203 |
}
|
|
|
204 |
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
|
|
205 |
$o = @fbsql_fetch_field($this->_queryID);// fbsql returns the max length less spaces -- so it is unrealiable
|
|
|
206 |
//$o->max_length = -1;
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
return $o;
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
function _seek($row)
|
|
|
213 |
{
|
|
|
214 |
return @fbsql_data_seek($this->_queryID,$row);
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
function _fetch($ignore_fields=false)
|
|
|
218 |
{
|
|
|
219 |
$this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode);
|
|
|
220 |
return ($this->fields == true);
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
function _close() {
|
|
|
224 |
return @fbsql_free_result($this->_queryID);
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
function MetaType($t,$len=-1,$fieldobj=false)
|
|
|
228 |
{
|
|
|
229 |
if (is_object($t)) {
|
|
|
230 |
$fieldobj = $t;
|
|
|
231 |
$t = $fieldobj->type;
|
|
|
232 |
$len = $fieldobj->max_length;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
$t = strtoupper($t);
|
|
|
236 |
|
|
|
237 |
if (array_key_exists($t,$this->connection->customActualTypes))
|
|
|
238 |
return $this->connection->customActualTypes[$t];
|
|
|
239 |
|
|
|
240 |
$len = -1; // fbsql max_length is not accurate
|
|
|
241 |
|
|
|
242 |
switch ($t) {
|
|
|
243 |
case 'CHARACTER':
|
|
|
244 |
case 'CHARACTER VARYING':
|
|
|
245 |
case 'BLOB':
|
|
|
246 |
case 'CLOB':
|
|
|
247 |
case 'BIT':
|
|
|
248 |
case 'BIT VARYING':
|
|
|
249 |
if ($len <= $this->blobSize) return 'C';
|
|
|
250 |
|
|
|
251 |
// so we have to check whether binary...
|
|
|
252 |
case 'IMAGE':
|
|
|
253 |
case 'LONGBLOB':
|
|
|
254 |
case 'BLOB':
|
|
|
255 |
case 'MEDIUMBLOB':
|
|
|
256 |
return !empty($fieldobj->binary) ? 'B' : 'X';
|
|
|
257 |
|
|
|
258 |
case 'DATE': return 'D';
|
|
|
259 |
|
|
|
260 |
case 'TIME':
|
|
|
261 |
case 'TIME WITH TIME ZONE':
|
|
|
262 |
case 'TIMESTAMP':
|
|
|
263 |
case 'TIMESTAMP WITH TIME ZONE': return 'T';
|
|
|
264 |
|
|
|
265 |
case 'PRIMARY_KEY':
|
|
|
266 |
return 'R';
|
|
|
267 |
case 'INTEGER':
|
|
|
268 |
case 'SMALLINT':
|
|
|
269 |
case 'BOOLEAN':
|
|
|
270 |
|
|
|
271 |
if (!empty($fieldobj->primary_key)) return 'R';
|
|
|
272 |
else return 'I';
|
|
|
273 |
|
|
|
274 |
default: return ADODB_DEFAULT_METATYPE;
|
|
|
275 |
}
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
} //class
|
|
|
279 |
} // defined
|