
Hi all, I'm learning sqlite, and as I know haskell has some libraries like HDBC or HSQL can access sqlite DB. Can anybody give me a small example to show how to use it? It will be very appreciate? Thanks! Best Regards, Deng Chao

On Sat, Mar 22, 2008 at 1:40 PM, Deng Chao
Hi all, I'm learning sqlite, and as I know haskell has some libraries like HDBC or HSQL can access sqlite DB. Can anybody give me a small example to show how to use it? It will be very appreciate? Thanks!
Best Regards, Deng Chao
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Here's a quick GHCi session with HDBC. Prelude> :m +Database.HDBC Prelude Database.HDBC> :m +Database.HDBC.Sqlite3 Prelude Database.HDBC Database.HDBC.Sqlite3> conn <- connectSqlite3 "mydb" Prelude Database.HDBC Database.HDBC.Sqlite3> quickQuery conn "CREATE TABLE mytable (FirstName varchar, LastName varchar, Age int )" [] [] Prelude Database.HDBC Database.HDBC.Sqlite3> quickQuery conn "INSERT INTO mytable VALUES ('Sebastian','Sylvan',26)" [] [] Prelude Database.HDBC Database.HDBC.Sqlite3> commit conn Prelude Database.HDBC Database.HDBC.Sqlite3> quickQuery conn "SELECT * FROM mytable" [] [[SqlString "Sebastian",SqlString "Sylvan",SqlString "26"]] Prelude Database.HDBC Database.HDBC.Sqlite3> disconnect conn Not sure why that Age field came back as a string though :-) -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862

2008/3/22 Sebastian Sylvan
On Sat, Mar 22, 2008 at 1:40 PM, Deng Chao
wrote: Hi all, I'm learning sqlite, and as I know haskell has some libraries like HDBC or HSQL can access sqlite DB. Can anybody give me a small example to show how to use it? It will be very appreciate? Thanks!
Best Regards, Deng Chao
Here's a quick GHCi session with HDBC.
Prelude> :m +Database.HDBC Prelude Database.HDBC> :m +Database.HDBC.Sqlite3 Prelude Database.HDBC Database.HDBC.Sqlite3> conn <- connectSqlite3 "mydb" Prelude Database.HDBC Database.HDBC.Sqlite3> quickQuery conn "CREATE TABLE mytable (FirstName varchar, LastName varchar, Age int )" [] [] Prelude Database.HDBC Database.HDBC.Sqlite3> quickQuery conn "INSERT INTO mytable VALUES ('Sebastian','Sylvan',26)" [] [] Prelude Database.HDBC Database.HDBC.Sqlite3> commit conn Prelude Database.HDBC Database.HDBC.Sqlite3> quickQuery conn "SELECT * FROM mytable" [] [[SqlString "Sebastian",SqlString "Sylvan",SqlString "26"]] Prelude Database.HDBC Database.HDBC.Sqlite3> disconnect conn
Not sure why that Age field came back as a string though :-)
This is SQLite's fault. In SQLite, all types are aliases for STRING. Whatever type you use in the create and insert, you will get strings back. /Björn

Hallo, Bjorn Bringert wrote:
This is SQLite's fault. In SQLite, all types are aliases for STRING. Whatever type you use in the create and insert, you will get strings back.
That's not true. SQLite has integers (64 bits) and reals. But, if you try to read the field as text it will gladly convert it for you. For reading as the correcting type, the binding should have used sqlite3_column_get_type first. Cheers, -alex

On Tue, Mar 25, 2008 at 3:29 PM, Alex Sandro Queiroz e Silva
Hallo,
Bjorn Bringert wrote:
This is SQLite's fault. In SQLite, all types are aliases for STRING. Whatever type you use in the create and insert, you will get strings back.
That's not true. SQLite has integers (64 bits) and reals. But, if you try to read the field as text it will gladly convert it for you. For reading as the correcting type, the binding should have used sqlite3_column_get_type first.
Cheers, -alex
Hi Alex, thanks for setting me straight. It would be great if you would want to submit a patch for HDBC-sqlite3 to fix this. /Björn
participants (4)
-
Alex Sandro Queiroz e Silva
-
Bjorn Bringert
-
Deng Chao
-
Sebastian Sylvan