[Haskell-cafe] How to program with sqlite?

Sebastian Sylvan sebastian.sylvan at gmail.com
Sat Mar 22 10:15:02 EDT 2008


On Sat, Mar 22, 2008 at 1:40 PM, Deng Chao <knifewolf at gmail.com> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080322/37aaabaf/attachment.htm


More information about the Haskell-Cafe mailing list