summaryrefslogtreecommitdiff
path: root/test/it_dbi.t
diff options
context:
space:
mode:
Diffstat (limited to 'test/it_dbi.t')
-rwxr-xr-xtest/it_dbi.t45
1 files changed, 31 insertions, 14 deletions
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 4b0c9a8..8528a86 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -3,19 +3,35 @@
# Tests for it_dbi.class
+$opts = it::getopt("
+ Usage: it_dbi.t [OPTIONS]
+ --db=S DB to use [lib_search_ch]
+ --user=S User
+ --pw=S Password
+ --subclass=S Subclass to test [it_dbi]
+");
+
# Initialize DB
-$db = ['db' => "lib_search_ch", 'safety' => 0];
-$dbi = new it_dbi($db);
-$dbi->query('create temporary table it_dbi_test (
- ID int not null auto_increment,
+$db = it::filter_keys($opts, 'db,user,pw');# + ['safety' => 0];
+$dbi = new $opts['subclass']($db);
+
+$opts['subclass']::createclasses();
+$tables = $dbi->tables();
+ok(count($tables) > 0, 'there are some existing tables in the db');
+ok(new $tables[0], 'classes for tables exist');
+
+$autoid = $opts['subclass'] == 'it_dbi_postgres' ? '"ID" Serial' : 'ID int not null auto_increment';
+$dyncols = $opts['subclass'] == 'it_dbi_postgres' ? 'dyncols JSONB' : 'dyncols JSON';
+$primarykey = $dbi->escape_name('ID');
+$dbi->query("create temporary table it_dbi_test (
+ $autoid,
x int,
foo varchar(42),
- dyncols JSON,
- primary key(ID)
-);');
-it_dbi::createclass(['table' => "it_dbi_test", 'forcecreate' => true]);
+ $dyncols,
+ primary key($primarykey)
+);");
+$opts['subclass']::createclass(['table' => "it_dbi_test", 'forcecreate' => true]);
-ok(new T_sl_accesscount, 'classes for tables exist');
$record = new it_dbi_test;
$record->insert(['x' => 42, 'foo' => null]);
@@ -283,14 +299,15 @@ $record->select(['foo' => "\xc3\x28"]);
# Test field localization feature
-$dbi->query('create temporary table it_dbi_testlocalized (
- ID int not null auto_increment,
+$dbi->query("create temporary table it_dbi_testlocalized (
+ $autoid,
foobar_de varchar(42),
foobar_fr varchar(42),
- primary key(ID)
-);');
+ primary key($primarykey)
+);");
+
-$record = new it_dbi($db + ['table' => "it_dbi_testlocalized"]);
+$record = new $opts['subclass']($db + ['table' => "it_dbi_testlocalized"]);
$record->insert(['foobar_de' => "deutsch", 'foobar_fr' => "franz"]);
$record->insert(['foobar_de' => "deutsch2", 'foobar_fr' => "franz2"]);