
21 Jun
2011
21 Jun
'11
10:54 a.m.
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.)