From eaaf2af7b77233698f41fc1388ec8462ab6e75cc Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 12 Feb 2009 01:39:14 -0600 Subject: [PATCH] Fixing db.sqlite bug: database schema don't need primary keys --- basis/db/sqlite/sqlite-tests.factor | 22 ++++++++++++++++++++++ basis/db/sqlite/sqlite.factor | 12 +++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/basis/db/sqlite/sqlite-tests.factor b/basis/db/sqlite/sqlite-tests.factor index 6fb1cd19ad..69d5f1dd43 100644 --- a/basis/db/sqlite/sqlite-tests.factor +++ b/basis/db/sqlite/sqlite-tests.factor @@ -73,3 +73,25 @@ IN: db.sqlite.tests "select * from person" sql-query length ] with-db ] unit-test + +! You don't need a primary key +USING: accessors arrays sorting ; +TUPLE: things one two ; + +things "THINGS" { + { "one" "ONE" INTEGER +not-null+ } + { "two" "TWO" INTEGER +not-null+ } +} define-persistent + +[ { { 0 0 } { 0 1 } { 1 0 } { 1 1 } } ] [ + test.db [ + things create-table + 0 0 things boa insert-tuple + 0 1 things boa insert-tuple + 1 1 things boa insert-tuple + 1 0 things boa insert-tuple + f f things boa select-tuples + [ [ one>> ] [ two>> ] bi 2array ] map natural-sort + things drop-table + ] with-db +] unit-test diff --git a/basis/db/sqlite/sqlite.factor b/basis/db/sqlite/sqlite.factor index fe3bb64d45..9b05cf9825 100755 --- a/basis/db/sqlite/sqlite.factor +++ b/basis/db/sqlite/sqlite.factor @@ -138,11 +138,13 @@ M: sqlite-db-connection create-sql-statement ( class -- statement ) modifiers 0% ] interleave - ", " 0% - find-primary-key - "primary key(" 0% - [ "," 0% ] [ column-name>> 0% ] interleave - "));" 0% + find-primary-key [ + ", " 0% + "primary key(" 0% + [ "," 0% ] [ column-name>> 0% ] interleave + ")" 0% + ] unless-empty + ");" 0% ] query-make ; M: sqlite-db-connection drop-sql-statement ( class -- statement )