|
From: FlorinCB <ory...@us...> - 2008-10-06 04:37:19
|
Update of /cvsroot/mxbb/core/install In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv28207 Modified Files: db_convert.php Log Message: version 1.0.0 working :) Index: db_convert.php =================================================================== RCS file: /cvsroot/mxbb/core/install/db_convert.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** db_convert.php 5 Oct 2008 09:23:59 -0000 1.2 --- db_convert.php 6 Oct 2008 04:34:36 -0000 1.3 *************** *** 28,32 **** $mx_portal_copy = '<b>MX-Publisher Modular System!</b> <br /><br/> MX-Publisher is a fully modular system, portal and CMS, featuring dynamic pages, blocks, and themes, by means of a powerful yet flexible AdminCP. It is the classical phpBB portal add-on, improved and enhanced for every phpBB version released since 2001 (originally named MX-Publisher). <br /><br />Authors: The MX-Publisher Development Team. <br />Please visit <a href="http://www.mx-publisher.com/">www.mx-publisher.com</a> for further information.'; ! define('INSTALLER_VERSION', '0.9.0'); define('INSTALLER_NAME', 'MX-Publisher-DB-Converter'); --- 28,32 ---- $mx_portal_copy = '<b>MX-Publisher Modular System!</b> <br /><br/> MX-Publisher is a fully modular system, portal and CMS, featuring dynamic pages, blocks, and themes, by means of a powerful yet flexible AdminCP. It is the classical phpBB portal add-on, improved and enhanced for every phpBB version released since 2001 (originally named MX-Publisher). <br /><br />Authors: The MX-Publisher Development Team. <br />Please visit <a href="http://www.mx-publisher.com/">www.mx-publisher.com</a> for further information.'; ! define('INSTALLER_VERSION', '1.0.0'); define('INSTALLER_NAME', 'MX-Publisher-DB-Converter'); *************** *** 118,121 **** --- 118,179 ---- } + // Determine mapping database type + switch ($db->sql_layer) + { + case 'mysql': + $this_sql_layer = 'mysql_40'; + break; + + case 'mysql4': + if (version_compare($db->mysql_version, '4.1.3', '>=')) + { + $this_sql_layer = 'mysql_41'; + } + else + { + $this_sql_layer = 'mysql_40'; + } + break; + + case 'mysqli': + $this_sql_layer = 'mysql_41'; + break; + + case 'mssql': + case 'mssql_odbc': + $this_sql_layer = 'mssql'; + break; + + default: + $this_sql_layer = $db->sql_layer; + break; + } + + switch ($db->sql_layer) + { + case 'mysql': + $charset = ' CHARACTER SET latin1;'; + break; + + case 'mysql4': + if (version_compare($db->mysql_version, '4.1.3', '>=')) + { + $charset = ' CHARACTER SET utf8 COLLATE utf8_bin;'; + } + else + { + $charset = ' CHARACTER SET latin1;'; + } + break; + + case 'mysqli': + $charset = ' CHARACTER SET utf8 COLLATE utf8_bin;'; + break; + + default: + $charset = ' CHARACTER SET latin1;'; + } + + if (!($result = $db->sql_query($sql))) { *************** *** 134,138 **** $table = $tables[0]; ! $sql2 = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"; if ( !($result2 = $db->sql_query($sql2)) ) --- 192,196 ---- $table = $tables[0]; ! $sql2 = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_bin"; if ( !($result2 = $db->sql_query($sql2)) ) *************** *** 144,181 **** print "$table changed to UTF-8 successfully.<br>\n"; ! // Now loop through all the fields within this table ! $sql3 = "SHOW COLUMNS FROM $table"; ! if ( !($result3 = $db->sql_query($sql3)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); ! ! break; ! } ! while ( $row3 = $db->sql_fetchrow($result3) ) ! { ! $field_name = $row3[0]; ! $field_type = $row3[1]; ! // Change text based fields ! $skipped_field_types = array('char', 'text', 'blob', 'enum', 'set'); ! foreach ( $skipped_field_types as $type ) ! { ! if ( strpos($field_type, $type) !== false ) ! { ! $sql4 = "ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type CHARACTER SET utf8 COLLATE utf8_bin"; ! if ( !($result4 = $db->sql_query($sql4)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql4); ! break 3; ! } ! print "---- $field_name changed to UTF-8 successfully.<br>\n"; ! } ! } ! } ! print "<hr>\n"; } --- 202,377 ---- print "$table changed to UTF-8 successfully.<br>\n"; + + + switch ($this_sql_layer) + { + case 'mysql_40': + case 'mysql_41': + $sql3 = "SHOW COLUMNS + FROM $table"; + if ( !($result3 = $db->sql_query($sql3)) ) + { + install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); + + break; + } + break; ! // PostgreSQL has a way of doing this in a much simpler way but would ! // not allow us to support all versions of PostgreSQL ! case 'postgres': ! $sql3 = "SELECT a.attname ! FROM pg_class c, pg_attribute a ! WHERE c.relname = '{$table}' ! AND a.attnum > 0 ! AND a.attrelid = c.oid"; ! if ( !($result3 = $db->sql_query($sql3)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); ! ! break; ! } ! break; ! // same deal with PostgreSQL, we must perform more complex operations than ! // we technically could ! case 'mssql': ! $sql3 = "SELECT c.name ! FROM syscolumns c ! LEFT JOIN sysobjects o ON c.id = o.id ! WHERE o.name = '{$table}'"; ! if ( !($result3 = $db->sql_query($sql3)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); ! ! break; ! } ! break; ! ! case 'oracle': ! $sql3 = "SELECT column_name ! FROM user_tab_columns ! WHERE table_name = '{$table}'"; ! if ( !($result3 = $db->sql_query($sql3)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); ! ! break; ! } ! break; ! ! case 'firebird': ! $sql3 = "SELECT RDB\$FIELD_NAME as FNAME ! FROM RDB\$RELATION_FIELDS ! WHERE RDB\$RELATION_NAME = '{$table}'"; ! if ( !($result3 = $db->sql_query($sql3)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); ! ! break; ! } ! break; ! ! // ugh, SQLite ! case 'sqlite': ! $sql3 = "SELECT sql ! FROM sqlite_master ! WHERE type = 'table' ! AND name = '{$table}'"; ! if ( !($result3 = $db->sql_query($sql3)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql3); ! ! break; ! } ! break; ! } ! ! while ($row3 = $db->sql_fetchrow($result3) ) ! { ! $field_types = array(); ! ! $field_types[] = current($row3); ! ! $db->sql_freeresult($result3); ! ! $field_type = $field_types[1]; ! ! switch ($this_sql_layer) ! { ! case 'mysql_40': ! case 'mysql_41': ! ! // lower case just in case ! $field_name = strtolower($row3['Field']); ! $field_type = strtolower($row3['Type']); ! break; ! ! case 'postgres': ! // lower case just in case ! $field_name = strtolower($row3['attname']); ! $field_type = strtolower($row3['atttype']); ! break; ! ! case 'mssql': ! // lower case just in case ! $field_name = strtolower($row3['name']); ! $field_type = strtolower($row3['type']); ! break; ! ! case 'oracle': ! // lower case just in case ! $field_name = strtolower($row3['column_name']); ! $field_type = strtolower($row3['column_type']); ! break; ! ! case 'firebird': ! // lower case just in case ! $field_name = strtolower($row3['fname']); ! $field_type = strtolower($row3['ftype']); ! break; ! ! case 'sqlite': ! ! preg_match('#\((.*)\)#s', $row['sql'], $matches); ! ! $cols = trim($matches[1]); ! $col_array = preg_split('/,(?![\s\w]+\))/m', $cols); ! ! foreach ($col_array as $declaration) ! { ! $entities = preg_split('#\s+#', trim($declaration)); ! if ($entities[0] == 'PRIMARY') ! { ! continue; ! } ! ! // lower case just in case ! $field_name = strtolower($entities[0]); ! $field_type = strtolower($entities[1]); ! } ! ! break; ! } ! // Change text based fields ! $skipped_field_types = array('char', 'text', 'blob', 'enum', 'set'); ! foreach ( $skipped_field_types as $type ) ! { ! if ( strpos($field_type, $type) !== false ) ! { ! $sql4 = "ALTER TABLE $table CHANGE `$field_name` `$field_name` $field_type " . $charset; ! if ( !($result4 = $db->sql_query($sql4)) ) ! { ! install_die('SQL Error: ' . 'Line: ' . __LINE__ . ' File: ' . __FILE__ . ' Query: ' . $sql4); ! break 3; ! } ! print "---- $field_name changed to UTF-8 successfully.<br>\n"; ! } ! } ! } ! print "<hr>\n"; } |