Front page | perl.cvs.parrot |
Postings from December 2008
[svn:parrot] r33507 - in trunk/ext/SQLite3: . DBDI/Driver
From:
simon
Date:
December 5, 2008 04:53
Subject:
[svn:parrot] r33507 - in trunk/ext/SQLite3: . DBDI/Driver
Message ID:
20081205125344.95D1ACB9AF@x12.develooper.com
Author: simon
Date: Fri Dec 5 04:53:43 2008
New Revision: 33507
Modified:
trunk/ext/SQLite3/DBDI.pm
trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm
trunk/ext/SQLite3/SQLite3.pir
Log:
And now we can do selects and pull data out of them. Which is pretty much all you need, really.
Modified: trunk/ext/SQLite3/DBDI.pm
==============================================================================
--- trunk/ext/SQLite3/DBDI.pm (original)
+++ trunk/ext/SQLite3/DBDI.pm Fri Dec 5 04:53:43 2008
@@ -23,5 +23,13 @@
class DBDI::ResultSet {
has $.statement;
- method next { $.statement.next(); }
+ method next() { return $.statement.next(); }
+ multi method getCol(Num $col) {
+ $.statement.getCol($col);
+ }
+ multi method getCol(Str $col) {
+ my $n = $.statement.lookupCol($col);
+ if ($n > -1) { return self.getCol($n) }
+ die "Couldn't find column "~$col;
+ }
}
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 04:53:43 2008
@@ -28,12 +28,12 @@
method executeQuery($sql) {
my $temp_statement = $connection.prepareStatement($sql);
- return DBDI::ResultSet(:statement($temp_statement));
+ return DBDI::ResultSet.new(:statement($temp_statement));
}
method executeUpdate($sql) {
my $temp_statement = $connection.prepareStatement($sql);
- $temp_statement.step();
+ $temp_statement.next();
$temp_statement.finalize();
}
}
@@ -42,10 +42,12 @@
has $connection;
has $stHandle;
has @columns;
+ has %columns;
+ has @bind_params;
has $!sql;
method executeUpdate() {
- self.step();
+ self.next();
self.finalize();
}
@@ -56,18 +58,40 @@
return $res;
}
- method step () {
+ 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;
+ #}
+ }
+
+ method next () {
SQLite::step($stHandle);
- return self!errorCheck();
+ if (! +@columns) { self!fillColumns(); }
+ my $res = self!errorCheck();
+ return $res == 100;
}
method finalize () {
SQLite::finalize($stHandle);
return self!errorCheck();
}
- method setColumn($num, $data) {
- @columns[$num] = $data;
+ method bind($num, $data) {
+ @bind_params[$num] = $data;
SQLite::bind_text($stHandle, $num, $data, chars($data), -1);
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 getCol ($num) { return SQLite::column_text($stHandle, $num); }
}
Modified: trunk/ext/SQLite3/SQLite3.pir
==============================================================================
--- trunk/ext/SQLite3/SQLite3.pir (original)
+++ trunk/ext/SQLite3/SQLite3.pir Fri Dec 5 04:53:43 2008
@@ -57,6 +57,10 @@
push sqlite_funcs, 'ipid'
push sqlite_funcs, 'bind_text'
push sqlite_funcs, 'ipitii'
+ push sqlite_funcs, 'column_name'
+ push sqlite_funcs, 'tpi'
+ push sqlite_funcs, 'column_text'
+ push sqlite_funcs, 'tpi'
function = dlfunc libname, 'sqlite3_open', 'itV'
set_global 'open_raw', function
-
[svn:parrot] r33507 - in trunk/ext/SQLite3: . DBDI/Driver
by simon