updating postgresql

db4
Doug Coleman 2008-03-10 13:56:58 -05:00
parent bf12f94957
commit 0e4ee18110
4 changed files with 31 additions and 10 deletions

View File

@ -20,8 +20,7 @@ GENERIC: db-open ( db -- )
HOOK: db-close db ( handle -- ) HOOK: db-close db ( handle -- )
: make-db ( seq class -- db ) construct-empty make-db* ; : make-db ( seq class -- db ) construct-empty make-db* ;
: dispose-statements ( seq -- ) : dispose-statements ( seq -- ) [ dispose drop ] assoc-each ;
[ dispose drop ] assoc-each ;
: dispose-db ( db -- ) : dispose-db ( db -- )
dup db [ dup db [
@ -46,8 +45,8 @@ GENERIC: bind-tuple ( tuple statement -- )
GENERIC: query-results ( query -- result-set ) GENERIC: query-results ( query -- result-set )
GENERIC: #rows ( result-set -- n ) GENERIC: #rows ( result-set -- n )
GENERIC: #columns ( result-set -- n ) GENERIC: #columns ( result-set -- n )
GENERIC# row-column 1 ( result-set n -- obj ) GENERIC# row-column 1 ( result-set column -- obj )
GENERIC# row-column-typed 1 ( result-set n -- sql ) GENERIC# row-column-typed 1 ( result-set column -- sql )
GENERIC: advance-row ( result-set -- ) GENERIC: advance-row ( result-set -- )
GENERIC: more-rows? ( result-set -- ? ) GENERIC: more-rows? ( result-set -- ? )

View File

@ -2,7 +2,8 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays continuations db io kernel math namespaces USING: arrays continuations db io kernel math namespaces
quotations sequences db.postgresql.ffi alien alien.c-types quotations sequences db.postgresql.ffi alien alien.c-types
db.types tools.walker ascii splitting ; db.types tools.walker ascii splitting math.parser
combinators combinators.cleave ;
IN: db.postgresql.lib IN: db.postgresql.lib
: postgresql-result-error-message ( res -- str/f ) : postgresql-result-error-message ( res -- str/f )
@ -48,3 +49,22 @@ IN: db.postgresql.lib
dup postgresql-result-ok? [ dup postgresql-result-ok? [
dup postgresql-result-error-message swap PQclear throw dup postgresql-result-error-message swap PQclear throw
] unless ; ] unless ;
: postgresql-column-typed ( handle row column type -- obj )
dup array? [ first ] when
{
{ +native-id+ [ ] }
{ INTEGER [ PQgetvalue string>number ] }
{ BIG-INTEGER [ PQgetvalue string>number ] }
{ DOUBLE [ PQgetvalue string>number ] }
{ TEXT [ PQgetvalue ] }
{ VARCHAR [ PQgetvalue ] }
{ DATE [ PQgetvalue ] }
{ TIME [ PQgetvalue ] }
{ TIMESTAMP [ PQgetvalue ] }
{ DATETIME [ PQgetvalue ] }
{ BLOB [ [ PQgetvalue ] 3keep PQgetlength ] }
{ FACTOR-BLOB [ [ PQgetvalue ] 3keep PQgetlength ] }
[ no-sql-type ]
} case ;
! PQgetlength PQgetisnull

View File

@ -4,7 +4,8 @@ USING: arrays assocs alien alien.syntax continuations io
kernel math math.parser namespaces prettyprint quotations kernel math math.parser namespaces prettyprint quotations
sequences debugger db db.postgresql.lib db.postgresql.ffi sequences debugger db db.postgresql.lib db.postgresql.ffi
db.tuples db.types tools.annotations math.ranges db.tuples db.types tools.annotations math.ranges
combinators sequences.lib classes locals words tools.walker ; combinators sequences.lib classes locals words tools.walker
combinators.cleave namespaces.lib ;
IN: db.postgresql IN: db.postgresql
TUPLE: postgresql-db host port pgopts pgtty db user pass ; TUPLE: postgresql-db host port pgopts pgtty db user pass ;
@ -53,11 +54,12 @@ M: postgresql-result-set #rows ( result-set -- n )
M: postgresql-result-set #columns ( result-set -- n ) M: postgresql-result-set #columns ( result-set -- n )
result-set-handle PQnfields ; result-set-handle PQnfields ;
M: postgresql-result-set row-column ( result-set n -- obj ) M: postgresql-result-set row-column ( result-set column -- obj )
>r dup result-set-handle swap result-set-n r> PQgetvalue ; >r dup result-set-handle swap result-set-n r> PQgetvalue ;
M: postgresql-result-set row-column-typed ( result-set n type -- obj ) M: postgresql-result-set row-column-typed ( result-set column -- obj )
>r row-column r> sql-type>factor-type ; dup pick result-set-out-params nth sql-spec-type
>r >r [ result-set-handle ] [ result-set-n ] bi r> r> postgresql-column-typed ;
M: postgresql-statement query-results ( query -- result-set ) M: postgresql-statement query-results ( query -- result-set )
dup statement-bind-params [ dup statement-bind-params [

View File

@ -127,9 +127,9 @@ IN: db.sqlite.lib
{ +native-id+ [ sqlite3_column_int64 ] } { +native-id+ [ sqlite3_column_int64 ] }
{ INTEGER [ sqlite3_column_int ] } { INTEGER [ sqlite3_column_int ] }
{ BIG-INTEGER [ sqlite3_column_int64 ] } { BIG-INTEGER [ sqlite3_column_int64 ] }
{ DOUBLE [ sqlite3_column_double ] }
{ TEXT [ sqlite3_column_text ] } { TEXT [ sqlite3_column_text ] }
{ VARCHAR [ sqlite3_column_text ] } { VARCHAR [ sqlite3_column_text ] }
{ DOUBLE [ sqlite3_column_double ] }
{ DATE [ sqlite3_column_text dup [ ymd>timestamp ] when ] } { DATE [ sqlite3_column_text dup [ ymd>timestamp ] when ] }
{ TIME [ sqlite3_column_text dup [ hms>timestamp ] when ] } { TIME [ sqlite3_column_text dup [ hms>timestamp ] when ] }
{ TIMESTAMP [ sqlite3_column_text dup [ ymdhms>timestamp ] when ] } { TIMESTAMP [ sqlite3_column_text dup [ ymdhms>timestamp ] when ] }