[geeklog-hg] geeklog: MySQL class will now add default character set if neces...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Thu Jan 17 07:46:52 EST 2013


changeset 8915:ed1753c5dd03
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/ed1753c5dd03
user: Kenji ITO <mystralkk at gmail.com>
date: Wed Jan 16 17:05:04 2013 +0900
description:
MySQL class will now add default character set if necessary (bug #0001540)

diffstat:

 plugins/links/functions.inc               |   2 +-
 plugins/polls/functions.inc               |   2 +-
 public_html/admin/install/lib-install.php |   3 -
 public_html/admin/install/lib-upgrade.php |  23 -----------
 public_html/admin/plugins.php             |   3 -
 system/databases/mysql.class.php          |  58 +++++++++++++++++++++++++++-
 system/databases/mysqli.class.php         |  61 ++++++++++++++++++++++++++++--
 7 files changed, 113 insertions(+), 39 deletions(-)

diffs (truncated from 337 to 300 lines):

diff -r 1e8d62d0021f -r ed1753c5dd03 plugins/links/functions.inc
--- a/plugins/links/functions.inc	Tue Jan 15 11:16:47 2013 -0500
+++ b/plugins/links/functions.inc	Wed Jan 16 17:05:04 2013 +0900
@@ -720,7 +720,7 @@
 
             if (isset($_UPDATES[$current_version])) {
                 $_SQL = $_UPDATES[$current_version];
-                $_SQL = INST_checkInnodbUpgrade($_SQL);
+
                 foreach ($_SQL as $sql) {
                     DB_query($sql);
                 }
diff -r 1e8d62d0021f -r ed1753c5dd03 plugins/polls/functions.inc
--- a/plugins/polls/functions.inc	Tue Jan 15 11:16:47 2013 -0500
+++ b/plugins/polls/functions.inc	Wed Jan 16 17:05:04 2013 +0900
@@ -1185,7 +1185,7 @@
 
             if (isset($_UPDATES[$current_version])) {
                 $_SQL = $_UPDATES[$current_version];
-                $_SQL = INST_checkInnodbUpgrade($_SQL);
+
                 foreach ($_SQL as $sql) {
                     DB_query($sql);
                 }
diff -r 1e8d62d0021f -r ed1753c5dd03 public_html/admin/install/lib-install.php
--- a/public_html/admin/install/lib-install.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/public_html/admin/install/lib-install.php	Wed Jan 16 17:05:04 2013 +0900
@@ -825,9 +825,6 @@
 
         foreach ($_SQL as $sql) {
             $sql = str_replace('#group#', $admin_group_id, $sql);
-            if ($use_innodb) {
-                $sql = str_replace('MyISAM', 'InnoDB', $sql);
-            }
             DB_query($sql);
             if (DB_error()) {
                 COM_errorLog('Error creating plugin table', 1);
diff -r 1e8d62d0021f -r ed1753c5dd03 public_html/admin/install/lib-upgrade.php
--- a/public_html/admin/install/lib-upgrade.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/public_html/admin/install/lib-upgrade.php	Wed Jan 16 17:05:04 2013 +0900
@@ -736,7 +736,6 @@
 {
     global $progress, $use_innodb, $_DB, $_DB_dbms;
 
-    $_SQL = INST_checkInnodbUpgrade($_SQL);
     foreach ($_SQL as $sql) {
         $progress .= "executing " . $sql . "<br" . XHTML . ">\n";
         if ($_DB_dbms == 'mssql') {
@@ -748,28 +747,6 @@
 }
 
 /**
- * Check InnoDB Upgrade
- *
- * @param   array   $_SQL   List of SQL queries
- * @return  array           InnoDB table style if chosen
- *
- */
-function INST_checkInnodbUpgrade($_SQL)
-{
-    global $use_innodb;
-
-    if ($use_innodb) {
-        $statements = count($_SQL);
-        for ($i = 0; $i < $statements; $i++) {
-            $_SQL[$i] = str_replace('MyISAM', 'InnoDB', $_SQL[$i]);
-        }
-    }
-
-    return $_SQL;
-}
-
-
-/**
  * Check for InnoDB table support (usually as of MySQL 4.0, but may be
  * available in earlier versions, e.g. "Max" or custom builds).
  *
diff -r 1e8d62d0021f -r ed1753c5dd03 public_html/admin/plugins.php
--- a/public_html/admin/plugins.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/public_html/admin/plugins.php	Wed Jan 16 17:05:04 2013 +0900
@@ -1141,9 +1141,6 @@
 
         foreach ($_SQL as $sql) {
             $sql = str_replace('#group#', $admin_group_id, $sql);
-            if ($use_innodb) {
-                $sql = str_replace('MyISAM', 'InnoDB', $sql);
-            }
             DB_query($sql);
             if (DB_error()) {
                 COM_errorLog('Error creating plugin table', 1);
diff -r 1e8d62d0021f -r ed1753c5dd03 system/databases/mysql.class.php
--- a/system/databases/mysql.class.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/system/databases/mysql.class.php	Wed Jan 16 17:05:04 2013 +0900
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.6                                                               |
+// | Geeklog 2.0                                                               |
 // +---------------------------------------------------------------------------+
 // | mysql.class.php                                                           |
 // |                                                                           |
 // | mysql database class                                                      |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2009 by the following authors:                         |
+// | Copyright (C) 2000-2013 by the following authors:                         |
 // |                                                                           |
 // | Authors: Tony Bibbs, tony AT tonybibbs DOT com                            |
 // +---------------------------------------------------------------------------+
@@ -39,7 +39,7 @@
 class database {
 
     // PRIVATE PROPERTIES
-    
+
     /**
     * @access private
     */
@@ -82,6 +82,10 @@
     var $_mysql_version = 0;
 
     // PRIVATE METHODS
+    /**
+    * @access private
+    */
+    var $_use_innodb = FALSE;
 
     /**
     * Logs messages
@@ -110,6 +114,8 @@
     */
     function _connect()
     {
+        global $_TABLES, $use_innodb;
+
         if ($this->isVerbose()) {
             $this->_errorlog("\n*** Inside database->_connect ***");
         }
@@ -146,6 +152,19 @@
             }
         }
 
+        // Checks if db engine is InnoDB.  During the installation
+        // $_TABLES['vars'] is not yet created, so we use $use_innodb instead.
+        if (isset($use_innodb)) {
+            $this->_use_innodb = (boolean) $use_innodb;
+        } else {
+            $result = $this->dbQuery("SELECT value FROM {$_TABLES['vars']} WHERE (name = 'database_engine')");
+
+            if (($result !== FALSE) AND ($this->dbNumRows($result) == 1)) {
+                $A = $this->dbFetchArray($result, FALSE);
+                $this->_use_innodb = (strcasecmp($A['value'], 'InnoDB') === 0);
+            }
+        }
+
         if ($this->isVerbose()) {
             $this->_errorlog("\n***leaving database->_connect***");
         }
@@ -176,6 +195,7 @@
         $this->_errorlog_fn = $errorlogfn;
         $this->_charset = strtolower($charset);
         $this->_mysql_version = 0;
+        $this->_use_innodb = FALSE;
 
         $this->_connect();
     }
@@ -256,6 +276,38 @@
             $this->_errorlog("\n*** sql to execute is $sql ***");
         }
 
+        // Modifies "CREATE TABLE" SQL
+        if (preg_match('/create\s+table\s/i', $sql)) {
+            $p = strrpos($sql, ')');
+
+            if ($p !== FALSE) {
+                $option = substr($sql, $p + 1);
+
+                if (($option !== '') AND ($option !== FALSE)) {
+                    // Replaces engine type
+                    $sql    = substr($sql, 0, $p + 1);
+                    $option = rtrim($option, " \t\n\r\0\x0b;");
+                    $option = str_ireplace('type', 'ENGINE', $option);
+
+                    if ($this->_use_innodb === TRUE) {
+                        $option = str_ireplace('MyISAM', 'InnoDB', $option);
+                    }
+                } else {
+                    // Appends engine type
+                    $option = ' ENGINE='
+                            . (($this->_use_innodb === TRUE) ? 'InnoDB' : 'MyISAM');
+                }
+
+                // Appends default charset if necessary
+                if (($this->_charset === 'utf-8') AND
+                        !preg_match('/DEFAULT\s+(CHARSET|CHARACTER\s+SET)/i', $option)) {
+                    $option .= ' DEFAULT CHARSET=utf8';
+                }
+
+                $sql .= $option;
+            }
+        }
+
         // Run query
         if ($ignore_errors == 1) {
             $result = @mysql_query($sql,$this->_db);
diff -r 1e8d62d0021f -r ed1753c5dd03 system/databases/mysqli.class.php
--- a/system/databases/mysqli.class.php	Tue Jan 15 11:16:47 2013 -0500
+++ b/system/databases/mysqli.class.php	Wed Jan 16 17:05:04 2013 +0900
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.8                                                               |
+// | Geeklog 2.0                                                               |
 // +---------------------------------------------------------------------------+
 // | mysqli.class.php                                                          |
 // |                                                                           |
 // | mysql database class with MySQLi extension                                |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2011 by the following authors:                         |
+// | Copyright (C) 2000-2013 by the following authors:                         |
 // |                                                                           |
 // | Authors: Tony Bibbs, tony AT tonybibbs DOT com                            |
 // |          Kenji Ito, geeklog AT mystral-kk DOT net                         |
@@ -48,6 +48,7 @@
     private $_errorlog_fn = '';
     private $_charset = '';
     private $_mysql_version = 0;
+    private $_use_innodb = FALSE;
 
     /**
     * Logs messages
@@ -76,6 +77,8 @@
     */
     private function _connect()
     {
+        global $_TABLES, $use_innodb;
+
         if ($this->_verbose) {
             $this->_errorlog("\n*** Inside database->_connect ***");
         }
@@ -110,6 +113,19 @@
             }
         }
 
+        // Checks if db engine is InnoDB.  During the installation
+        // $_TABLES['vars'] is not yet created, so we use $use_innodb instead.
+        if (isset($use_innodb)) {
+            $this->_use_innodb = (boolean) $use_innodb;
+        } else {
+            $result = $this->dbQuery("SELECT value FROM {$_TABLES['vars']} WHERE (name = 'database_engine')");
+
+            if (($result !== FALSE) AND ($this->dbNumRows($result) == 1)) {
+                $A = $this->dbFetchArray($result, FALSE);
+                $this->_use_innodb = (strcasecmp($A['value'], 'InnoDB') === 0);
+            }
+        }
+
         if ($this->_verbose) {
             $this->_errorlog("\n***leaving database->_connect***");
         }
@@ -138,6 +154,7 @@
         $this->_errorlog_fn = $errorlogfn;
         $this->_charset = strtolower($charset);
         $this->_mysql_version = 0;
+        $this->_use_innodb = FALSE;
 
         $this->_connect();
     }
@@ -157,7 +174,7 @@
     */
     public function setVerbose($flag)
     {
-        $this->_verbose = (bool) $flag;
+        $this->_verbose = (boolean) $flag;
     }
 
     /**
@@ -172,7 +189,7 @@
     */
     public function setDisplayError($flag)
     {
-        $this->_display_error = (bool) $flag;
+        $this->_display_error = (boolean) $flag;
     }
 
     /**
@@ -201,7 +218,9 @@
     */
     public function setErrorFunction($functionname)
     {
-        $this->_errorlog_fn = $functionname;
+        if (is_callable($functionname)) {
+            $this->_errorlog_fn = $functionname;
+        }
     }
 
     /**
@@ -221,6 +240,38 @@
             $this->_errorlog("\n*** sql to execute is $sql ***");



More information about the geeklog-cvs mailing list