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

Christopher Done chrisdone at googlemail.com
Tue Jun 21 16:54:33 CEST 2011

On 21 June 2011 16:47, David Virebayre <dav.vire+haskell at gmail.com> wrote:
> 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.)

More information about the web-devel mailing list