summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2007-09-30 19:23:31 +0000
committerChristian Schneider2007-09-30 19:23:31 +0000
commit0cc945636e6c8c1a967578086696ada2caad4494 (patch)
tree358f0b1d332149adcc85ae80615857e27b36d96e
parent4878ef5f12e7d9e107cd518330b2588fea15b9dd (diff)
downloaditools-0cc945636e6c8c1a967578086696ada2caad4494.tar.gz
itools-0cc945636e6c8c1a967578086696ada2caad4494.tar.bz2
itools-0cc945636e6c8c1a967578086696ada2caad4494.zip
Do not create class for non-existant tables
-rw-r--r--it_dbi.class33
1 files changed, 23 insertions, 10 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 585856e..95eb18a 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -116,21 +116,34 @@ function createclass($p)
if (!is_array($p))
$p = array('table' => $p);
- $classname = $p['classprefix'] . $p['table'];
+ # Make sure singleton exists
+ $dbi = $GLOBALS['it_dbi'] ? $GLOBALS['it_dbi'] : new it_dbi(array('table' => null) + $p);
+ $db = $dbi->_p['db'];
- if (substr($classname, 0, 4) != 'PMA_') # It is designed behaviour that an error is generated if this class already exists!
+ if (!isset($dbi->_tables[$db]))
{
- $code = "class $classname extends it_dbi
+ for ($res = $dbi->query('SHOW TABLES'); $row = mysql_fetch_row($res);)
+ $dbi->_tables[$db][] = $row[0];
+ }
+
+ if (in_array($p['table'], $dbi->_tables[$db])) # Do not generate classes for non-existant tables
+ {
+ $classname = $p['classprefix'] . $p['table'];
+
+ if (substr($classname, 0, 4) != 'PMA_') # It is designed behaviour that an error is generated if this class already exists!
{
- function $classname(\$query = null, \$p = array())
+ $code = "class $classname extends it_dbi
{
- \$p += " . var_export($p, true) . ";
- \$this->it_dbi(\$p, \$query);
- }
- }";
+ function $classname(\$query = null, \$p = array())
+ {
+ \$p += " . var_export($p, true) . ";
+ \$this->it_dbi(\$p, \$query);
+ }
+ }";
- debug("it_dbi::createclass('{$p['table']}'): creating class $classname", 5);
- eval($code);
+ debug("it_dbi::createclass('{$p['table']}'): creating class $classname", 5);
+ eval($code);
+ }
}
}