[Haskell-cafe] How to program with sqlite?
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
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
[[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 :-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe