From 7244b4500e2b685cee5e9c4746a87f12acb56297 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Fri, 12 Mar 2010 03:13:59 -0500
Subject: [PATCH] - Merge changes from MDB2's trunk

---
 program/lib/MDB2/Driver/Reverse/mysqli.php |   44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/program/lib/MDB2/Driver/Reverse/mysqli.php b/program/lib/MDB2/Driver/Reverse/mysqli.php
index 4ad52b1..10e9183 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 @@
      */
     function getTableFieldDefinition($table_name, $field_name)
     {
-        $db =& $this->getDBInstance();
+        $db = $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }
@@ -171,9 +171,17 @@
                         $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 @@
                     $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 @@
      */
     function getTableIndexDefinition($table_name, $index_name)
     {
-        $db =& $this->getDBInstance();
+        $db = $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }
@@ -310,7 +314,7 @@
      */
     function getTableConstraintDefinition($table_name, $constraint_name)
     {
-        $db =& $this->getDBInstance();
+        $db = $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }
@@ -410,10 +414,16 @@
      */
     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 @@
             }
             $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 @@
                         '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 @@
      */
     function getTriggerDefinition($trigger)
     {
-        $db =& $this->getDBInstance();
+        $db = $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }
@@ -530,7 +540,7 @@
            return parent::tableInfo($result, $mode);
         }
 
-        $db =& $this->getDBInstance();
+        $db = $this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
         }

--
Gitblit v1.9.1