use ERROR:, inline database combinator examples

db4
Doug Coleman 2008-10-08 19:06:19 -05:00
parent 031ebe98b1
commit ea69c8996f
2 changed files with 5 additions and 3 deletions

View File

@ -285,7 +285,7 @@ ARTICLE: "db-custom-database-combinators" "Custom database combinators"
{ $code <"
USING: db.sqlite db io.files ;
: 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:"
{ $code <" USING: db.postgresql db ;
@ -296,7 +296,7 @@ USING: db.sqlite db io.files ;
"erg" >>username
"secrets?" >>password
"factor-test" >>database
swap with-db ;">
swap with-db ; inline">
} ;
ABOUT: "db"

View File

@ -87,9 +87,11 @@ M: sqlite-statement bind-tuple ( tuple statement -- )
in-params>> [ sqlite-bind-conversion ] with map
] keep bind-statement ;
ERROR: sqlite-last-id-fail ;
: last-insert-id ( -- id )
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 -- )
execute-statement last-insert-id swap set-primary-key ;