part-cw / lambdanative

LambdaNative is a cross-platform development environment written in Scheme, supporting Android, iOS, BlackBerry 10, OS X, Linux, Windows, OpenBSD, NetBSD, FreeBSD and OpenWrt.
http://www.lambdanative.org
Other
1.4k stars 86 forks source link

Sqlite test entry does not match data type #453

Closed bkmgit closed 4 months ago

bkmgit commented 5 months ago

A float is used in https://github.com/part-cw/lambdanative/blob/master/modules/sqlite/sqlite.scm#L184 but the field type is integer.

mgorges commented 5 months ago

I appreciate that this is a bit odd but SQLite uses weak typing: https://www.sqlite.org/datatype3.html, so this is permissible and validates. I also added a unittest in 9f61acc. If you like an example see this:

(define filename "test.sqlite")
(define res '(("hello!" 10) ("goodbye" 20) ("one more" 2.3)))
(define db (sqlite-open filename))
(sqlite-query db "CREATE TABLE tbl1(one VARCHAR(10), two INTEGER)")
(sqlite-query db "INSERT INTO tbl1 VALUES('hello!',10)")
(sqlite-query db "INSERT INTO tbl1 VALUES('goodbye', 20)")
(sqlite-query db "INSERT INTO tbl1 VALUES('one more', 2.3)")
(for-each display (list res "\n" 
                        (sqlite-query db "SELECT * FROM tbl1") "\n" 
                        (equal? res (sqlite-query db "SELECT * FROM tbl1"))))
(sqlite-query db " SELECT typeof(one), typeof(two) FROM tbl1;")
(sqlite-close db)
(delete-file filename)

which results in

((hello! 10) (goodbye 20) (one more 2.3))
((hello! 10) (goodbye 20) (one more 2.3))
#t
(("text" "integer") ("text" "integer") ("text" "real"))
bkmgit commented 4 months ago

Ok, thanks.