Permalink
Browse files

[SQLite] implement column_names

  • Loading branch information...
1 parent 2534dea commit ce8eda8837a58b401b1d77903ea6050f89592c74 @moritz moritz committed May 2, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/DBDish/SQLite.pm6
View
11 lib/DBDish/SQLite.pm6
@@ -80,6 +80,7 @@ sub sqlite3_reset(OpaquePointer) returns Int is native('libsqlite3') { ... }
sub sqlite3_column_text(OpaquePointer, Int) returns Str is native('libsqlite3') { ... }
sub sqlite3_finalize(OpaquePointer) returns Int is native('libsqlite3') { ... }
sub sqlite3_column_count(OpaquePointer) returns Int is native('libsqlite3') { ... }
+sub sqlite3_column_name(OpaquePointer, Int) returns Str is native('libsqlite3') { * }
class DBDish::SQLite::StatementHandle does DBDish::StatementHandle {
@@ -89,6 +90,7 @@ class DBDish::SQLite::StatementHandle does DBDish::StatementHandle {
has $.dbh;
has Int $!row_status;
has @!mem_rows;
+ has @!column_names;
method !handle-error($status) {
return if $status == SQLITE_OK;
@@ -120,6 +122,15 @@ class DBDish::SQLite::StatementHandle does DBDish::StatementHandle {
$rows == 0 ?? '0E0' !! $rows;
}
+ method column_names {
+ unless @!column_names {
+ my Int $count = sqlite3_column_count($!statement_handle);
+ @!column_names.push: sqlite3_column_name($!statement_handle, $_)
+ for ^$count;
+ }
+ @!column_names;
+ }
+
method fetchrow {
my @row;
die 'fetchrow_array without prior execute' unless $!row_status.defined;

0 comments on commit ce8eda8

Please sign in to comment.