]> gitweb.factorcode.org Git - factor.git/commitdiff
db.sqlite: make sure select-tuple throws sql-table-missing etc.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 3 Jan 2019 20:39:37 +0000 (12:39 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 3 Jan 2019 20:39:37 +0000 (12:39 -0800)
basis/db/sqlite/lib/lib.factor
basis/db/sqlite/sqlite-tests.factor
basis/db/sqlite/sqlite.factor

index edc8a39f9e948017b4fc13576095b7bbd93ff532..00babd6f4c63666608dadf2d48384a6e111da5b3 100644 (file)
@@ -1,20 +1,20 @@
 ! Copyright (C) 2008 Chris Double, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.c-types alien.data arrays calendar.format
-calendar.parser combinators db db.errors db.sqlite.ffi db.types
-io.backend io.encodings.string io.encodings.utf8 kernel math
-namespaces present sequences serialize urls ;
+calendar.parser combinators db db.errors db.sqlite.errors
+db.sqlite.ffi db.types io.backend io.encodings.string
+io.encodings.utf8 kernel math namespaces present sequences
+serialize urls ;
 IN: db.sqlite.lib
 
 ERROR: sqlite-error < db-error n string ;
-ERROR: sqlite-sql-error < sql-error n string ;
 
 : sqlite-other-error ( n -- * )
     dup sqlite-error-messages nth sqlite-error ;
 
 : sqlite-statement-error ( -- * )
-    SQLITE_ERROR
-    db-connection get handle>> sqlite3_errmsg sqlite-sql-error ;
+    db-connection get handle>> sqlite3_errmsg
+    parse-sqlite-sql-error throw ;
 
 : sqlite-check-result ( n -- )
     {
index 12bf6a40a798c4a1167928aa2dc207639ec99729..ed515efff47d86c9e9da8d7557fa59ebb43a6708 100644 (file)
@@ -1,6 +1,7 @@
-USING: accessors arrays db db.sqlite db.tuples db.types io.directories
-io.files.temp kernel layouts literals math.parser namespaces sequences
-sorting splitting tools.test ;
+USING: accessors arrays db db.errors db.sqlite db.tuples
+db.types io.directories io.files.temp kernel layouts literals
+math.parser namespaces sequences sorting splitting tools.test ;
+
 IN: db.sqlite.tests
 
 : normalize ( str -- str' )
@@ -247,3 +248,9 @@ watch "WATCH" {
         num-test3 new select-tuple
     ] with-db num>>
 ] unit-test
+
+[
+    TUPLE: no-table name ;
+    no-table "NO_TABLE" { { "name" "NAME" VARCHAR } } define-persistent
+    test.db [ no-table new select-tuple ] with-db
+] [ sql-table-missing? ] must-fail-with
index 9a79e456ea37c11b1ac01b6c474f346128a858aa..6b786bb851251bec68889172f41833367ad134e8 100644 (file)
@@ -331,7 +331,9 @@ M: sqlite-db-connection compound ( string seq -- new-string )
     } case ;
 
 M: sqlite-db-connection parse-db-error
-    dup n>> {
-        { 1 [ string>> parse-sqlite-sql-error ] }
-        [ drop ]
-    } case ;
+    dup sqlite-error? [
+        dup n>> {
+            { 1 [ string>> parse-sqlite-sql-error ] }
+            [ drop ]
+        } case
+    ] when ;