Haskell Language Learning Note (HDBC)

Source: Internet
Author: User
Tags prepare sql error stmt

Installing Hdbc-sqlite3
$ cabal install HDBC-Sqlite3Installed HDBC-sqlite3-2.3.3.1Prelude> :m Database.HDBC Database.HDBC.Sqlite3Prelude Database.HDBC Database.HDBC.Sqlite3>
DB operation
Prelude DATABASE.HDBC database.hdbc.sqlite3> Conn <-connectSqlite3 "Test1.db"--connect or create a database Prelude DATABASE.HDBC Database.hdbc.sqlite3> Run Conn "CREATE table Test (ID INTEGER not NULL, desc VARCHAR (80))" []--Build table 0Prelude Database.H DBC database.hdbc.sqlite3> Run conn "INSERT into Test (ID) VALUES (0)" []--insert record 1Prelude DATABASE.HDBC Database.hdbc.s Qlite3> commit Connprelude DATABASE.HDBC database.hdbc.sqlite3> run conn "INSERT into Test VALUES (?,?)" [Tosql 0, Tosql "Zero"]--insert record, use parameter 1Prelude database.hdbc database.hdbc.sqlite3> commit connprelude database.hdbc Dat Abase. Hdbc. sqlite3> stmt <-Prepare conn "INSERT into Test VALUES (?,?)"--insert record, use statement Prelude Database.hdbc Database.HDBC.Sqlit e3> Execute stmt [tosql 1, Tosql "one"] 1Prelude database.hdbc database.hdbc.sqlite3> execute stmt [Tosql 2, Tosql] Both "] 1Prelude database.hdbc database.hdbc.sqlite3> execute stmt [tosql 3, Tosql" three "]1prelude Database.hdbc Databa Se. Hdbc. Sqlite3> Execute STMT [Tosql 4, Sqlnull]1prelude database.hdbc database.hdbc.sqlite3> commit connprelude DATABASE.HDBC database.hdbc.sqlite3> stmt <-Prepare conn "INSERT into Test VALUES (?,?)" Prelude database.hdbc database.hdbc.sqlite3> executemany stmt [[Tosql 5, Tosql ' five ' nice '], [Tosql 6, Sqlnull]]--Plug into multiple records, using statements Prelude Database.hdbc database.hdbc.sqlite3> commit Connprelude database.hdbc database.hdbc.sqlite3> Quickquery ' conn ' select * from Test where ID < 2 "[]--Query record [[SqlInt64 0,sqlnull],[sqlint64 0,sqlbytestring ' zero '],[s QlInt64 1,sqlbytestring "One"]]prelude database.hdbc database.hdbc.sqlite3> quickquery ' conn ' select ID, desc from tes t where ID <=? ORDER by ID, desc "[Tosql 2]--querying records, using parameters [[SqlInt64 0,sqlnull],[sqlint64 0,sqlbytestring" Zero "],[sqlint64 1,sqlbytestrin G "One"],[sqlint64 2,sqlbytestring "]]prelude database.hdbc database.hdbc.sqlite3> stmt <-Prepare conn" SELECT * FROM Test where ID < 2 "--query record Prelude Database.hdbc database.hdbc.sqlite3> Execute stmt []0prelude database.hdbc database.hdbc.sqlite3> results <-fetchallrowsal stmt--Lazy Read PR Elude Database.hdbc database.hdbc.sqlite3> mapm_ print results[("id", SqlInt64 0), ("desc", Sqlnull) [("id", SqlInt64 0), ("desc", sqlbytestring "Zero") [("id", SqlInt64 1), ("desc", sqlbytestring "one")]
DB Operation 2
Prelude Database.HDBC Database.HDBC.Sqlite3> getTables conn["test"]Prelude Database.HDBC Database.HDBC.Sqlite3> proxiedClientName conn"sqlite3"Prelude Database.HDBC Database.HDBC.Sqlite3> dbServerVer conn"3.19.3"Prelude Database.HDBC Database.HDBC.Sqlite3> dbTransactionSupport connTruePrelude Database.HDBC Database.HDBC.Sqlite3> quickQuery' conn "SELECT * from test2" []*** Exception: SqlError {seState = "", seNativeError = 1, seErrorMsg = "prepare 20: SELECT * from test2: no such table: test2"}Prelude Database.HDBC Database.HDBC.Sqlite3> handleSqlError $ quickQuery' conn "SELECT * from test2" []*** Exception: user error (SQL error: SqlError {seState = "", seNativeError = 1, seErrorMsg = "prepare 20: SELECT * from test2: no such table: test2"})Prelude Database.HDBC Database.HDBC.Sqlite3> disconnect conn

Haskell Language Learning Note (HDBC)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.