cvs: pear /MDB2 package_sqlite.php /MDB2/MDB2/Driver/Reverse sqlite.php
[email protected] ("Lorenzo Alberton")
| Newsgroups | php.pear.cvs |
|---|---|
| Message-ID | <cvsquipo1209810614@cvsserver> |
quipo Sat May 3 10:30:14 2008 UTC
Modified files:
/pear/MDB2/MDB2/Driver/Reverse sqlite.php
/pear/MDB2 package_sqlite.php
Log:
- fixed bug #13815: incomplete regexp in the Reverse module
- handle SQL comments
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/sqlite.php?r1=1.79&r2=1.80&diff_format=u
Index: pear/MDB2/MDB2/Driver/Reverse/sqlite.php
diff -u pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.79 pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.80
--- pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.79 Wed Mar 5 11:08:53 2008
+++ pear/MDB2/MDB2/Driver/Reverse/sqlite.php Sat May 3 10:30:14 2008
@@ -43,7 +43,7 @@
// | Lorenzo Alberton <[email protected]> |
// +----------------------------------------------------------------------+
//
-// $Id: sqlite.php,v 1.79 2008/03/05 11:08:53 quipo Exp $
+// $Id: sqlite.php,v 1.80 2008/05/03 10:30:14 quipo Exp $
//
require_once 'MDB2/Driver/Reverse/Common.php';
@@ -57,6 +57,25 @@
*/
class MDB2_Driver_Reverse_sqlite extends MDB2_Driver_Reverse_Common
{
+ /**
+ * Remove SQL comments from the field definition
+ *
+ * @access private
+ */
+ function _removeComments($sql) {
+ $lines = split("\n", $sql);
+ foreach ($lines as $k => $line) {
+ $pieces = explode('--', $line);
+ if (count($pieces) > 1 && (substr_count($pieces[0], '\'') % 2) == 0) {
+ $lines[$k] = substr($line, 0, strpos($line, '--'));
+ }
+ }
+ return implode("\n", $lines);
+ }
+
+ /**
+ *
+ */
function _getTableColumns($sql)
{
$db =& $this->getDBInstance();
@@ -68,6 +87,7 @@
$column_def = substr($sql, $start_pos+1, $end_pos-$start_pos-1);
// replace the decimal length-places-separator with a colon
$column_def = preg_replace('/(\d),(\d)/', '\1:\2', $column_def);
+ $column_def = $this->_removeComments($column_def);
$column_sql = split(',', $column_def);
$columns = array();
$count = count($column_sql);
@@ -75,7 +95,7 @@
return $db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
'unexpected empty table column definition list', __FUNCTION__);
}
- $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( UNSIGNED)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?$/i';
+ $regexp = '/^\s*([^\s]+) +(CHAR|VARCHAR|VARCHAR2|TEXT|BOOLEAN|SMALLINT|INT|INTEGER|DECIMAL|BIGINT|DOUBLE|FLOAT|DATETIME|DATE|TIME|LONGTEXT|LONGBLOB)( ?\(([1-9][0-9]*)(:([1-9][0-9]*))?\))?( NULL| NOT NULL)?( UNSIGNED)?( NULL| NOT NULL)?( PRIMARY KEY)?( DEFAULT (\'[^\']*\'|[^ ]+))?( NULL| NOT NULL)?( PRIMARY KEY)?(\s*\-\-.*)?$/i';
$regexp2 = '/^\s*([^ ]+) +(PRIMARY|UNIQUE|CHECK)$/i';
for ($i=0, $j=0; $i<$count; ++$i) {
if (!preg_match($regexp, trim($column_sql[$i]), $matches)) {
@@ -93,14 +113,14 @@
if (isset($matches[6]) && strlen($matches[6])) {
$columns[$j]['decimal'] = $matches[6];
}
- if (isset($matches[7]) && strlen($matches[7])) {
+ if (isset($matches[8]) && strlen($matches[8])) {
$columns[$j]['unsigned'] = true;
}
- if (isset($matches[8]) && strlen($matches[8])) {
+ if (isset($matches[9]) && strlen($matches[9])) {
$columns[$j]['autoincrement'] = true;
}
- if (isset($matches[10]) && strlen($matches[10])) {
- $default = $matches[10];
+ if (isset($matches[12]) && strlen($matches[12])) {
+ $default = $matches[12];
if (strlen($default) && $default[0]=="'") {
$default = str_replace("''", "'", substr($default, 1, strlen($default)-2));
}
@@ -109,8 +129,12 @@
}
$columns[$j]['default'] = $default;
}
- if (isset($matches[11]) && strlen($matches[11])) {
- $columns[$j]['notnull'] = ($matches[11] === ' NOT NULL');
+ if (isset($matches[7]) && strlen($matches[7])) {
+ $columns[$j]['notnull'] = ($matches[7] === ' NOT NULL');
+ } else if (isset($matches[9]) && strlen($matches[9])) {
+ $columns[$j]['notnull'] = ($matches[9] === ' NOT NULL');
+ } else if (isset($matches[13]) && strlen($matches[13])) {
+ $columns[$j]['notnull'] = ($matches[13] === ' NOT NULL');
}
++$j;
}
http://cvs.php.net/viewvc.cgi/pear/MDB2/package_sqlite.php?r1=1.120&r2=1.121&diff_format=u
Index: pear/MDB2/package_sqlite.php
diff -u pear/MDB2/package_sqlite.php:1.120 pear/MDB2/package_sqlite.php:1.121
--- pear/MDB2/package_sqlite.php:1.120 Sat Mar 15 09:49:28 2008
+++ pear/MDB2/package_sqlite.php Sat May 3 10:30:14 2008
@@ -6,6 +6,7 @@
$version = 'XXX';
$state = 'beta';
$notes = <<<EOT
+- fixed bug #13815: incomplete regexp in the Reverse module
note:
open todo items: