From ea69c8996fe9f20f304b8b00af034c15f9f66773 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 8 Oct 2008 19:06:19 -0500 Subject: [PATCH 1/5] use ERROR:, inline database combinator examples --- basis/db/db-docs.factor | 4 ++-- basis/db/sqlite/sqlite.factor | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/basis/db/db-docs.factor b/basis/db/db-docs.factor index 16a8228fca..7c84e6205e 100644 --- a/basis/db/db-docs.factor +++ b/basis/db/db-docs.factor @@ -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 swap with-db ;"> } + "my-database.db" temp-file 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" diff --git a/basis/db/sqlite/sqlite.factor b/basis/db/sqlite/sqlite.factor index 8580b9012c..4aa41483d8 100644 --- a/basis/db/sqlite/sqlite.factor +++ b/basis/db/sqlite/sqlite.factor @@ -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 ; From 7b9a3b61c35c78ba40794a5fac792934fc712293 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 9 Oct 2008 14:07:11 -0500 Subject: [PATCH 2/5] partial fix for db, going to make it use dispose* soon --- basis/db/db.factor | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/basis/db/db.factor b/basis/db/db.factor index bf23005bc2..a124914a35 100644 --- a/basis/db/db.factor +++ b/basis/db/db.factor @@ -6,6 +6,7 @@ tools.walker accessors combinators fry ; IN: db TUPLE: db + disposed handle insert-statements update-statements @@ -24,12 +25,10 @@ HOOK: db-close db ( handle -- ) : db-dispose ( db -- ) dup db [ - { - [ insert-statements>> dispose-statements ] - [ update-statements>> dispose-statements ] - [ delete-statements>> dispose-statements ] - [ handle>> db-close ] - } cleave + [ dispose-statements H{ } clone ] change-insert-statements + [ dispose-statements H{ } clone ] change-update-statements + [ dispose-statements H{ } clone ] change-delete-statements + handle>> db-close ] with-variable ; TUPLE: result-set sql in-params out-params handle n max ; From 83f1634219f2a281a27d138466aa007313e6b89d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 9 Oct 2008 15:42:23 -0500 Subject: [PATCH 3/5] clean up dispose a bit --- basis/db/db.factor | 6 +++--- basis/db/postgresql/postgresql.factor | 4 ++-- basis/db/sqlite/sqlite.factor | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/basis/db/db.factor b/basis/db/db.factor index a124914a35..3ee0fe3d09 100644 --- a/basis/db/db.factor +++ b/basis/db/db.factor @@ -6,7 +6,6 @@ tools.walker accessors combinators fry ; IN: db TUPLE: db - disposed handle insert-statements update-statements @@ -23,12 +22,13 @@ HOOK: db-close db ( handle -- ) : dispose-statements ( assoc -- ) values dispose-each ; -: db-dispose ( db -- ) +M: db dispose ( db -- ) dup db [ [ dispose-statements H{ } clone ] change-insert-statements [ dispose-statements H{ } clone ] change-update-statements [ dispose-statements H{ } clone ] change-delete-statements - handle>> db-close + [ db-close f ] change-handle + drop ] with-variable ; TUPLE: result-set sql in-params out-params handle n max ; diff --git a/basis/db/postgresql/postgresql.factor b/basis/db/postgresql/postgresql.factor index 08df25c13a..f9c9ea73ec 100644 --- a/basis/db/postgresql/postgresql.factor +++ b/basis/db/postgresql/postgresql.factor @@ -30,8 +30,8 @@ M: postgresql-db db-open ( db -- db ) [ password>> ] } cleave connect-postgres >>handle ; -M: postgresql-db dispose ( db -- ) - handle>> PQfinish ; +M: postgresql-db db-close ( handle -- ) + PQfinish ; M: postgresql-statement bind-statement* ( statement -- ) drop ; diff --git a/basis/db/sqlite/sqlite.factor b/basis/db/sqlite/sqlite.factor index 4aa41483d8..216f324bbf 100644 --- a/basis/db/sqlite/sqlite.factor +++ b/basis/db/sqlite/sqlite.factor @@ -19,7 +19,6 @@ M: sqlite-db db-open ( db -- db ) dup path>> sqlite-open >>handle ; M: sqlite-db db-close ( handle -- ) sqlite-close ; -M: sqlite-db dispose ( db -- ) db-dispose ; TUPLE: sqlite-statement < statement ; From ace2ce2ce7a069f60239b346af0e4abc108dd88e Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 9 Oct 2008 16:40:19 -0500 Subject: [PATCH 4/5] remove old word --- basis/db/db-docs.factor | 4 ---- 1 file changed, 4 deletions(-) diff --git a/basis/db/db-docs.factor b/basis/db/db-docs.factor index 7c84e6205e..52dc389fe6 100644 --- a/basis/db/db-docs.factor +++ b/basis/db/db-docs.factor @@ -26,10 +26,6 @@ HELP: dispose-statements { $values { "assoc" assoc } } { $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 { $description "A " { $snippet "statement" } " stores the information about a statemen, such as the SQL statement text, the in/out parameters, and type information." } ; From f1286a353f1e24a8036628323a3e75ae2d4fcc32 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 10 Oct 2008 13:43:58 -0500 Subject: [PATCH 5/5] Fix typo --- core/alien/alien-docs.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/alien/alien-docs.factor b/core/alien/alien-docs.factor index 814ca8613e..ce3497439a 100644 --- a/core/alien/alien-docs.factor +++ b/core/alien/alien-docs.factor @@ -302,8 +302,8 @@ ARTICLE: "embedding" "Embedding Factor into C applications" "The Factor " { $snippet "Makefile" } " builds the Factor VM both as an executable and a library. The library can be used by other applications. File names for the library on various operating systems:" { $table { "OS" "Library name" "Shared?" } - { "Windows XP/Vista" { $snippet "factor-nt.dll" } "Yes" } - { "Windows CE" { $snippet "factor-ce.dll" } "Yes" } + { "Windows XP/Vista" { $snippet "factor.dll" } "Yes" } + ! { "Windows CE" { $snippet "factor-ce.dll" } "Yes" } { "Mac OS X" { $snippet "libfactor.dylib" } "Yes" } { "Other Unix" { $snippet "libfactor.a" } "No" } }