Re: [web-devel] [Haskell-cafe] [ANN] mysql-simple - your go-to package for talking to MySQL

On 21 June 2011 16:47, David Virebayre
For example, how to write a function that returns the columns of a table using show columns ?
type Champ = (String,String,String,String,String,String) getColumns :: Connection -> String -> IO [Champ] getColumns conn table = do query_ conn (fromString $ "show columns from " ++ table)
if you try query conn "show columns from " ( Only table), the query built is show columns from 'xxxxx' which fails.
For this you could have newtype Entity = Entity String and implement the Param class for this type which will output the string in double quotes, and then you can write: query conn "SHOW COLUMNS FROM ?" (Only "mytable") (With OverloadedStrings enabled.)

On 21 June 2011 16:54, Christopher Done
query conn "SHOW COLUMNS FROM ?" (Only "mytable")
(With OverloadedStrings enabled.)
Woops, that would need a type annotation. (Only ("mytable" :: Entity))
participants (1)
-
Christopher Done