Parameterized SQL statement: Difference between revisions

no edit summary
No edit summary
Line 307:
100 0 false
</pre>
 
=={{header|Haskell}}==
 
Example uses the [http://hackage.haskell.org/package/HDBC <tt>HDBC</tt>] package:
 
<lang haskell>
module Main (main) where
 
import Database.HDBC (IConnection, commit, run, toSql)
 
updatePlayers :: IConnection a => a -> String -> Int -> Bool -> Int -> IO Bool
updatePlayers conn name score active jerseyNum = do
rowCount <- run conn
"UPDATE players\
\ SET name = ?, score = ?, active = ?\
\ WHERE jerseyNum = ?"
[ toSql name
, toSql score
, toSql active
, toSql jerseyNum
]
commit conn
return $ rowCount == 1
 
main :: IO ()
main = undefined
</lang>
 
You need a type with an instance for the <tt>IConnection</tt> type class in order to use this function, such as [http://hackage.haskell.org/package/HDBC-postgresql-2.3.2.5/docs/Database-HDBC-PostgreSQL.html#t:Connection <tt>Connection</tt>] from [http://hackage.haskell.org/package/HDBC-postgresql <tt>HDBC-postgresql</tt>].
 
=={{header|Java}}==
Anonymous user