Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   1  <?php
   2  
   3  /**
   4    @version   v5.20.16  12-Jan-2020
   5    @copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved.
   6    @copyright (c) 2014      Damien Regad, Mark Newnham and the ADOdb community
   7    Released under both BSD license and Lesser GPL library license.
   8    Whenever there is any discrepancy between the two licenses,
   9    the BSD license will take precedence.
  10  
  11    Set tabs to 4 for best viewing.
  12  
  13  */
  14  
  15  class ADODB2_firebird extends ADODB_DataDict {
  16  
  17  	 var $databaseType = 'firebird';
  18  	 var $seqField = false;
  19  	 var $seqPrefix = 'gen_';
  20  	 var $blobSize = 40000;
  21  
  22   	function ActualType($meta)
  23  	 {
  24  	 	 switch($meta) {
  25  	 	 case 'C': return 'VARCHAR';
  26  	 	 case 'XL': return 'VARCHAR(32000)';
  27  	 	 case 'X': return 'VARCHAR(4000)';
  28  
  29  	 	 case 'C2': return 'VARCHAR'; // up to 32K
  30  	 	 case 'X2': return 'VARCHAR(4000)';
  31  
  32  	 	 case 'B': return 'BLOB';
  33  
  34  	 	 case 'D': return 'DATE';
  35  	 	 case 'TS':
  36  	 	 case 'T': return 'TIMESTAMP';
  37  
  38  	 	 case 'L': return 'SMALLINT';
  39  	 	 case 'I': return 'INTEGER';
  40  	 	 case 'I1': return 'SMALLINT';
  41  	 	 case 'I2': return 'SMALLINT';
  42  	 	 case 'I4': return 'INTEGER';
  43  	 	 case 'I8': return 'INTEGER';
  44  
  45  	 	 case 'F': return 'DOUBLE PRECISION';
  46  	 	 case 'N': return 'DECIMAL';
  47  	 	 default:
  48  	 	 	 return $meta;
  49  	 	 }
  50  	 }
  51  
  52  	function NameQuote($name = NULL)
  53  	 {
  54  	 	 if (!is_string($name)) {
  55  	 	 	 return FALSE;
  56  	 	 }
  57  
  58  	 	 $name = trim($name);
  59  
  60  	 	 if ( !is_object($this->connection) ) {
  61  	 	 	 return $name;
  62  	 	 }
  63  
  64  	 	 $quote = $this->connection->nameQuote;
  65  
  66  	 	 // if name is of the form `name`, quote it
  67  	 	 if ( preg_match('/^`(.+)`$/', $name, $matches) ) {
  68  	 	 	 return $quote . $matches[1] . $quote;
  69  	 	 }
  70  
  71  	 	 // if name contains special characters, quote it
  72  	 	 if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) {
  73  	 	 	 return $quote . $name . $quote;
  74  	 	 }
  75  
  76  	 	 return $quote . $name . $quote;
  77  	 }
  78  
  79  	function CreateDatabase($dbname, $options=false)
  80  	 {
  81  	 	 $options = $this->_Options($options);
  82  	 	 $sql = array();
  83  
  84  	 	 $sql[] = "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'";
  85  
  86  	 	 return $sql;
  87  	 }
  88  
  89  	function _DropAutoIncrement($t)
  90  	 {
  91  	 	 if (strpos($t,'.') !== false) {
  92  	 	 	 $tarr = explode('.',$t);
  93  	 	 	 return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"';
  94  	 	 }
  95  	 	 return 'DROP GENERATOR "GEN_'.$t;
  96  	 }
  97  
  98  
  99  	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
 100  	 {
 101  	 	 $suffix = '';
 102  
 103  	 	 if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
 104  	 	 if ($fnotnull) $suffix .= ' NOT NULL';
 105  	 	 if ($fautoinc) $this->seqField = $fname;
 106  	 	 if ($fconstraint) $suffix .= ' '.$fconstraint;
 107  
 108  	 	 return $suffix;
 109  	 }
 110  
 111  /*
 112  CREATE or replace TRIGGER jaddress_insert
 113  before insert on jaddress
 114  for each row
 115  begin
 116  IF ( NEW."seqField" IS NULL OR NEW."seqField" = 0 ) THEN
 117    NEW."seqField" = GEN_ID("GEN_tabname", 1);
 118  end;
 119  */
 120  	function _Triggers($tabname,$tableoptions)
 121  	 {
 122  	 	 if (!$this->seqField) return array();
 123  
 124  	 	 $tab1 = preg_replace( '/"/', '', $tabname );
 125  	 	 if ($this->schema) {
 126  	 	 	 $t = strpos($tab1,'.');
 127  	 	 	 if ($t !== false) $tab = substr($tab1,$t+1);
 128  	 	 	 else $tab = $tab1;
 129  	 	 	 $seqField = $this->seqField;
 130  	 	 	 $seqname = $this->schema.'.'.$this->seqPrefix.$tab;
 131  	 	 	 $trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab;
 132  	 	 } else {
 133  	 	 	 $seqField = $this->seqField;
 134  	 	 	 $seqname = $this->seqPrefix.$tab1;
 135  	 	 	 $trigname = 'trig_'.$seqname;
 136  	 	 }
 137  	 	 if (isset($tableoptions['REPLACE']))
 138  	 	 { $sql[] = "DROP GENERATOR \"$seqname\"";
 139  	 	   $sql[] = "CREATE GENERATOR \"$seqname\"";
 140  	 	   $sql[] = "ALTER TRIGGER \"$trigname\" BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID(\"$seqname\", 1); END";
 141  	 	 }
 142  	 	 else
 143  	 	 { $sql[] = "CREATE GENERATOR \"$seqname\"";
 144  	 	   $sql[] = "CREATE TRIGGER \"$trigname\" FOR $tabname BEFORE INSERT OR UPDATE AS BEGIN IF ( NEW.$seqField IS NULL OR NEW.$seqField = 0 ) THEN NEW.$seqField = GEN_ID(\"$seqname\", 1); END";
 145  	 	 }
 146  
 147  	 	 $this->seqField = false;
 148  	 	 return $sql;
 149  	 }
 150  
 151  }