Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  /*
   3   @version   v5.21.0  2021-02-27
   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 _insertid()
  29  	 {
  30  	 	 	 return fbsql_insert_id($this->_connectionID);
  31  	 }
  32  
  33  	function _affectedrows()
  34  	 {
  35  	 	 	 return fbsql_affected_rows($this->_connectionID);
  36  	 }
  37  
  38    	function MetaDatabases()
  39  	 {
  40  	 	 $qid = fbsql_list_dbs($this->_connectionID);
  41  	 	 $arr = array();
  42  	 	 $i = 0;
  43  	 	 $max = fbsql_num_rows($qid);
  44  	 	 while ($i < $max) {
  45  	 	 	 $arr[] = fbsql_tablename($qid,$i);
  46  	 	 	 $i += 1;
  47  	 	 }
  48  	 	 return $arr;
  49  	 }
  50  
  51  	 // returns concatenated string
  52  	function Concat()
  53  	 {
  54  	 	 $s = "";
  55  	 	 $arr = func_get_args();
  56  	 	 $first = true;
  57  
  58  	 	 $s = implode(',',$arr);
  59  	 	 if (sizeof($arr) > 0) return "CONCAT($s)";
  60  	 	 else return '';
  61  	 }
  62  
  63  	 // returns true or false
  64  	function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
  65  	 {
  66  	 	 $this->_connectionID = fbsql_connect($argHostname,$argUsername,$argPassword);
  67  	 	 if ($this->_connectionID === false) return false;
  68  	 	 if ($argDatabasename) return $this->SelectDB($argDatabasename);
  69  	 	 return true;
  70  	 }
  71  
  72  	 // returns true or false
  73  	function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  74  	 {
  75  	 	 $this->_connectionID = fbsql_pconnect($argHostname,$argUsername,$argPassword);
  76  	 	 if ($this->_connectionID === false) return false;
  77  	 	 if ($argDatabasename) return $this->SelectDB($argDatabasename);
  78  	 	 return true;
  79  	 }
  80  
  81   	function MetaColumns($table, $normalize=true)
  82  	 {
  83  	 	 if ($this->metaColumnsSQL) {
  84  
  85  	 	 	 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
  86  
  87  	 	 	 if ($rs === false) return false;
  88  
  89  	 	 	 $retarr = array();
  90  	 	 	 while (!$rs->EOF){
  91  	 	 	 	 $fld = new ADOFieldObject();
  92  	 	 	 	 $fld->name = $rs->fields[0];
  93  	 	 	 	 $fld->type = $rs->fields[1];
  94  
  95  	 	 	 	 // split type into type(length):
  96  	 	 	 	 if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) {
  97  	 	 	 	 	 $fld->type = $query_array[1];
  98  	 	 	 	 	 $fld->max_length = $query_array[2];
  99  	 	 	 	 } else {
 100  	 	 	 	 	 $fld->max_length = -1;
 101  	 	 	 	 }
 102  	 	 	 	 $fld->not_null = ($rs->fields[2] != 'YES');
 103  	 	 	 	 $fld->primary_key = ($rs->fields[3] == 'PRI');
 104  	 	 	 	 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
 105  	 	 	 	 $fld->binary = (strpos($fld->type,'blob') !== false);
 106  
 107  	 	 	 	 $retarr[strtoupper($fld->name)] = $fld;
 108  	 	 	 	 $rs->MoveNext();
 109  	 	 	 }
 110  	 	 	 $rs->Close();
 111  	 	 	 return $retarr;
 112  	 	 }
 113  	 	 return false;
 114  	 }
 115  
 116  	 // returns true or false
 117  	function SelectDB($dbName)
 118  	 {
 119  	 	 $this->database = $dbName;
 120  	 	 if ($this->_connectionID) {
 121  	 	 	 return @fbsql_select_db($dbName,$this->_connectionID);
 122  	 	 }
 123  	 	 else return false;
 124  	 }
 125  
 126  
 127  	 // returns queryID or false
 128  	function _query($sql,$inputarr=false)
 129  	 {
 130  	 	 return fbsql_query("$sql;",$this->_connectionID);
 131  	 }
 132  
 133  	 /*	 Returns: the last error message from previous database operation	 */
 134  	function ErrorMsg()
 135  	 {
 136  	 	 $this->_errorMsg = @fbsql_error($this->_connectionID);
 137  	 	 	 return $this->_errorMsg;
 138  	 }
 139  
 140  	 /*	 Returns: the last error number from previous database operation	 */
 141  	function ErrorNo()
 142  	 {
 143  	 	 return @fbsql_errno($this->_connectionID);
 144  	 }
 145  
 146  	 // returns true or false
 147  	function _close()
 148  	 {
 149  	 	 return @fbsql_close($this->_connectionID);
 150  	 }
 151  
 152  }
 153  
 154  /*--------------------------------------------------------------------------------------
 155  	  Class Name: Recordset
 156  --------------------------------------------------------------------------------------*/
 157  
 158  class ADORecordSet_fbsql extends ADORecordSet{
 159  
 160  	 var $databaseType = "fbsql";
 161  	 var $canSeek = true;
 162  
 163  	function __construct($queryID,$mode=false)
 164  	 {
 165  	 	 if (!$mode) {
 166  	 	 	 global $ADODB_FETCH_MODE;
 167  	 	 	 $mode = $ADODB_FETCH_MODE;
 168  	 	 }
 169  	 	 switch ($mode) {
 170  	 	 case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break;
 171  	 	 case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break;
 172  	 	 case ADODB_FETCH_BOTH:
 173  	 	 default:
 174  	 	 $this->fetchMode = FBSQL_BOTH; break;
 175  	 	 }
 176  	 	 parent::__construct($queryID);
 177  	 }
 178  
 179  	function _initrs()
 180  	 {
 181  	 GLOBAL $ADODB_COUNTRECS;
 182  	 	 $this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1;
 183  	 	 $this->_numOfFields = @fbsql_num_fields($this->_queryID);
 184  	 }
 185  
 186  
 187  
 188  	function FetchField($fieldOffset = -1) {
 189  	 	 if ($fieldOffset != -1) {
 190  	 	 	 $o =  @fbsql_fetch_field($this->_queryID, $fieldOffset);
 191  	 	 	 //$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable
 192  	 	 	 $f = @fbsql_field_flags($this->_queryID,$fieldOffset);
 193  	 	 	 $o->binary = (strpos($f,'binary')!== false);
 194  	 	 }
 195  	 	 else if ($fieldOffset == -1) {	 /*	 The $fieldOffset argument is not provided thus its -1 	 */
 196  	 	 	 $o = @fbsql_fetch_field($this->_queryID);// fbsql returns the max length less spaces -- so it is unrealiable
 197  	 	 	 //$o->max_length = -1;
 198  	 	 }
 199  
 200  	 	 return $o;
 201  	 }
 202  
 203  	function _seek($row)
 204  	 {
 205  	 	 return @fbsql_data_seek($this->_queryID,$row);
 206  	 }
 207  
 208  	function _fetch($ignore_fields=false)
 209  	 {
 210  	 	 $this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode);
 211  	 	 return ($this->fields == true);
 212  	 }
 213  
 214  	function _close() {
 215  	 	 return @fbsql_free_result($this->_queryID);
 216  	 }
 217  
 218  	function MetaType($t,$len=-1,$fieldobj=false)
 219  	 {
 220  	 	 if (is_object($t)) {
 221  	 	 	 $fieldobj = $t;
 222  	 	 	 $t = $fieldobj->type;
 223  	 	 	 $len = $fieldobj->max_length;
 224  	 	 }
 225  	 	 $len = -1; // fbsql max_length is not accurate
 226  	 	 switch (strtoupper($t)) {
 227  	 	 case 'CHARACTER':
 228  	 	 case 'CHARACTER VARYING':
 229  	 	 case 'BLOB':
 230  	 	 case 'CLOB':
 231  	 	 case 'BIT':
 232  	 	 case 'BIT VARYING':
 233  	 	 	 if ($len <= $this->blobSize) return 'C';
 234  
 235  	 	 // so we have to check whether binary...
 236  	 	 case 'IMAGE':
 237  	 	 case 'LONGBLOB':
 238  	 	 case 'BLOB':
 239  	 	 case 'MEDIUMBLOB':
 240  	 	 	 return !empty($fieldobj->binary) ? 'B' : 'X';
 241  
 242  	 	 case 'DATE': return 'D';
 243  
 244  	 	 case 'TIME':
 245  	 	 case 'TIME WITH TIME ZONE':
 246  	 	 case 'TIMESTAMP':
 247  	 	 case 'TIMESTAMP WITH TIME ZONE': return 'T';
 248  
 249  	 	 case 'PRIMARY_KEY':
 250  	 	 	 return 'R';
 251  	 	 case 'INTEGER':
 252  	 	 case 'SMALLINT':
 253  	 	 case 'BOOLEAN':
 254  
 255  	 	 	 if (!empty($fieldobj->primary_key)) return 'R';
 256  	 	 	 else return 'I';
 257  
 258  	 	 default: return ADODB_DEFAULT_METATYPE;
 259  	 	 }
 260  	 }
 261  
 262  } //class
 263  } // defined