mirror of
https://github.com/moodle/moodle.git
synced 2025-08-11 11:56:40 +02:00
MDL-71011 adodb: Bump to v5.21.0
Following the instructions @ readme_moodle.txt
This commit is contained in:
parent
18aafd0ed4
commit
91969d1e04
111 changed files with 9763 additions and 4252 deletions
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?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.
|
||||
|
@ -18,7 +17,12 @@ class ADODB2_db2 extends ADODB_DataDict {
|
|||
|
||||
var $databaseType = 'db2';
|
||||
var $seqField = false;
|
||||
var $dropCol = 'ALTER TABLE %s DROP COLUMN %s';
|
||||
|
||||
public $blobAllowsDefaultValue = true;
|
||||
public $blobAllowsNotNull = true;
|
||||
|
||||
|
||||
function ActualType($meta)
|
||||
{
|
||||
switch($meta) {
|
||||
|
@ -60,21 +64,66 @@ class ADODB2_db2 extends ADODB_DataDict {
|
|||
return $suffix;
|
||||
}
|
||||
|
||||
function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
|
||||
function alterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
|
||||
{
|
||||
if ($this->debug) ADOConnection::outp("AlterColumnSQL not supported");
|
||||
return array();
|
||||
$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 . ' ';
|
||||
|
||||
$dataTypeWords = array('SET','DATA','TYPE');
|
||||
|
||||
foreach($lines as $v)
|
||||
{
|
||||
/*
|
||||
* We must now post-process the line to insert the 'SET DATA TYPE'
|
||||
* text into the alter statement
|
||||
*/
|
||||
$e = explode(' ',$v);
|
||||
|
||||
array_splice($e,1,0,$dataTypeWords);
|
||||
|
||||
$v = implode(' ',$e);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
|
||||
|
||||
function dropColumnSql($tabname, $flds, $tableflds='',$tableoptions='')
|
||||
{
|
||||
if ($this->debug) ADOConnection::outp("DropColumnSQL not supported");
|
||||
return array();
|
||||
|
||||
|
||||
$tabname = $this->connection->getMetaCasedValue($tabname);
|
||||
$flds = $this->connection->getMetaCasedValue($flds);
|
||||
|
||||
if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_NATIVE )
|
||||
{
|
||||
/*
|
||||
* METACASE_NATIVE
|
||||
*/
|
||||
$tabname = $this->connection->nameQuote . $tabname . $this->connection->nameQuote;
|
||||
$flds = $this->connection->nameQuote . $flds . $this->connection->nameQuote;
|
||||
}
|
||||
$sql = sprintf($this->dropCol,$tabname,$flds);
|
||||
return (array)$sql;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function ChangeTableSQL($tablename, $flds, $tableoptions = false)
|
||||
function changeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFields=false)
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -86,17 +135,25 @@ class ADODB2_db2 extends ADODB_DataDict {
|
|||
$validTypes = array("CHAR","VARC");
|
||||
$invalidTypes = array("BIGI","BLOB","CLOB","DATE", "DECI","DOUB", "INTE", "REAL","SMAL", "TIME");
|
||||
// check table exists
|
||||
$cols = $this->MetaColumns($tablename);
|
||||
|
||||
|
||||
$cols = $this->metaColumns($tablename);
|
||||
if ( empty($cols)) {
|
||||
return $this->CreateTableSQL($tablename, $flds, $tableoptions);
|
||||
return $this->createTableSQL($tablename, $flds, $tableoptions);
|
||||
}
|
||||
|
||||
// already exists, alter table instead
|
||||
list($lines,$pkey) = $this->_GenFields($flds);
|
||||
$alter = 'ALTER TABLE ' . $this->TableName($tablename);
|
||||
$alter = 'ALTER TABLE ' . $this->tableName($tablename);
|
||||
$sql = array();
|
||||
|
||||
foreach ( $lines as $id => $v ) {
|
||||
/*
|
||||
* If the metaCasing was NATIVE the col returned with nameQuotes
|
||||
* around the field. We need to remove this for the metaColumn
|
||||
* match
|
||||
*/
|
||||
$id = str_replace($this->connection->nameQuote,'',$id);
|
||||
if ( isset($cols[$id]) && is_object($cols[$id]) ) {
|
||||
/**
|
||||
If the first field of $v is the fieldname, and
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -12,22 +12,31 @@
|
|||
|
||||
*/
|
||||
|
||||
// security - hide paths
|
||||
if (!defined('ADODB_DIR')) die();
|
||||
|
||||
class ADODB2_firebird extends ADODB_DataDict {
|
||||
|
||||
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';
|
||||
var $dropCol = ' DROP';
|
||||
|
||||
function ActualType($meta)
|
||||
function ActualType($meta)
|
||||
{
|
||||
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'; // up to 32K
|
||||
case 'X2': return 'VARCHAR(4000)';
|
||||
case 'C2': return 'VARCHAR(32765)'; // up to 32K
|
||||
case 'X2': return 'VARCHAR(4096)';
|
||||
|
||||
case 'V': return 'CHAR';
|
||||
case 'C1': return 'CHAR(1)';
|
||||
|
||||
case 'B': return 'BLOB';
|
||||
|
||||
|
@ -40,7 +49,7 @@ class ADODB2_firebird extends ADODB_DataDict {
|
|||
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';
|
||||
|
@ -49,7 +58,7 @@ class ADODB2_firebird extends ADODB_DataDict {
|
|||
}
|
||||
}
|
||||
|
||||
function NameQuote($name = NULL)
|
||||
function NameQuote($name = NULL,$allowBrackets=false)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
return FALSE;
|
||||
|
@ -90,9 +99,9 @@ class ADODB2_firebird extends ADODB_DataDict {
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,11 +112,41 @@ class ADODB2_firebird extends ADODB_DataDict {
|
|||
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.
|
||||
*/
|
||||
function CreateTableSQL($tabname, $flds, $tableoptions=array())
|
||||
{
|
||||
list($lines,$pkey,$idxs) = $this->_GenFields($flds, true);
|
||||
// genfields can return FALSE at times
|
||||
if ($lines == null) $lines = array();
|
||||
|
||||
$taboptions = $this->_Options($tableoptions);
|
||||
$tabname = $this->TableName ($tabname);
|
||||
$sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
|
||||
|
||||
if ($this->autoIncrement && !isset($taboptions['DROP']))
|
||||
{ $tsql = $this->_Triggers($tabname,$taboptions);
|
||||
foreach($tsql as $s) $sql[] = $s;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
CREATE or replace TRIGGER jaddress_insert
|
||||
before insert on jaddress
|
||||
|
@ -128,24 +167,60 @@ end;
|
|||
else $tab = $tab1;
|
||||
$seqField = $this->seqField;
|
||||
$seqname = $this->schema.'.'.$this->seqPrefix.$tab;
|
||||
$trigname = $this->schema.'.trig_'.$this->seqPrefix.$tab;
|
||||
$trigname = $this->schema.'.t_'.$this->seqPrefix.$tab;
|
||||
} else {
|
||||
$seqField = $this->seqField;
|
||||
$seqname = $this->seqPrefix.$tab1;
|
||||
$trigname = 'trig_'.$seqname;
|
||||
$trigname = 't_'.$seqname;
|
||||
}
|
||||
if (isset($tableoptions['REPLACE']))
|
||||
|
||||
if (isset($tableoptions['DROP']))
|
||||
{ $sql[] = "DROP GENERATOR $seqname";
|
||||
}
|
||||
elseif (isset($tableoptions['REPLACE']))
|
||||
{ $sql[] = "DROP GENERATOR \"$seqname\"";
|
||||
$sql[] = "CREATE GENERATOR \"$seqname\"";
|
||||
$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";
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -269,7 +269,7 @@ CREATE TABLE
|
|||
}
|
||||
|
||||
|
||||
function _GetSize($ftype, $ty, $fsize, $fprec)
|
||||
function _GetSize($ftype, $ty, $fsize, $fprec, $options=false)
|
||||
{
|
||||
switch ($ftype) {
|
||||
case 'INT':
|
||||
|
@ -279,7 +279,7 @@ CREATE TABLE
|
|||
return $ftype;
|
||||
}
|
||||
if ($ty == 'T') return $ftype;
|
||||
return parent::_GetSize($ftype, $ty, $fsize, $fprec);
|
||||
return parent::_GetSize($ftype, $ty, $fsize, $fprec, $options);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -53,6 +53,9 @@ class ADODB2_mssqlnative extends ADODB_DataDict {
|
|||
|
||||
//var $alterCol = ' ALTER COLUMN ';
|
||||
|
||||
public $blobAllowsDefaultValue = true;
|
||||
public $blobAllowsNotNull = true;
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
if (is_object($t)) {
|
||||
|
@ -94,7 +97,10 @@ class ADODB2_mssqlnative extends ADODB_DataDict {
|
|||
-3 => 'X'
|
||||
);
|
||||
|
||||
return $_typeConversion($t);
|
||||
if (isset($_typeConversion[$t]))
|
||||
return $_typeConversion[$t];
|
||||
|
||||
return ADODB_DEFAULT_METATYPE;
|
||||
|
||||
}
|
||||
|
||||
|
@ -126,7 +132,6 @@ class ADODB2_mssqlnative extends ADODB_DataDict {
|
|||
case 'F': return 'REAL';
|
||||
case 'N': return 'NUMERIC';
|
||||
default:
|
||||
print "RETURN $meta";
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +358,7 @@ CREATE TABLE
|
|||
}
|
||||
|
||||
|
||||
function _GetSize($ftype, $ty, $fsize, $fprec)
|
||||
function _GetSize($ftype, $ty, $fsize, $fprec,$options=false)
|
||||
{
|
||||
switch ($ftype) {
|
||||
case 'INT':
|
||||
|
@ -363,7 +368,7 @@ CREATE TABLE
|
|||
return $ftype;
|
||||
}
|
||||
if ($ty == 'T') return $ftype;
|
||||
return parent::_GetSize($ftype, $ty, $fsize, $fprec);
|
||||
return parent::_GetSize($ftype, $ty, $fsize, $fprec, $options);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -24,8 +24,11 @@ class ADODB2_mysql extends ADODB_DataDict {
|
|||
var $dropIndex = 'DROP INDEX %s ON %s';
|
||||
var $renameColumn = 'ALTER TABLE %s CHANGE COLUMN %s %s %s'; // needs column-definition!
|
||||
|
||||
public $blobAllowsNotNull = true;
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
|
||||
if (is_object($t)) {
|
||||
$fieldobj = $t;
|
||||
$t = $fieldobj->type;
|
||||
|
@ -74,7 +77,7 @@ class ADODB2_mysql extends ADODB_DataDict {
|
|||
case 'SMALLINT': return $is_serial ? 'R' : 'I2';
|
||||
case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
|
||||
case 'BIGINT': return $is_serial ? 'R' : 'I8';
|
||||
default: return 'N';
|
||||
default: return ADODB_DEFAULT_METATYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -25,8 +25,18 @@ class ADODB2_oci8 extends ADODB_DataDict {
|
|||
var $alterCol = ' MODIFY ';
|
||||
var $typeX = 'VARCHAR(4000)';
|
||||
var $typeXL = 'CLOB';
|
||||
|
||||
/**
|
||||
* Legacy compatibility for sequence names for emulated auto-increments.
|
||||
*
|
||||
* If set to true, creates sequences and triggers as TRIG_394545594
|
||||
* instead of TRIG_possibly_too_long_tablename
|
||||
*
|
||||
* @var bool $useCompactAutoIncrements
|
||||
*/
|
||||
public $useCompactAutoIncrements = false;
|
||||
|
||||
function MetaType($t, $len=-1, $fieldobj=false)
|
||||
function metaType($t, $len=-1, $fieldobj=false)
|
||||
{
|
||||
if (is_object($t)) {
|
||||
$fieldobj = $t;
|
||||
|
@ -69,7 +79,7 @@ class ADODB2_oci8 extends ADODB_DataDict {
|
|||
return 'I';
|
||||
|
||||
default:
|
||||
return 'N';
|
||||
return ADODB_DEFAULT_METATYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,32 +195,52 @@ class ADODB2_oci8 extends ADODB_DataDict {
|
|||
return $suffix;
|
||||
}
|
||||
|
||||
/*
|
||||
CREATE or replace TRIGGER jaddress_insert
|
||||
before insert on jaddress
|
||||
for each row
|
||||
begin
|
||||
select seqaddress.nextval into :new.A_ID from dual;
|
||||
end;
|
||||
*/
|
||||
/**
|
||||
* Creates an insert trigger to emulate an auto-increment column
|
||||
* in a table
|
||||
*
|
||||
* @param string $tabname The name of the table
|
||||
* @param string[] $tableoptions Optional configuration items
|
||||
*
|
||||
* @return string[] The SQL statements to create the trigger
|
||||
*/
|
||||
function _Triggers($tabname,$tableoptions)
|
||||
{
|
||||
|
||||
if (!$this->seqField) return array();
|
||||
|
||||
if ($this->schema) {
|
||||
if ($this->schema)
|
||||
{
|
||||
$t = strpos($tabname,'.');
|
||||
if ($t !== false) $tab = substr($tabname,$t+1);
|
||||
else $tab = $tabname;
|
||||
if ($t !== false)
|
||||
$tab = substr($tabname,$t+1);
|
||||
else
|
||||
$tab = $tabname;
|
||||
|
||||
if ($this->connection->useCompactAutoIncrements)
|
||||
$id = sprintf('%u',crc32(strtolower($tab)));
|
||||
else
|
||||
$id = $tab;
|
||||
|
||||
$seqname = $this->schema.'.'.$this->seqPrefix.$tab;
|
||||
$trigname = $this->schema.'.'.$this->trigPrefix.$this->seqPrefix.$tab;
|
||||
} else {
|
||||
$seqname = $this->seqPrefix.$tabname;
|
||||
$trigname = $this->trigPrefix.$seqname;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->connection->useCompactAutoIncrements)
|
||||
$id = sprintf('%u',crc32(strtolower($tabname)));
|
||||
else
|
||||
$id = $tabname;
|
||||
|
||||
$seqname = $this->seqPrefix.$id;
|
||||
$trigname = $this->trigPrefix.$id;
|
||||
}
|
||||
|
||||
if (strlen($seqname) > 30) {
|
||||
$seqname = $this->seqPrefix.uniqid('');
|
||||
} // end if
|
||||
|
||||
if (strlen($trigname) > 30) {
|
||||
$trigname = $this->trigPrefix.uniqid('');
|
||||
} // end if
|
||||
|
@ -221,8 +251,8 @@ end;
|
|||
$seqIncr = '';
|
||||
if (isset($tableoptions['SEQUENCE_INCREMENT'])){$seqIncr = ' INCREMENT BY '.$tableoptions['SEQUENCE_INCREMENT'];}
|
||||
$seqStart = '';
|
||||
if (isset($tableoptions['SEQUENCE_START'])){$seqIncr = ' START WITH '.$tableoptions['SEQUENCE_START'];}
|
||||
$sql[] = "CREATE SEQUENCE $seqname $seqStart $seqIncr $seqCache";
|
||||
if (isset($tableoptions['SEQUENCE_START'])){$seqStart = ' START WITH '.$tableoptions['SEQUENCE_START'];}
|
||||
$sql[] = "CREATE SEQUENCE $seqname MINVALUE 1 $seqStart $seqIncr $seqCache";
|
||||
$sql[] = "CREATE OR REPLACE TRIGGER $trigname BEFORE insert ON $tabname FOR EACH ROW WHEN (NEW.$this->seqField IS NULL OR NEW.$this->seqField = 0) BEGIN select $seqname.nextval into :new.$this->seqField from dual; END;";
|
||||
|
||||
$this->seqField = false;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -25,6 +25,9 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
var $renameTable = 'ALTER TABLE %s RENAME TO %s'; // at least since 7.1
|
||||
var $dropTable = 'DROP TABLE %s CASCADE';
|
||||
|
||||
public $blobAllowsDefaultValue = true;
|
||||
public $blobAllowsNotNull = true;
|
||||
|
||||
function MetaType($t,$len=-1,$fieldobj=false)
|
||||
{
|
||||
if (is_object($t)) {
|
||||
|
@ -85,7 +88,7 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
return 'F';
|
||||
|
||||
default:
|
||||
return 'N';
|
||||
return ADODB_DEFAULT_METATYPE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,11 +167,11 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
/**
|
||||
* Change the definition of one column
|
||||
*
|
||||
* Postgres can't do that on it's own, you need to supply the complete defintion of the new table,
|
||||
* Postgres can't do that on it's 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 defintion of the new table, eg. for postgres, default ''
|
||||
* @param string $tableflds complete definition of the new table, eg. for postgres, default ''
|
||||
* @param array/ $tableoptions options for the new table see CreateTableSQL, default ''
|
||||
* @return array with SQL strings
|
||||
*/
|
||||
|
@ -200,7 +203,7 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
// this next block doesn't work - there is no way that I can see to
|
||||
// explicitly ask a column to be null using $flds
|
||||
else if ($set_null = preg_match('/NULL/i',$v)) {
|
||||
// if they didn't specify not null, see if they explicitely asked for null
|
||||
// if they didn't specify not null, see if they explicitly asked for null
|
||||
// Lookbehind pattern covers the case 'fieldname NULL datatype DEFAULT NULL'
|
||||
// only the first NULL should be removed, not the one specifying
|
||||
// the default value
|
||||
|
@ -274,11 +277,11 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
/**
|
||||
* Drop one column
|
||||
*
|
||||
* Postgres < 7.3 can't do that on it's own, you need to supply the complete defintion of the new table,
|
||||
* Postgres < 7.3 can't do that on it's 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 defintion of the new table, eg. for postgres, default ''
|
||||
* @param string $tableflds complete definition of the new table, eg. for postgres, default ''
|
||||
* @param array/ $tableoptions options for the new table see CreateTableSQL, default ''
|
||||
* @return array with SQL strings
|
||||
*/
|
||||
|
@ -303,7 +306,7 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
* @internal
|
||||
* @param string $tabname table-name
|
||||
* @param string $dropflds column-names to drop
|
||||
* @param string $tableflds complete defintion of the new table, eg. for postgres
|
||||
* @param string $tableflds complete definition of the new table, eg. for postgres
|
||||
* @param array/string $tableoptions options for the new table see CreateTableSQL, default ''
|
||||
* @return array with SQL strings
|
||||
*/
|
||||
|
@ -312,20 +315,34 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
if ($dropflds && !is_array($dropflds)) $dropflds = explode(',',$dropflds);
|
||||
$copyflds = array();
|
||||
foreach($this->MetaColumns($tabname) as $fld) {
|
||||
if (!$dropflds || !in_array($fld->name,$dropflds)) {
|
||||
// we need to explicit convert varchar to a number to be able to do an AlterColumn of a char column to a nummeric one
|
||||
if (preg_match('/'.$fld->name.' (I|I2|I4|I8|N|F)/i',$tableflds,$matches) &&
|
||||
in_array($fld->type,array('varchar','char','text','bytea'))) {
|
||||
if (preg_match('/'.$fld->name.' (\w+)/i', $tableflds, $matches)) {
|
||||
$new_type = strtoupper($matches[1]);
|
||||
// AlterColumn of a char column to a nummeric one needs an explicit conversation
|
||||
if (in_array($new_type, array('I', 'I2', 'I4', 'I8', 'N', 'F')) &&
|
||||
in_array($fld->type, array('varchar','char','text','bytea'))
|
||||
) {
|
||||
$copyflds[] = "to_number($fld->name,'S9999999999999D99')";
|
||||
} else {
|
||||
$copyflds[] = $fld->name;
|
||||
}
|
||||
// identify the sequence name and the fld its on
|
||||
if ($fld->primary_key && $fld->has_default &&
|
||||
preg_match("/nextval\('([^']+)'::text\)/",$fld->default_value,$matches)) {
|
||||
$seq_name = $matches[1];
|
||||
$seq_fld = $fld->name;
|
||||
// other column-type changes needs explicit decode, encode for bytea or cast otherwise
|
||||
$new_actual_type = $this->ActualType($new_type);
|
||||
if (strtoupper($fld->type) != $new_actual_type) {
|
||||
if ($new_actual_type == 'BYTEA' && $fld->type == 'text') {
|
||||
$copyflds[] = "DECODE($fld->name, 'escape')";
|
||||
} elseif ($fld->type == 'bytea' && $new_actual_type == 'TEXT') {
|
||||
$copyflds[] = "ENCODE($fld->name, 'escape')";
|
||||
} else {
|
||||
$copyflds[] = "CAST($fld->name AS $new_actual_type)";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$copyflds[] = $fld->name;
|
||||
}
|
||||
// identify the sequence name and the fld its on
|
||||
if ($fld->primary_key && $fld->has_default &&
|
||||
preg_match("/nextval\('([^']+)'::(text|regclass)\)/",$fld->default_value,$matches)) {
|
||||
$seq_name = $matches[1];
|
||||
$seq_fld = $fld->name;
|
||||
}
|
||||
}
|
||||
$copyflds = implode(', ',$copyflds);
|
||||
|
@ -341,7 +358,7 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
$aSql[] = "SELECT setval('$seq_name',MAX($seq_fld)) FROM $tabname";
|
||||
}
|
||||
$aSql[] = "DROP TABLE $tempname";
|
||||
// recreate the indexes, if they not contain one of the droped columns
|
||||
// recreate the indexes, if they not contain one of the dropped columns
|
||||
foreach($this->MetaIndexes($tabname) as $idx_name => $idx_data)
|
||||
{
|
||||
if (substr($idx_name,-5) != '_pkey' && (!$dropflds || !count(array_intersect($dropflds,$idx_data['columns'])))) {
|
||||
|
@ -377,7 +394,7 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
return $suffix;
|
||||
}
|
||||
|
||||
// search for a sequece for the given table (asumes the seqence-name contains the table-name!)
|
||||
// search for a sequence for the given table (asumes the seqence-name contains the table-name!)
|
||||
// if yes return sql to drop it
|
||||
// this is still necessary if postgres < 7.3 or the SERIAL was created on an earlier version!!!
|
||||
function _DropAutoIncrement($tabname)
|
||||
|
@ -386,7 +403,7 @@ class ADODB2_postgres extends ADODB_DataDict {
|
|||
|
||||
$seq = $this->connection->GetOne("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relname LIKE $tabname AND relkind='S'");
|
||||
|
||||
// check if a tables depends on the sequenz and it therefor cant and dont need to be droped separatly
|
||||
// check if a tables depends on the sequence and it therefore can't and don't need to be dropped separately
|
||||
if (!$seq || $this->connection->GetOne("SELECT relname FROM pg_class JOIN pg_depend ON pg_class.relfilenode=pg_depend.objid WHERE relname='$seq' AND relkind='S' AND deptype='i'")) {
|
||||
return False;
|
||||
}
|
||||
|
@ -472,13 +489,75 @@ CREATE [ UNIQUE ] INDEX index_name ON table
|
|||
return $sql;
|
||||
}
|
||||
|
||||
function _GetSize($ftype, $ty, $fsize, $fprec)
|
||||
function _GetSize($ftype, $ty, $fsize, $fprec, $options=false)
|
||||
{
|
||||
if (strlen($fsize) && $ty != 'X' && $ty != 'B' && $ty != 'I' && strpos($ftype,'(') === false) {
|
||||
$ftype .= "(".$fsize;
|
||||
if (strlen($fprec)) $ftype .= ",".$fprec;
|
||||
$ftype .= ')';
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle additional options
|
||||
*/
|
||||
if (is_array($options))
|
||||
{
|
||||
foreach($options as $type=>$value)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'ENUM':
|
||||
$ftype .= '(' . $value . ')';
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ftype;
|
||||
}
|
||||
|
||||
function ChangeTableSQL($tablename, $flds, $tableoptions = false, $dropOldFlds=false){
|
||||
global $ADODB_FETCH_MODE;
|
||||
parent::ChangeTableSQL($tablename, $flds);
|
||||
$save = $ADODB_FETCH_MODE;
|
||||
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||
if ($this->connection->fetchMode !== false)
|
||||
$savem = $this->connection->SetFetchMode(false);
|
||||
|
||||
// check table exists
|
||||
$save_handler = $this->connection->raiseErrorFn;
|
||||
$this->connection->raiseErrorFn = '';
|
||||
$cols = $this->MetaColumns($tablename);
|
||||
$this->connection->raiseErrorFn = $save_handler;
|
||||
|
||||
if (isset($savem))
|
||||
$this->connection->SetFetchMode($savem);
|
||||
$ADODB_FETCH_MODE = $save;
|
||||
|
||||
$sqlResult=array();
|
||||
if ( empty($cols)) {
|
||||
$sqlResult=$this->CreateTableSQL($tablename, $flds, $tableoptions);
|
||||
} else {
|
||||
$sqlResultAdd = $this->AddColumnSQL($tablename, $flds);
|
||||
$sqlResultAlter = $this->AlterColumnSQL($tablename, $flds, '', $tableoptions);
|
||||
$sqlResult = array_merge((array)$sqlResultAdd, (array)$sqlResultAlter);
|
||||
|
||||
if ($dropOldFlds) {
|
||||
// already exists, alter table instead
|
||||
list($lines,$pkey,$idxs) = $this->_GenFields($flds);
|
||||
// genfields can return FALSE at times
|
||||
if ($lines == null)
|
||||
$lines = array();
|
||||
$alter = 'ALTER TABLE ' . $this->TableName($tablename);
|
||||
foreach ( $cols as $id => $v ){
|
||||
if ( !isset($lines[$id]) ){
|
||||
$sqlResult[] = $alter . $this->dropCol . ' ' . $v->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $sqlResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -71,7 +71,7 @@ class ADODB2_sapdb extends ADODB_DataDict {
|
|||
'FLOAT' => 'F',
|
||||
'FIXED' => 'N',
|
||||
);
|
||||
$type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : 'C';
|
||||
$type = isset($maxdb_type2adodb[$t]) ? $maxdb_type2adodb[$t] : ADODB_DEFAULT_METATYPE;
|
||||
|
||||
// convert integer-types simulated with fixed back to integer
|
||||
if ($t == 'FIXED' && !$fieldobj->scale && ($len == 20 || $len == 3)) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
@ -25,8 +25,9 @@ class ADODB2_sqlite extends ADODB_DataDict {
|
|||
var $dropIndex = 'DROP INDEX IF EXISTS %s';
|
||||
var $renameTable = 'ALTER TABLE %s RENAME TO %s';
|
||||
|
||||
|
||||
|
||||
public $blobAllowsDefaultValue = true;
|
||||
public $blobAllowsNotNull = true;
|
||||
|
||||
function ActualType($meta)
|
||||
{
|
||||
switch(strtoupper($meta)) {
|
||||
|
@ -58,7 +59,7 @@ class ADODB2_sqlite extends ADODB_DataDict {
|
|||
}
|
||||
|
||||
// return string must begin with space
|
||||
function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
|
||||
function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
|
||||
{
|
||||
$suffix = '';
|
||||
if ($funsigned) $suffix .= ' UNSIGNED';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue