Fixing db.sqlite bug: database schema don't need primary keys

db4
Daniel Ehrenberg 2009-02-12 01:39:14 -06:00
parent 6215c38676
commit eaaf2af7b7
2 changed files with 29 additions and 5 deletions

View File

@ -73,3 +73,25 @@ IN: db.sqlite.tests
"select * from person" sql-query length "select * from person" sql-query length
] with-db ] with-db
] unit-test ] 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

View File

@ -138,11 +138,13 @@ M: sqlite-db-connection create-sql-statement ( class -- statement )
modifiers 0% modifiers 0%
] interleave ] interleave
find-primary-key [
", " 0% ", " 0%
find-primary-key
"primary key(" 0% "primary key(" 0%
[ "," 0% ] [ column-name>> 0% ] interleave [ "," 0% ] [ column-name>> 0% ] interleave
"));" 0% ")" 0%
] unless-empty
");" 0%
] query-make ; ] query-make ;
M: sqlite-db-connection drop-sql-statement ( class -- statement ) M: sqlite-db-connection drop-sql-statement ( class -- statement )