June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,20 @@
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

View file

@ -0,0 +1,19 @@
using SQLite
name = "Smith, Steve"
jerseys = Dict("Smith, Steve" => 99)
sqlbool(tf::Bool) = if(tf) "TRUE" else "FALSE" end
db = SQLite.DB() # no filename given, so create an in-memory temporary
SQLite.execute!(db, "create table players (id integer primary key,
name text,
score number,
active bool,
jerseynum integer)")
SQLite.query(db, "INSERT INTO players (name, score, active, jerseynum) values ('Jones, James', 9, 'FALSE', 99)")
SQLite.query(db, "UPDATE players SET name = ?, score = ?, active = ? WHERE jerseynum = ?";
values = ["Smith, Steve", 42, sqlbool(true), jerseys[name]])
tbl = SQLite.query(db, "SELECT * from players")
println(tbl)

View file

@ -0,0 +1,24 @@
// Version 1.2.41
import java.sql.DriverManager
import java.sql.Connection
fun main(args: Array<String>) {
val url = "jdbc:mysql://localhost:3306/test"
val username = "example"
val password = "password123"
val conn = DriverManager.getConnection(url, username, password)
val query = conn.prepareStatement(
"UPDATE players SET name = ?, score = ?, active = ? WHERE jerseyNum = ?"
)
with (query) {
setString(1, "Smith, Steve")
setInt(2, 42)
setBoolean(3, true)
setInt(4, 99)
val rowCount = executeUpdate()
if (rowCount == 0) println("Update failed")
close()
}
conn.close()
}