]> gitweb.factorcode.org Git - factor.git/commitdiff
Fixing db.sqlite bug: database schema don't need primary keys
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Thu, 12 Feb 2009 07:39:14 +0000 (01:39 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Thu, 12 Feb 2009 07:39:14 +0000 (01:39 -0600)
basis/db/sqlite/sqlite-tests.factor
basis/db/sqlite/sqlite.factor

index 6fb1cd19adccb262b943a4bbad49ccfaa90135e5..69d5f1dd430f951398c7f298cdd0a09fa4de243e 100644 (file)
@@ -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
index fe3bb64d450626d9658227b839459cdcf18e4893..9b05cf9825d7397312c9d7b89c62557bfa996eca 100755 (executable)
@@ -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 )