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.
<?php

/**
< @version v5.20.16 12-Jan-2020
> @version v5.21.0 2021-02-27
@copyright (c) 2000-2013 John Lim (jlim#natsoft.com). All rights reserved. @copyright (c) 2014 Damien Regad, Mark Newnham and the ADOdb community Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. Set tabs to 4 for best viewing. */
> // security - hide paths class ADODB2_firebird extends ADODB_DataDict { > if (!defined('ADODB_DIR')) die(); >
var $databaseType = 'firebird'; var $seqField = false;
< var $seqPrefix = 'gen_';
> var $seqPrefix = 's_';
var $blobSize = 40000;
> var $renameColumn = 'ALTER TABLE %s ALTER %s TO %s'; > var $alterCol = ' ALTER'; function ActualType($meta) > var $dropCol = ' DROP';
{ switch($meta) { case 'C': return 'VARCHAR';
< case 'XL': return 'VARCHAR(32000)'; < case 'X': return 'VARCHAR(4000)';
> case 'XL': > case 'X': return 'BLOB SUB_TYPE TEXT'; > > case 'C2': return 'VARCHAR(32765)'; // up to 32K > case 'X2': return 'VARCHAR(4096)';
< case 'C2': return 'VARCHAR'; // up to 32K < case 'X2': return 'VARCHAR(4000)';
> case 'V': return 'CHAR'; > case 'C1': return 'CHAR(1)';
case 'B': return 'BLOB'; case 'D': return 'DATE'; case 'TS': case 'T': return 'TIMESTAMP'; case 'L': return 'SMALLINT'; case 'I': return 'INTEGER'; case 'I1': return 'SMALLINT'; case 'I2': return 'SMALLINT'; case 'I4': return 'INTEGER';
< case 'I8': return 'INTEGER';
> case 'I8': return 'BIGINT';
case 'F': return 'DOUBLE PRECISION'; case 'N': return 'DECIMAL'; default: return $meta; } }
< function NameQuote($name = NULL)
> function NameQuote($name = NULL,$allowBrackets=false)
{ if (!is_string($name)) { return FALSE; } $name = trim($name); if ( !is_object($this->connection) ) { return $name; } $quote = $this->connection->nameQuote; // if name is of the form `name`, quote it if ( preg_match('/^`(.+)`$/', $name, $matches) ) { return $quote . $matches[1] . $quote; } // if name contains special characters, quote it if ( !preg_match('/^[' . $this->nameRegex . ']+$/', $name) ) { return $quote . $name . $quote; } return $quote . $name . $quote; } function CreateDatabase($dbname, $options=false) { $options = $this->_Options($options); $sql = array(); $sql[] = "DECLARE EXTERNAL FUNCTION LOWER CSTRING(80) RETURNS CSTRING(80) FREE_IT ENTRY_POINT 'IB_UDF_lower' MODULE_NAME 'ib_udf'"; return $sql; } function _DropAutoIncrement($t) { if (strpos($t,'.') !== false) { $tarr = explode('.',$t);
< return 'DROP GENERATOR '.$tarr[0].'."gen_'.$tarr[1].'"';
> return 'DROP GENERATOR '.$tarr[0].'."s_'.$tarr[1].'"';
}
< return 'DROP GENERATOR "GEN_'.$t;
> return 'DROP GENERATOR s_'.$t;
} function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned) { $suffix = ''; if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault"; if ($fnotnull) $suffix .= ' NOT NULL'; if ($fautoinc) $this->seqField = $fname;
> $fconstraint = preg_replace("/``/", "\"", $fconstraint);
if ($fconstraint) $suffix .= ' '.$fconstraint; return $suffix; }
> /** /* > Generate the SQL to create table. Returns an array of sql strings. CREATE or replace TRIGGER jaddress_insert > */ before insert on jaddress > function CreateTableSQL($tabname, $flds, $tableoptions=array()) for each row > { begin > list($lines,$pkey,$idxs) = $this->_GenFields($flds, true); IF ( NEW."seqField" IS NULL OR NEW."seqField" = 0 ) THEN > // genfields can return FALSE at times NEW."seqField" = GEN_ID("GEN_tabname", 1); > if ($lines == null) $lines = array(); end; > */ > $taboptions = $this->_Options($tableoptions); function _Triggers($tabname,$tableoptions) > $tabname = $this->TableName ($tabname); { > $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions); if (!$this->seqField) return array(); > > if ($this->autoIncrement && !isset($taboptions['DROP'])) $tab1 = preg_replace( '/"/', '', $tabname ); > { $tsql = $this->_Triggers($tabname,$taboptions); if ($this->schema) { > foreach($tsql as $s) $sql[] = $s; $t = strpos($tab1,'.'); > } if ($t !== false) $tab = substr($tab1,$t+1); > else $tab = $tab1; > if (is_array($idxs)) { $seqField = $this->seqField; > foreach($idxs as $idx => $idxdef) { $seqname = $this->schema.'.'.$this->seqPrefix.$tab; > $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); $trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab; > $sql = array_merge($sql, $sql_idxs); } else { > } $seqField = $this->seqField; > } $seqname = $this->seqPrefix.$tab1; > $trigname = 'trig_'.$seqname; > return $sql; } > } if (isset($tableoptions['REPLACE'])) > { $sql[] = "DROP GENERATOR \"$seqname\""; >
< $trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab;
> $trigname = $this->schema.'.t_'.$this->seqPrefix.$tab;
< $trigname = 'trig_'.$seqname;
> $trigname = 't_'.$seqname; > } > > if (isset($tableoptions['DROP'])) > { $sql[] = "DROP GENERATOR $seqname";
< if (isset($tableoptions['REPLACE']))
> elseif (isset($tableoptions['REPLACE']))
else
< { $sql[] = "CREATE GENERATOR \"$seqname\""; < $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";
> { $sql[] = "CREATE GENERATOR $seqname"; > $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";
} $this->seqField = false;
> return $sql; return $sql; > } } > > /** } > * Change the definition of one column > * > * As some DBM's can't do that on there own, you need to supply the complete definition of the new table, > * to allow, recreating the table and copying the content over to the new table > * @param string $tabname table-name > * @param string $flds column-name and type for the changed column > * @param string $tableflds='' complete definition of the new table, eg. for postgres, default '' > * @param array/string $tableoptions='' options for the new table see CreateTableSQL, default '' > * @return array with SQL strings > */ > function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') > { > $tabname = $this->TableName ($tabname); > $sql = array(); > list($lines,$pkey,$idxs) = $this->_GenFields($flds); > // genfields can return FALSE at times > if ($lines == null) $lines = array(); > $alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' '; > foreach($lines as $v) { > $sql[] = $alter . $v; > } > if (is_array($idxs)) { > foreach($idxs as $idx => $idxdef) { > $sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']); > $sql = array_merge($sql, $sql_idxs); > } > > }