From 14f6adaba224344e32013430736189ed94c028d2 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Tue, 27 Jul 2010 17:06:12 -0700 Subject: [PATCH] Require dbname arg to `has_table()`. --- README.md | 19 +++++++++---------- mytap.sql | 6 +++--- test.sql | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 8ac7929..bcfc18a 100644 --- a/README.md +++ b/README.md @@ -219,19 +219,18 @@ The Schema Things Need to make sure that your database is designed just the way you think it should be? Use these test functions and rest easy. -A note on comparisons: pgTAP uses a simple equivalence test (`=`) to compare +A note on comparisons: MyTAP uses a simple equivalence test (`=`) to compare +identifier names. -### `has_table( table, description )` ### -### `has_table( table )` ### +### `has_table( database, table, description )` ### - SELECT has_table( - 'sometable', - 'I got sometable' - ); + SELECT has_table(DATABASE(), 'sometable', 'I got sometable'); -This function tests whether or not a table exists in the database. The first -argument is a table name and the second is the (optional) test description. If -you omit the test description, it will be set to "Table `:table` should +This function tests whether or not a table exists in a database. The first +argument is a database name, the second is a table name, and the third is the +test description. If you want to test for a table in the current database, use +the `DATABASE()` function to specify the current databasen name. If you omit +the test description, it will be set to "Table ':database'.':table' should exist". No Test for the Wicked diff --git a/mytap.sql b/mytap.sql index 1344e9b..ace7445 100644 --- a/mytap.sql +++ b/mytap.sql @@ -326,16 +326,16 @@ BEGIN END // DROP FUNCTION IF EXISTS has_table; -CREATE FUNCTION has_table(tname TEXT) RETURNS TEXT +CREATE FUNCTION has_table(dbname TEXT, tname TEXT) RETURNS TEXT BEGIN DECLARE ret BOOLEAN; SELECT 1 INTO ret FROM information_schema.tables WHERE table_name = tname - AND table_schema = DATABASE() + AND table_schema = dbname AND table_type <> 'SYSTEM VIEW'; - RETURN ok(ret, concat('Table ', quote(tname), ' should exist')); + RETURN ok(ret, concat('Table ', quote(dbname), '.', quote(tname), ' should exist')); END // DELIMITER ; diff --git a/test.sql b/test.sql index db59393..412d1dc 100644 --- a/test.sql +++ b/test.sql @@ -27,7 +27,7 @@ select tap.diag('hey\nthere'); SELECT tap.ok(maxlen > 1, concat(character_set_name, ' should have length > 1')) FROM information_schema.character_sets; -SELECT tap.has_table('__tcache__'); +SELECT tap.has_table('tap', '__tcache__'); CALL tap.finish(); ROLLBACK;