use new lookup for sqlite

db4
Doug Coleman 2008-04-20 16:57:50 -05:00
parent f5485c1a3d
commit be8ac1d7b6
2 changed files with 37 additions and 52 deletions

View File

@ -126,7 +126,7 @@ M: sqlite-db create-sql-statement ( class -- statement )
"(" 0% [ ", " 0% ] [ "(" 0% [ ", " 0% ] [
dup column-name>> 0% dup column-name>> 0%
" " 0% " " 0%
dup type>> t lookup-type 0% dup type>> lookup-create-type 0%
modifiers 0% modifiers 0%
] interleave ");" 0% ] interleave ");" 0%
] sqlite-make dup sql>> . ; ] sqlite-make dup sql>> . ;
@ -247,42 +247,34 @@ M: sqlite-db <select-by-slots-statement> ( tuple class -- statement )
M: sqlite-db random-id-quot ( -- quot ) M: sqlite-db random-id-quot ( -- quot )
[ 64 [ 2^ random ] keep 1 - set-bit ] ; [ 64 [ 2^ random ] keep 1 - set-bit ] ;
M: sqlite-db modifier-table ( -- hashtable ) M: sqlite-db persistent-table ( -- assoc )
H{ H{
{ +native-id+ "primary key" } { +native-id+ { "integer primary key" "integer primary key" f } }
{ +assigned-id+ "primary key" } { +assigned-id+ { f f "primary key" } }
{ +random-id+ "primary key" } { +random-id+ { "integer primary key" "integer primary key" f } }
{ +autoincrement+ "autoincrement" } { INTEGER { "integer" "integer" "primary key" } }
{ +unique+ "unique" } { BIG-INTEGER { "bigint" "bigint" } }
{ +default+ "default" } { SIGNED-BIG-INTEGER { "bigint" "bigint" } }
{ +null+ "null" } { UNSIGNED-BIG-INTEGER { "bigint" "bigint" } }
{ +not-null+ "not null" } { TEXT { "text" "text" } }
{ system-random-generator "" } { VARCHAR { "text" "text" } }
{ secure-random-generator "" } { DATE { "date" "date" } }
{ random-generator "" } { TIME { "time" "time" } }
{ DATETIME { "datetime" "datetime" } }
{ TIMESTAMP { "timestamp" "timestamp" } }
{ DOUBLE { "real" "real" } }
{ BLOB { "blob" "blob" } }
{ FACTOR-BLOB { "blob" "blob" } }
{ +autoincrement+ { f f "autoincrement" } }
{ +unique+ { f f "unique" } }
{ +default+ { f f "default" } }
{ +null+ { f f "null" } }
{ +not-null+ { f f "not null" } }
{ system-random-generator { f f f } }
{ secure-random-generator { f f f } }
{ random-generator { f f f } }
} ; } ;
M: sqlite-db type-table ( -- assoc )
H{
{ +native-id+ "integer primary key" }
{ +random-id+ "integer primary key" }
{ INTEGER "integer" }
{ BIG-INTEGER "bigint" }
{ SIGNED-BIG-INTEGER "bigint" }
{ UNSIGNED-BIG-INTEGER "bigint" }
{ TEXT "text" }
{ VARCHAR "text" }
{ DATE "date" }
{ TIME "time" }
{ DATETIME "datetime" }
{ TIMESTAMP "timestamp" }
{ DOUBLE "real" }
{ BLOB "blob" }
{ FACTOR-BLOB "blob" }
} ;
M: sqlite-db create-type-table ( symbol -- str ) type-table ;
M: sqlite-db compound ( str seq -- str' ) M: sqlite-db compound ( str seq -- str' )
over { over {
{ "default" [ first number>string join-space ] } { "default" [ first number>string join-space ] }

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: io.files kernel tools.test db db.tuples classes USING: io.files kernel tools.test db db.tuples classes
db.types continuations namespaces math math.ranges db.types continuations namespaces math math.ranges
prettyprint tools.walker db.sqlite calendar sequences prettyprint tools.walker calendar sequences db.sqlite
math.intervals db.postgresql accessors random math.bitfields.lib ; math.intervals db.postgresql accessors random math.bitfields.lib ;
IN: db.tuples.tests IN: db.tuples.tests
@ -106,13 +106,6 @@ SYMBOL: person4
[ ] [ person drop-table ] unit-test ; [ ] [ person drop-table ] unit-test ;
: make-native-person-table ( -- )
[ person drop-table ] [ drop ] recover
person create-table
T{ person f f "billy" 200 3.14 } insert-tuple
T{ person f f "johnny" 10 3.14 } insert-tuple
;
: native-person-schema ( -- ) : native-person-schema ( -- )
person "PERSON" person "PERSON"
{ {
@ -192,7 +185,6 @@ TUPLE: annotation n paste-id summary author mode contents ;
: test-repeated-insert : test-repeated-insert
[ ] [ person ensure-table ] unit-test [ ] [ person ensure-table ] unit-test
[ ] [ person1 get insert-tuple ] unit-test [ ] [ person1 get insert-tuple ] unit-test
[ person1 get insert-tuple ] must-fail ; [ person1 get insert-tuple ] must-fail ;
@ -302,11 +294,12 @@ TUPLE: bignum-test id m n o ;
} define-persistent } define-persistent
[ bignum-test drop-table ] ignore-errors [ bignum-test drop-table ] ignore-errors
[ ] [ bignum-test ensure-table ] unit-test [ ] [ bignum-test ensure-table ] unit-test
[ ] [ 63 2^ dup dup <bignum-test> insert-tuple ] unit-test [ ] [ 63 2^ 1- dup dup <bignum-test> insert-tuple ] unit-test ;
[ T{ bignum-test f 1 ! sqlite only
-9223372036854775808 9223372036854775808 -9223372036854775808 } ] ! [ T{ bignum-test f 1
[ T{ bignum-test f 1 } select-tuple ] unit-test ; ! -9223372036854775808 9223372036854775808 -9223372036854775808 } ]
! [ T{ bignum-test f 1 } select-tuple ] unit-test ;
TUPLE: secret n message ; TUPLE: secret n message ;
C: <secret> secret C: <secret> secret
@ -346,17 +339,17 @@ C: <secret> secret
[ native-person-schema test-tuples ] test-postgresql [ native-person-schema test-tuples ] test-postgresql
[ assigned-person-schema test-tuples ] test-postgresql [ assigned-person-schema test-tuples ] test-postgresql
[ assigned-person-schema test-repeated-insert ] test-postgresql [ assigned-person-schema test-repeated-insert ] test-postgresql
[ test-bignum ] test-sqlite [ test-bignum ] test-postgresql
[ test-serialize ] test-postgresql [ test-serialize ] test-postgresql
! [ test-intervals ] test-postgresql ! [ test-intervals ] test-postgresql
! [ test-random-id ] test-postgresql ! [ test-random-id ] test-postgresql
TUPLE: does-not-persist ; TUPLE: does-not-persist ;
[ ! [
[ does-not-persist create-sql-statement ] ! [ does-not-persist create-sql-statement ]
[ class \ not-persistent = ] must-fail-with ! [ class \ not-persistent = ] must-fail-with
] test-sqlite ! ] test-sqlite
[ [
[ does-not-persist create-sql-statement ] [ does-not-persist create-sql-statement ]