Skip to content

Commit

Permalink
Require dbname arg to has_table().
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Jul 28, 2010
1 parent 2deeb45 commit 14f6ada
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions README.md
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mytap.sql
Expand Up @@ -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 ;
2 changes: 1 addition & 1 deletion test.sql
Expand Up @@ -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;

0 comments on commit 14f6ada

Please sign in to comment.