summaryrefslogtreecommitdiff
path: root/program/lib/MDB2/Driver/Reverse
diff options
context:
space:
mode:
Diffstat (limited to 'program/lib/MDB2/Driver/Reverse')
-rw-r--r--program/lib/MDB2/Driver/Reverse/mssql.php14
-rw-r--r--program/lib/MDB2/Driver/Reverse/mysql.php54
-rw-r--r--program/lib/MDB2/Driver/Reverse/mysqli.php44
-rw-r--r--program/lib/MDB2/Driver/Reverse/pgsql.php12
-rw-r--r--program/lib/MDB2/Driver/Reverse/sqlite.php14
-rw-r--r--program/lib/MDB2/Driver/Reverse/sqlsrv.php12
6 files changed, 85 insertions, 65 deletions
diff --git a/program/lib/MDB2/Driver/Reverse/mssql.php b/program/lib/MDB2/Driver/Reverse/mssql.php
index 96bc09515..e83ab6f60 100644
--- a/program/lib/MDB2/Driver/Reverse/mssql.php
+++ b/program/lib/MDB2/Driver/Reverse/mssql.php
@@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: mssql.php 292715 2009-12-28 14:06:34Z quipo $
+// $Id: mssql.php 295587 2010-02-28 17:16:38Z quipo $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@@ -70,7 +70,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
*/
function getTableFieldDefinition($table_name, $field_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -187,7 +187,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
*/
function getTableIndexDefinition($table_name, $index_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -271,7 +271,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -406,7 +406,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
*/
function getTriggerDefinition($trigger)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -486,7 +486,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
return parent::tableInfo($result, $mode);
}
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -564,7 +564,7 @@ class MDB2_Driver_Reverse_mssql extends MDB2_Driver_Reverse_Common
*/
function _mssql_field_flags($table, $column)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
diff --git a/program/lib/MDB2/Driver/Reverse/mysql.php b/program/lib/MDB2/Driver/Reverse/mysql.php
index 2ac9fc0f5..1cd2ad9c0 100644
--- a/program/lib/MDB2/Driver/Reverse/mysql.php
+++ b/program/lib/MDB2/Driver/Reverse/mysql.php
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: mysql.php 292715 2009-12-28 14:06:34Z quipo $
+// $Id: mysql.php 295587 2010-02-28 17:16:38Z quipo $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@@ -69,7 +69,7 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
*/
function getTableFieldDefinition($table_name, $field_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -117,9 +117,17 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
$default = '';
}
}
+ $definition[0] = array(
+ 'notnull' => $notnull,
+ 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
+ );
$autoincrement = false;
- if (!empty($column['extra']) && $column['extra'] == 'auto_increment') {
- $autoincrement = true;
+ if (!empty($column['extra'])) {
+ if ($column['extra'] == 'auto_increment') {
+ $autoincrement = true;
+ } else {
+ $definition[0]['extra'] = $column['extra'];
+ }
}
$collate = null;
if (!empty($column['collation'])) {
@@ -127,10 +135,6 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
$charset = preg_replace('/(.+?)(_.+)?/', '$1', $collate);
}
- $definition[0] = array(
- 'notnull' => $notnull,
- 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
- );
if (null !== $length) {
$definition[0]['length'] = $length;
}
@@ -181,7 +185,7 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
*/
function getTableIndexDefinition($table_name, $index_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -256,7 +260,7 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -356,10 +360,16 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
*/
function _getTableFKConstraintDefinition($table, $constraint_name, $definition)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
+ //Use INFORMATION_SCHEMA instead?
+ //SELECT *
+ // FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
+ // WHERE CONSTRAINT_SCHEMA = '$dbname'
+ // AND TABLE_NAME = '$table'
+ // AND CONSTRAINT_NAME = '$constraint_name';
$query = 'SHOW CREATE TABLE '. $db->escape($table);
$constraint = $db->queryOne($query, 'text', 1);
if (!PEAR::isError($constraint) && !empty($constraint)) {
@@ -372,10 +382,10 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
}
$constraint_name_original = $constraint_name;
$constraint_name = $db->getIndexName($constraint_name);
- $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
+ $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i';
if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
//fallback to original constraint name
- $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
+ $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i';
}
if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
$definition['foreign'] = true;
@@ -397,8 +407,8 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
'position' => $colpos++
);
}
- $definition['onupdate'] = 'NO ACTION';
- $definition['ondelete'] = 'NO ACTION';
+ $definition['ondelete'] = empty($matches[4]) ? 'RESTRICT' : strtoupper($matches[4]);
+ $definition['onupdate'] = empty($matches[5]) ? 'RESTRICT' : strtoupper($matches[5]);
$definition['match'] = 'SIMPLE';
return $definition;
}
@@ -424,7 +434,7 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
*/
function getTriggerDefinition($trigger)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -476,7 +486,7 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
return parent::tableInfo($result, $mode);
}
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -506,11 +516,11 @@ class MDB2_Driver_Reverse_mysql extends MDB2_Driver_Reverse_Common
$db->loadModule('Datatype', null, true);
for ($i = 0; $i < $count; $i++) {
$res[$i] = array(
- 'table' => $case_func(@mysql_field_table($resource, $i)),
- 'name' => $case_func(@mysql_field_name($resource, $i)),
- 'type' => @mysql_field_type($resource, $i),
- 'length' => @mysql_field_len($resource, $i),
- 'flags' => @mysql_field_flags($resource, $i),
+ 'table' => $case_func(@mysql_field_table($resource, $i)),
+ 'name' => $case_func(@mysql_field_name($resource, $i)),
+ 'type' => @mysql_field_type($resource, $i),
+ 'length' => @mysql_field_len($resource, $i),
+ 'flags' => @mysql_field_flags($resource, $i),
);
if ($res[$i]['type'] == 'string') {
$res[$i]['type'] = 'char';
diff --git a/program/lib/MDB2/Driver/Reverse/mysqli.php b/program/lib/MDB2/Driver/Reverse/mysqli.php
index 4ad52b16c..10e918338 100644
--- a/program/lib/MDB2/Driver/Reverse/mysqli.php
+++ b/program/lib/MDB2/Driver/Reverse/mysqli.php
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@pooteeweet.org> |
// +----------------------------------------------------------------------+
//
-// $Id: mysqli.php 292715 2009-12-28 14:06:34Z quipo $
+// $Id: mysqli.php 295587 2010-02-28 17:16:38Z quipo $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@@ -123,7 +123,7 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
*/
function getTableFieldDefinition($table_name, $field_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -171,9 +171,17 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
$default = '';
}
}
+ $definition[0] = array(
+ 'notnull' => $notnull,
+ 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
+ );
$autoincrement = false;
- if (!empty($column['extra']) && $column['extra'] == 'auto_increment') {
- $autoincrement = true;
+ if (!empty($column['extra'])) {
+ if ($column['extra'] == 'auto_increment') {
+ $autoincrement = true;
+ } else {
+ $definition[0]['extra'] = $column['extra'];
+ }
}
$collate = null;
if (!empty($column['collation'])) {
@@ -181,10 +189,6 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
$charset = preg_replace('/(.+?)(_.+)?/', '$1', $collate);
}
- $definition[0] = array(
- 'notnull' => $notnull,
- 'nativetype' => preg_replace('/^([a-z]+)[^a-z].*/i', '\\1', $column['type'])
- );
if (null !== $length) {
$definition[0]['length'] = $length;
}
@@ -235,7 +239,7 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
*/
function getTableIndexDefinition($table_name, $index_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -310,7 +314,7 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -410,10 +414,16 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
*/
function _getTableFKConstraintDefinition($table, $constraint_name, $definition)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
+ //Use INFORMATION_SCHEMA instead?
+ //SELECT *
+ // FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
+ // WHERE CONSTRAINT_SCHEMA = '$dbname'
+ // AND TABLE_NAME = '$table'
+ // AND CONSTRAINT_NAME = '$constraint_name';
$query = 'SHOW CREATE TABLE '. $db->escape($table);
$constraint = $db->queryOne($query, 'text', 1);
if (!PEAR::isError($constraint) && !empty($constraint)) {
@@ -426,10 +436,10 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
}
$constraint_name_original = $constraint_name;
$constraint_name = $db->getIndexName($constraint_name);
- $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
+ $pattern = '/\bCONSTRAINT\s+'.$constraint_name.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i';
if (!preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
//fallback to original constraint name
- $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^ ]+) \(([^\)]+)\)/i';
+ $pattern = '/\bCONSTRAINT\s+'.$constraint_name_original.'\s+FOREIGN KEY\s+\(([^\)]+)\) \bREFERENCES\b ([^\s]+) \(([^\)]+)\)(?: ON DELETE ([^\s]+))?(?: ON UPDATE ([^\s]+))?/i';
}
if (preg_match($pattern, str_replace('`', '', $constraint), $matches)) {
$definition['foreign'] = true;
@@ -451,8 +461,8 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
'position' => $colpos++
);
}
- $definition['onupdate'] = 'NO ACTION';
- $definition['ondelete'] = 'NO ACTION';
+ $definition['ondelete'] = empty($matches[4]) ? 'RESTRICT' : strtoupper($matches[4]);
+ $definition['onupdate'] = empty($matches[5]) ? 'RESTRICT' : strtoupper($matches[5]);
$definition['match'] = 'SIMPLE';
return $definition;
}
@@ -478,7 +488,7 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
*/
function getTriggerDefinition($trigger)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -530,7 +540,7 @@ class MDB2_Driver_Reverse_mysqli extends MDB2_Driver_Reverse_Common
return parent::tableInfo($result, $mode);
}
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
diff --git a/program/lib/MDB2/Driver/Reverse/pgsql.php b/program/lib/MDB2/Driver/Reverse/pgsql.php
index 47ae38ec1..a630f306c 100644
--- a/program/lib/MDB2/Driver/Reverse/pgsql.php
+++ b/program/lib/MDB2/Driver/Reverse/pgsql.php
@@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: pgsql.php 292715 2009-12-28 14:06:34Z quipo $
+// $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $
require_once 'MDB2/Driver/Reverse/Common.php';
@@ -69,7 +69,7 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
*/
function getTableFieldDefinition($table_name, $field_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -199,7 +199,7 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
*/
function getTableIndexDefinition($table_name, $index_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -257,7 +257,7 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -444,7 +444,7 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
*/
function getTriggerDefinition($trigger)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -518,7 +518,7 @@ class MDB2_Driver_Reverse_pgsql extends MDB2_Driver_Reverse_Common
return parent::tableInfo($result, $mode);
}
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
diff --git a/program/lib/MDB2/Driver/Reverse/sqlite.php b/program/lib/MDB2/Driver/Reverse/sqlite.php
index 6fb638298..c88ad0ddb 100644
--- a/program/lib/MDB2/Driver/Reverse/sqlite.php
+++ b/program/lib/MDB2/Driver/Reverse/sqlite.php
@@ -43,7 +43,7 @@
// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: sqlite.php 292715 2009-12-28 14:06:34Z quipo $
+// $Id: sqlite.php 295587 2010-02-28 17:16:38Z quipo $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@@ -78,7 +78,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
*/
function _getTableColumns($sql)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -156,7 +156,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
*/
function getTableFieldDefinition($table_name, $field_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -258,7 +258,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
*/
function getTableIndexDefinition($table_name, $index_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -341,7 +341,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -532,7 +532,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
*/
function getTriggerDefinition($trigger)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -596,7 +596,7 @@ class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
return parent::tableInfo($result, $mode);
}
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
diff --git a/program/lib/MDB2/Driver/Reverse/sqlsrv.php b/program/lib/MDB2/Driver/Reverse/sqlsrv.php
index 3835ceb85..d913594e9 100644
--- a/program/lib/MDB2/Driver/Reverse/sqlsrv.php
+++ b/program/lib/MDB2/Driver/Reverse/sqlsrv.php
@@ -67,7 +67,7 @@ class MDB2_Driver_Reverse_sqlsrv extends MDB2_Driver_Reverse_Common
*/
function getTableFieldDefinition($table_name, $field_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -184,7 +184,7 @@ class MDB2_Driver_Reverse_sqlsrv extends MDB2_Driver_Reverse_Common
*/
function getTableIndexDefinition($table_name, $index_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -268,7 +268,7 @@ class MDB2_Driver_Reverse_sqlsrv extends MDB2_Driver_Reverse_Common
*/
function getTableConstraintDefinition($table_name, $constraint_name)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -403,7 +403,7 @@ class MDB2_Driver_Reverse_sqlsrv extends MDB2_Driver_Reverse_Common
*/
function getTriggerDefinition($trigger)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -483,7 +483,7 @@ class MDB2_Driver_Reverse_sqlsrv extends MDB2_Driver_Reverse_Common
return parent::tableInfo($result, $mode);
}
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}
@@ -564,7 +564,7 @@ class MDB2_Driver_Reverse_sqlsrv extends MDB2_Driver_Reverse_Common
*/
function _mssql_field_flags($table, $column)
{
- $db =& $this->getDBInstance();
+ $db = $this->getDBInstance();
if (PEAR::isError($db)) {
return $db;
}