Author: simon
Date: Fri Dec 5 17:19:44 2008
New Revision: 33531
Modified:
trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm
trunk/ext/SQLite3/t/test.p6
Log:
Fixes to column-lookup code, and some more tests
Modified: trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm
==============================================================================
--- trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm (original)
+++ trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm Fri Dec 5 17:19:44 2008
@@ -60,11 +60,11 @@
my method fillColumns () {
# Won't work in any useful way at the moment
- #my $cn; my $i =0;
- #while ($cn = SQLite::column_name($stHandle, $i)) {
- # %columns{$cn} = $i++;
- # push @columns, $cn;
- #}
+ my $cn; my $i =0;
+ while ($cn = SQLite::column_name($stHandle, $i)) {
+ %columns{$cn} = $i++;
+ push @columns, $cn;
+ }
}
method next () {
@@ -84,14 +84,7 @@
return self!errorCheck();
}
- method lookupCol ($name) {
- # This should be a hash but ...
- my $i = 0; my $cn;
- while ($cn = SQLite::column_name($stHandle, $i)) {
- if $cn eq $name { return $i }
- }
- return -1;
- }
+ method lookupCol ($name) { return %columns{$name} // -1; }
method getCol ($num) { return SQLite::column_text($stHandle, $num); }
}
Modified: trunk/ext/SQLite3/t/test.p6
==============================================================================
--- trunk/ext/SQLite3/t/test.p6 (original)
+++ trunk/ext/SQLite3/t/test.p6 Fri Dec 5 17:19:44 2008
@@ -1,18 +1,19 @@
-# Andy the time-strapped test fairy says:
-# If this were Perl 5, I'd put in tests roughly like the following:
use DBDI;
use Test;
-plan 5;
+plan 7;
my $conn = DBDI::DriverManager.getConnection("dbdi:SQLite3:test.db", "", "");
isa_ok($conn, DBDI::Driver::SQLite3);
my $stm = $conn.createStatement();
isa_ok($stm, DBDI::Statement);
my $rs = $stm.executeUpdate("CREATE TABLE foo (bar, baz)");
-### ok( $rs->success, 'Created foo OK');
### I'd also add a test that a SELECT works and returns 0 rows
+try {
+ $rs = $stm.executeUpdate("CREATE TABLE foo (bar, baz)");
+};
+ok($! eq "table foo already exists", "Can't create again (and did create first
time)");
my $stm = $conn.prepareStatement("INSERT INTO foo (bar, baz) VALUES (?, ?)");
isa_ok( $stm, DBDI::PreparedStatement);
$stm.bind(1, 123);
@@ -25,7 +26,10 @@
while ($rs.next()) {
ok(($rs.getCol("baz") eq "Thingy"), "baz == Thingy");
ok(($rs.getCol(1) = 123), "col1 == 123");
- #say $rs.getCol("bas"); #segfaults
+ try {
+ $rs.getCol("bas");
+ };
+ ok($! eq "Couldn't find column bas", "Non-existent columns");
}
# vim: ft=perl6: