Merge branch 'master' of git://factorcode.org/git/factor
commit
5a4c637719
|
@ -26,10 +26,6 @@ HELP: dispose-statements
|
||||||
{ $values { "assoc" assoc } }
|
{ $values { "assoc" assoc } }
|
||||||
{ $description "Disposes an associative list of statements." } ;
|
{ $description "Disposes an associative list of statements." } ;
|
||||||
|
|
||||||
HELP: db-dispose
|
|
||||||
{ $values { "db" db } }
|
|
||||||
{ $description "Disposes of all the statements stored in the " { $link db } " object." } ;
|
|
||||||
|
|
||||||
HELP: statement
|
HELP: statement
|
||||||
{ $description "A " { $snippet "statement" } " stores the information about a statemen, such as the SQL statement text, the in/out parameters, and type information." } ;
|
{ $description "A " { $snippet "statement" } " stores the information about a statemen, such as the SQL statement text, the in/out parameters, and type information." } ;
|
||||||
|
|
||||||
|
@ -285,7 +281,7 @@ ARTICLE: "db-custom-database-combinators" "Custom database combinators"
|
||||||
{ $code <"
|
{ $code <"
|
||||||
USING: db.sqlite db io.files ;
|
USING: db.sqlite db io.files ;
|
||||||
: with-sqlite-db ( quot -- )
|
: with-sqlite-db ( quot -- )
|
||||||
"my-database.db" temp-file <sqlite-db> swap with-db ;"> }
|
"my-database.db" temp-file <sqlite-db> swap with-db ; inline"> }
|
||||||
|
|
||||||
"PostgreSQL example combinator:"
|
"PostgreSQL example combinator:"
|
||||||
{ $code <" USING: db.postgresql db ;
|
{ $code <" USING: db.postgresql db ;
|
||||||
|
@ -296,7 +292,7 @@ USING: db.sqlite db io.files ;
|
||||||
"erg" >>username
|
"erg" >>username
|
||||||
"secrets?" >>password
|
"secrets?" >>password
|
||||||
"factor-test" >>database
|
"factor-test" >>database
|
||||||
swap with-db ;">
|
swap with-db ; inline">
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
ABOUT: "db"
|
ABOUT: "db"
|
||||||
|
|
|
@ -22,14 +22,13 @@ HOOK: db-close db ( handle -- )
|
||||||
|
|
||||||
: dispose-statements ( assoc -- ) values dispose-each ;
|
: dispose-statements ( assoc -- ) values dispose-each ;
|
||||||
|
|
||||||
: db-dispose ( db -- )
|
M: db dispose ( db -- )
|
||||||
dup db [
|
dup db [
|
||||||
{
|
[ dispose-statements H{ } clone ] change-insert-statements
|
||||||
[ insert-statements>> dispose-statements ]
|
[ dispose-statements H{ } clone ] change-update-statements
|
||||||
[ update-statements>> dispose-statements ]
|
[ dispose-statements H{ } clone ] change-delete-statements
|
||||||
[ delete-statements>> dispose-statements ]
|
[ db-close f ] change-handle
|
||||||
[ handle>> db-close ]
|
drop
|
||||||
} cleave
|
|
||||||
] with-variable ;
|
] with-variable ;
|
||||||
|
|
||||||
TUPLE: result-set sql in-params out-params handle n max ;
|
TUPLE: result-set sql in-params out-params handle n max ;
|
||||||
|
|
|
@ -30,8 +30,8 @@ M: postgresql-db db-open ( db -- db )
|
||||||
[ password>> ]
|
[ password>> ]
|
||||||
} cleave connect-postgres >>handle ;
|
} cleave connect-postgres >>handle ;
|
||||||
|
|
||||||
M: postgresql-db dispose ( db -- )
|
M: postgresql-db db-close ( handle -- )
|
||||||
handle>> PQfinish ;
|
PQfinish ;
|
||||||
|
|
||||||
M: postgresql-statement bind-statement* ( statement -- ) drop ;
|
M: postgresql-statement bind-statement* ( statement -- ) drop ;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ M: sqlite-db db-open ( db -- db )
|
||||||
dup path>> sqlite-open >>handle ;
|
dup path>> sqlite-open >>handle ;
|
||||||
|
|
||||||
M: sqlite-db db-close ( handle -- ) sqlite-close ;
|
M: sqlite-db db-close ( handle -- ) sqlite-close ;
|
||||||
M: sqlite-db dispose ( db -- ) db-dispose ;
|
|
||||||
|
|
||||||
TUPLE: sqlite-statement < statement ;
|
TUPLE: sqlite-statement < statement ;
|
||||||
|
|
||||||
|
@ -87,9 +86,11 @@ M: sqlite-statement bind-tuple ( tuple statement -- )
|
||||||
in-params>> [ sqlite-bind-conversion ] with map
|
in-params>> [ sqlite-bind-conversion ] with map
|
||||||
] keep bind-statement ;
|
] keep bind-statement ;
|
||||||
|
|
||||||
|
ERROR: sqlite-last-id-fail ;
|
||||||
|
|
||||||
: last-insert-id ( -- id )
|
: last-insert-id ( -- id )
|
||||||
db get handle>> sqlite3_last_insert_rowid
|
db get handle>> sqlite3_last_insert_rowid
|
||||||
dup zero? [ "last-id failed" throw ] when ;
|
dup zero? [ sqlite-last-id-fail ] when ;
|
||||||
|
|
||||||
M: sqlite-db insert-tuple-set-key ( tuple statement -- )
|
M: sqlite-db insert-tuple-set-key ( tuple statement -- )
|
||||||
execute-statement last-insert-id swap set-primary-key ;
|
execute-statement last-insert-id swap set-primary-key ;
|
||||||
|
|
Loading…
Reference in New Issue