From 5e7eda37c44648e5773d0f333eea07cab73c4056 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Mon, 3 Sep 2012 04:34:17 +0000 Subject: [PATCH] error cases --- dbdimp.c | 4 ++-- t/51_table_column_metadata.t | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index 9624c7a..01d8970 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -1422,11 +1422,11 @@ HV* sqlite_db_table_column_metadata(pTHX_ SV *dbh, SV *dbname, SV *tablename, SV /* dbname may be NULL but (table|column)name may not be NULL */ if (!tablename || !SvPOK(tablename)) { sqlite_error(dbh, -2, "table_column_metadata requires a table name"); - return FALSE; + return metadata; } if (!columnname || !SvPOK(columnname)) { sqlite_error(dbh, -2, "table_column_metadata requires a column name"); - return FALSE; + return metadata; } #ifdef SQLITE_ENABLE_COLUMN_METADATA diff --git a/t/51_table_column_metadata.t b/t/51_table_column_metadata.t index 0a0752e..d94a84f 100644 --- a/t/51_table_column_metadata.t +++ b/t/51_table_column_metadata.t @@ -10,9 +10,9 @@ use t::lib::Test qw/connect_ok @CALL_FUNCS/; use Test::More; use Test::NoWarnings; -plan tests => 11 * @CALL_FUNCS + 1; +plan tests => 15 * @CALL_FUNCS + 1; for my $call_func (@CALL_FUNCS) { - my $dbh = connect_ok(); + my $dbh = connect_ok(RaiseError => 1); $dbh->do('create table foo (id integer primary key autoincrement, "name space", unique_col integer unique)'); { @@ -32,4 +32,20 @@ for my $call_func (@CALL_FUNCS) { ok !$data->{primary}, "name space is not a primary key"; ok !$data->{not_null}, "name space is not null"; } + + # exceptions + { + local $SIG{__WARN__} = sub {}; + eval { $dbh->$call_func(undef, undef, 'name space', 'table_column_metadata') }; + ok $@, "successfully died when tablename is undef"; + + eval { $dbh->$call_func(undef, '', 'name space', 'table_column_metadata') }; + ok !$@, "not died when tablename is an empty string"; + + eval { $dbh->$call_func(undef, 'foo', undef, 'table_column_metadata') }; + ok $@, "successfully died when columnname is undef"; + + eval { $dbh->$call_func(undef, 'foo', '', 'table_column_metadata') }; + ok !$@, "not died when columnname is an empty string"; + } }