diff options
author | Christian Schneider | 2008-06-26 15:08:57 +0000 |
---|---|---|
committer | Christian Schneider | 2008-06-26 15:08:57 +0000 |
commit | abfc7d5e3419e6f317a6366b7e4c273b0465ed2e (patch) | |
tree | 50fdafa7efa4c82494ddeefc4be1d9a5ee915993 /it_dbi.class | |
parent | 156228c730ac944b751f6e8bb7d463c2fee3763c (diff) | |
download | itools-abfc7d5e3419e6f317a6366b7e4c273b0465ed2e.tar.gz itools-abfc7d5e3419e6f317a6366b7e4c273b0465ed2e.tar.bz2 itools-abfc7d5e3419e6f317a6366b7e4c273b0465ed2e.zip |
Replaced deprecated mysql_list_tables by SHOW TABLES
Constructor of generated classes now take varargs too and added tests for it
Diffstat (limited to 'it_dbi.class')
-rw-r--r-- | it_dbi.class | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/it_dbi.class b/it_dbi.class index 396ff84..709ddee 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -109,13 +109,13 @@ function createclasses($p = array()) $p += $dbi->_p; $p['dbid'] = "{$p['user']}@{$p['server']}:{$p['db']}"; - $dbi->_connect($p); - if (!($tables = mysql_list_tables($p['db'], $dbi->_link))) - $dbi->_fatal("createclasses(): can't list on tables \"{$p['db']}\""); - - for ($i = 0; $i < mysql_num_rows($tables); $i++) - it_dbi::createclass(array('table' => mysql_tablename($tables, $i)) + $p); + for ($res = $dbi->query('SHOW TABLES'); $row = mysql_fetch_row($res);) + { + # Either create class in autoloader or manually just below + if (!class_exists($row[0])) + it_dbi::createclass(array('table' => $row[0]) + $p); + } } @@ -139,7 +139,7 @@ function createclass($p) $dbi->_tables[$dbid][$row[0]] = true; } - if ($dbi->_tables[$dbid][$p['table']]) # Do not generate classes for non-existant tables + if ($p['forcecreate'] || $dbi->_tables[$dbid][$p['table']]) # Do not generate classes for non-existant tables (can be overridden by forcecreate => true, used in tests/it_dbi.t) { $classname = $p['classprefix'] . $p['table']; @@ -147,12 +147,15 @@ function createclass($p) { $code = "class $classname extends it_dbi { - function $classname(\$query = null, \$p = array()) + function $classname(/* $query ... */) { - if (\$p) - it::error(array('title' => 'Deprecated use of \$p parameter for $classname', 'body' => var_export(\$p, true), 'backtraceskip' => 1)); - \$p += " . var_export($p, true) . "; - \$this->it_dbi(\$p, \$query); + \$args = func_get_args(); + \$query = array_shift(\$args); # Preserve type (scalar/array) in single parameter case + + foreach (\$args as \$arg) + \$query = array_merge((array)\$query, (array)\$arg); + + \$this->it_dbi(" . var_export($p, true) . ", \$query); } }"; |