Front page | perl.cvs.parrot |
Postings from December 2008
[svn:parrot] r33503 - in trunk: . config/gen/call_list ext/SQLite3 ext/SQLite3/DBDI ext/SQLite3/DBDI/Driver
From:
simon
Date:
December 5, 2008 02:18
Subject:
[svn:parrot] r33503 - in trunk: . config/gen/call_list ext/SQLite3 ext/SQLite3/DBDI ext/SQLite3/DBDI/Driver
Message ID:
20081205101810.4DB06CB9AF@x12.develooper.com
Author: simon
Date: Fri Dec 5 02:18:07 2008
New Revision: 33503
Added:
trunk/ext/SQLite3/DBDI/
trunk/ext/SQLite3/DBDI.pm
trunk/ext/SQLite3/DBDI/Driver/
trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm
Modified:
trunk/MANIFEST
trunk/config/gen/call_list/misc.in
trunk/ext/SQLite3/SQLite3.pir
Log:
Some more work on the DBDI; by no means official, (yet) but submitting it so it doesn't get lost.
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Fri Dec 5 02:18:07 2008
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Dec 4 22:47:11 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Fri Dec 5 10:16:51 2008 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -914,6 +914,8 @@
ext/Parrot-Embed/tools/check_embed_coverage.pl []
ext/Parrot-Embed/tools/write_typemap.pl []
ext/Parrot-Embed/typemap []
+ext/SQLite3/DBDI.pm []
+ext/SQLite3/DBDI/Driver/SQLite3.pm []
ext/SQLite3/Makefile.PL []
ext/SQLite3/Makefile.in []
ext/SQLite3/SQLite3.pir []
Modified: trunk/config/gen/call_list/misc.in
==============================================================================
--- trunk/config/gen/call_list/misc.in (original)
+++ trunk/config/gen/call_list/misc.in Fri Dec 5 02:18:07 2008
@@ -386,3 +386,5 @@
# Testing SQLite
i tV
i ptiVp
+i pid
+i pitii
Added: trunk/ext/SQLite3/DBDI.pm
==============================================================================
--- (empty file)
+++ trunk/ext/SQLite3/DBDI.pm Fri Dec 5 02:18:07 2008
@@ -0,0 +1,27 @@
+class DBDI::DriverManager {
+ method getConnection($url, $login, $password) {
+ my $c1 = $url.index(":");
+ my $schema = substr($url, 0, $c1);
+ if ($schema ne "dbdi") { die "Unknown schema "~$schema }
+ my $rurl = substr($url, $c1+1);
+ #say "Remainder was "~$rurl;
+
+ my $c2 = $rurl.index(":");
+ my $driver = "DBDI::Driver::"~substr($rurl, 0, $c2);
+ eval "use "~$driver;
+ if ($!) { die "Couldn't load "~$driver~": "~$!; }
+
+ my $r = substr($rurl, $c2+1);
+ return (eval $driver).getConnection($r, $login, $password);
+ #return ::($driver).getConnection($r, $login, $password);
+ }
+}
+
+class DBDI::Driver { }
+class DBDI::Statement { }
+class DBDI::PreparedStatement { }
+
+class DBDI::ResultSet {
+ has $.statement;
+ method next { $.statement.next(); }
+}
Added: trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm
==============================================================================
--- (empty file)
+++ trunk/ext/SQLite3/DBDI/Driver/SQLite3.pm Fri Dec 5 02:18:07 2008
@@ -0,0 +1,73 @@
+use SQLite3;
+use DBDI;
+
+class DBDI::Driver::SQLite3 is DBDI::Driver {
+ has $dbHandle;
+ # This bit of hackery is to get around the fact that you can't use
+ # $foo = <pointer>, only $foo := <pointer>
+ method dbHandle { return $dbHandle }
+
+ method getConnection ($db, $username, $password) {
+ my $o = DBDI::Driver::SQLite3.new(:dbHandle(SQLite::open($db)));
+ return $o;
+ }
+
+ method createStatement() {
+ return DBDI::Statement::SQLite3.new(:connection(self));
+ }
+
+ method prepareStatement($sql) {
+ my $sth := SQLite::prepare($.dbHandle, $sql);
+ my $p = DBDI::PreparedStatement::SQLite3.new(:connection(self), :sql($sql), :stHandle($sth));
+ return $p;
+ }
+}
+
+class DBDI::Statement::SQLite3 is DBDI::Statement {
+ has $connection;
+
+ method executeQuery($sql) {
+ my $temp_statement = $connection.prepareStatement($sql);
+ return DBDI::ResultSet(:statement($temp_statement));
+ }
+
+ method executeUpdate($sql) {
+ my $temp_statement = $connection.prepareStatement($sql);
+ $temp_statement.step();
+ $temp_statement.finalize();
+ }
+}
+
+class DBDI::PreparedStatement::SQLite3 is DBDI::PreparedStatement {
+ has $connection;
+ has $stHandle;
+ has @columns;
+ has $!sql;
+
+ method executeUpdate() {
+ self.step();
+ self.finalize();
+ }
+
+ my method errorCheck () {
+ my $res = SQLite::errcode($connection.dbHandle);
+ my $res_c = SQLite::errmsg($connection.dbHandle);
+ if ($res > 0 and $res < 100) { die $res_c }
+ return $res;
+ }
+
+ method step () {
+ SQLite::step($stHandle);
+ return self!errorCheck();
+ }
+ method finalize () {
+ SQLite::finalize($stHandle);
+ return self!errorCheck();
+ }
+
+ method setColumn($num, $data) {
+ @columns[$num] = $data;
+ SQLite::bind_text($stHandle, $num, $data, chars($data), -1);
+ return self!errorCheck();
+ }
+}
Modified: trunk/ext/SQLite3/SQLite3.pir
==============================================================================
--- trunk/ext/SQLite3/SQLite3.pir (original)
+++ trunk/ext/SQLite3/SQLite3.pir Fri Dec 5 02:18:07 2008
@@ -35,24 +35,51 @@
.sub '_sqlite_init' :load
.local pmc libname
.local pmc function
+ .local pmc sqlite_funcs
libname = loadlib 'libsqlite3'
set_global '_sqlite3', libname
+ sqlite_funcs = new 'ResizableStringArray'
+ push sqlite_funcs, 'step'
+ push sqlite_funcs, 'ip'
+ push sqlite_funcs, 'finalize'
+ push sqlite_funcs, 'ip'
+ push sqlite_funcs, 'close'
+ push sqlite_funcs, 'ip'
+ push sqlite_funcs, 'errmsg'
+ push sqlite_funcs, 'tp'
+ push sqlite_funcs, 'errcode'
+ push sqlite_funcs, 'ip'
+ push sqlite_funcs, 'bind_int'
+ push sqlite_funcs, 'ipii'
+ push sqlite_funcs, 'bind_double'
+ push sqlite_funcs, 'ipid'
+ push sqlite_funcs, 'bind_text'
+ push sqlite_funcs, 'ipitii'
+
function = dlfunc libname, 'sqlite3_open', 'itV'
set_global 'open_raw', function
function = dlfunc libname, 'sqlite3_prepare_v2', 'iptiVp'
set_global 'prepare_raw', function
- function = dlfunc libname, 'sqlite3_step', 'ip'
- set_global 'step', function
+ .local pmc list_iter
+ list_iter = iter sqlite_funcs
+ .local string func_name, signature
+ .local pmc function
+
+ list_loop:
+ unless list_iter goto done
+ func_name = shift list_iter
+ signature = shift list_iter
+ $S0 = concat 'sqlite3_', func_name
+ function = dlfunc libname, $S0, signature
+ set_global func_name, function
+ goto list_loop
- function = dlfunc libname, 'sqlite3_finalize', 'ip'
- set_global 'finalize', function
+ done:
- function = dlfunc libname, 'sqlite3_close', 'ip'
- set_global 'close', function
.end
.sub 'open'
-
[svn:parrot] r33503 - in trunk: . config/gen/call_list ext/SQLite3 ext/SQLite3/DBDI ext/SQLite3/DBDI/Driver
by simon