hdbc

How do I connect Haskell HDBC to an oracle db on osx

不问归期 提交于 2020-01-14 06:01:48
问题 I was wondering how you are supposed to connect to an oracle db on mac with Haskell HDBC. I tried doing it through ODBC, by running brew install unixobcd and then installing oracle instant client basic and obdc into a directory. Then in Haskell, with HDBC and HDBC-odbc both installed, calling connectODBC with Driver set to the location of libsqora.dylib.12.1 in said directory. It is giving me sot-dba: SqlError {seState = "[\"01000\"]", seNativeError = -1, seErrorMsg = "connectODBC

Deserializing data form a SQL Database

一曲冷凌霜 提交于 2020-01-02 08:38:28
问题 I've a little application, backed by a database (SQLite, but it's not really relevant to the question). I've defined some types like: data Whatever = Whatever Int Int String String data ImportantStuff = ImportantStuff { id :: Int, count :: Int, name :: String, description :: String } The types are mapped to tables in the DB. When I read the data, I end up writing functions like this one: whateverFromDB :: [SqlValue] -> Whatever whateverFromDB (a:b:c:d:_) = Whatever (fromSql a) (fromSql b)

How to use “IO String” as an HTTP response in Happstack?

有些话、适合烂在心里 提交于 2019-12-24 09:14:13
问题 I'm retrieving data from a database using HDBC, then trying to send this data to a web client using Happstack. myFunc :: Integer -> IO String myFunc = ... fetch from db here ... handlers :: ServerPart Response handlers = do decodeBody (defaultBodyPolicy "/tmp/" 0 1000 1000) msum [ dir "getData" $ ok $ toResponse $ myFunc $ toInteger 1 ] mainFunc = simpleHTTP nullConf handlers When I build the above code I get this error: No instance for (ToMessage (IO String)) arising from a use of

How do you fill in the parameters for an SQL IN placeholder with HDBC?

a 夏天 提交于 2019-12-10 17:43:23
问题 I'm trying to do something like this with Database.HDBC.PostgreSQL: run c "update questions set deleted = now() where question_id in (?)" [toSql ids] where ids is [Int]. But I get the error No instance for (Data.Convertible.Base.Convertible [Int] SqlValue) How do you fill in an IN placeholder with HDBC? 回答1: I don't think you can avoid building the query dynamically, but you can still avoid SQL injection and the like. import Control.Applicative ((<$), (<$>)) import Data.List (intersperse) let

Concurrent DB connection pool in Haskell

女生的网名这么多〃 提交于 2019-12-03 06:12:06
I am a Java programmer who learns Haskell. I work on a small web-app that uses Happstack and talks to a database via HDBC. I've written select and exec functions and I use them like this: module Main where import Control.Exception (throw) import Database.HDBC import Database.HDBC.Sqlite3 -- just for this example, I use MySQL in production main = do exec "CREATE TABLE IF NOT EXISTS users (name VARCHAR(80) NOT NULL)" [] exec "INSERT INTO users VALUES ('John')" [] exec "INSERT INTO users VALUES ('Rick')" [] rows <- select "SELECT name FROM users" [] let toS x = (fromSql x)::String let names = map

Cheapest way to to determine if a MySQL connection is still alive

人盡茶涼 提交于 2019-11-28 21:34:33
I have a pool of MySQL connections for a web-based data service. When it starts to service a request, it takes a connection from the pool to use. The problem is that if there has been a significant pause since that particular connection has been used, the server may have timed it out and closed its end. I'd like to be able to detect this in the pool management code. The trick is this: The environment in which I'm coding gives me only a very abstract API into the connection. I can basically only execute SQL statements. I don't have access to the actual socket or direct access to the MySQL

Cheapest way to to determine if a MySQL connection is still alive

独自空忆成欢 提交于 2019-11-27 14:06:39
问题 I have a pool of MySQL connections for a web-based data service. When it starts to service a request, it takes a connection from the pool to use. The problem is that if there has been a significant pause since that particular connection has been used, the server may have timed it out and closed its end. I'd like to be able to detect this in the pool management code. The trick is this: The environment in which I'm coding gives me only a very abstract API into the connection. I can basically