[Thousand-oaks-pm] P6 Hackathon - Word from the Parrot SQLite3 Trenches...

Todd Presta toddpresta at sbcglobal.net
Tue Jul 21 11:16:12 PDT 2009


Ok. I might be able to sleep tonight.

Even with Parrot 1.4 out, still getting build errors when trying to use ncigen for the SQLite3 extension.

On another front, the NCI functionality within Parrot seems to choke whenever requesting SQLite database connection handle and prepared statement handle no matter what type of PMC is passed as a parameter during the SQLite dynamic library function calls from within Parrot PIR. Using either Pointer, CPointer, UnManagedStruct, ManagedStruct, or ResizablePMCArray either segfaults or returns an erroneous value.

I decided to go deep and write some C code, basically wrapping both the sqlite3_open and sqlite3_prepare functions in the SQLite3 dynamic library and returning the pointers as the function return values rather than as a reference parameters.

This following PIR snippet calls my dynamic library (birdseed), the SQLite3 dynamic library, and obtains the last column value of a row returned from a prepared statement.

.sub main :main
  .local pmc sqllib, bslib
  .local pmc fn_dbh, dbh, fn_sth, sth, fn_close, fn_step, fn_final, fn_col_t
  bslib  = loadlib "birdseed"
  sqllib = loadlib "sqlite3"

  $S0 = "select * from dummy"

  fn_dbh   = dlfunc bslib,  "get_db_handle",        "pt"
  fn_sth   = dlfunc bslib,  "get_statement_handle", "ppt"
  fn_step  = dlfunc sqllib, "sqlite3_step",         "ip"
  fn_final = dlfunc sqllib, "sqlite3_finalize",     "ip"
  fn_col_t = dlfunc sqllib, "sqlite3_column_text",  "tpi"
  fn_close = dlfunc sqllib, "sqlite3_close",        "ip"

  dbh = fn_dbh("dummy.db") 
  sth = fn_sth(dbh, "select * from dummy")
 
  $I1 = fn_step(sth)
  say $I1

  $S0 = fn_col_t(sth, 1)
  say $S0

  $I2 = fn_final(sth)
  say $I2
  $I3 = fn_close(dbh)
  say $I3

.end

Here is the resulting output from Parrot

C:\t\dv\parrot\PARROT~1\birdseed>parrot birdseed.pir
get_db_handle: got here
get_statement_handle: got here
100
This is tag 1
0
0

Basically, the line that reads "This is tag 1" is the second column of the first row returned from the table "dummy." The lines beginning with "get_" are being printf'd from my library. 100 is SQLITE_ROW (that is a row ready for plucking), and the 0's are SQLITE_OK.

So the trick now is to determine if the SQLite3.pir under <parrot src tree>/etc/SQLite3 can be retrofitted with the "potential" birdseed dynamic library and then be recognized by <parrot src tree>/etc/SQLite3/DBDI/Driver/SQLite3.pm.

More on this later ...

"Er uh, we're still doing the project, right?" :)



T



-- Todd Presta

-- http://www.asciiville.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/thousand-oaks-pm/attachments/20090721/6a0b1ece/attachment.html>


More information about the Thousand-oaks-pm mailing list