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