Prototyping via JDBC
[email protected] (Tim Bunce) Mon, 12 Sep 2005 21:19:56 +0100
| Newsgroups | perl.dbi2.dev |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Sep 12, 2005 at 10:16:42AM -0700, Brent 'Dax' Royal-Gordon wrote: > On 9/9/05, Tim Bunce <[email protected]> wrote: > > The Perl 5 DBI will be available from Perl 6. Either via Ponie or by embedding > > libperl5 in some way. > > > > This implies that the new DBI is less urgent than it otherwise would be. > > It also implies that we can prototype DBI2 on top of DBI1, i.e. by > writing a wrapper around DBI1 with the interface we want. Yes, that's certainly an option, but I'm actually more keen to prototype DBI2 on top of JDBC! This JDBC-in-Perl5 code: my $con = java::sql::DriverManager->getConnection("jdbc:derby:derbydb", "test", "test"); my $s = $con->createStatement(); $s->executeUpdate("create table foo (foo int, bar varchar(200), primary key (foo))"); $s->executeUpdate("insert into foo (foo, bar) values (42,'notthis')"); $s->executeUpdate("insert into foo (foo, bar) values (43,'notthat')"); my $rs = $s->executeQuery("select foo, bar from foo"); while ($rs->next()) { my $foo = $rs->getInt(1); my $bar = $rs->getString(2); print "row: foo=$foo, bar=$bar\n"; } $s->close; $con->close; is already working. Since it's built on Inline::Java the rest of the JDBC API should also work, I've just not tried it yet... I plan to release a JDBC module to CPAN - hopefully next week. May only be about a page of code as it's just a very thin layer over Inline::Java to provide a level of isolation. (I might want to switch to Java::Import for example.) Tim. p.s. The org.apache.derby.jdbc.EmbeddedDriver is a standards compliant pure-Java embedded (no server) ACID relational database that's very handy for testing. It also happens to be what the JDBC test suite uses.