comparison src/mysql.sml @ 1293:acabf3935060

tryDml
author Adam Chlipala <adam@chlipala.net>
date Sun, 05 Sep 2010 14:00:57 -0400
parents 514be09d5018
children 929981850d9d
comparison
equal deleted inserted replaced
1292:a671c986f517 1293:acabf3935060
1192 box [string "uw_pop_cleanup(ctx);", 1192 box [string "uw_pop_cleanup(ctx);",
1193 newline] 1193 newline]
1194 else 1194 else
1195 box []] 1195 box []]
1196 1196
1197 fun dmlCommon {loc, dml} = 1197 fun dmlCommon {loc, dml, mode} =
1198 box [string "if (mysql_stmt_execute(stmt)) uw_error(ctx, FATAL, \"", 1198 box [string "if (mysql_stmt_execute(stmt)) ",
1199 string (ErrorMsg.spanToString loc), 1199 case mode of
1200 string ": Error executing DML: %s\\n%s\", ", 1200 Settings.Error => box [string "uw_error(ctx, FATAL, \"",
1201 dml, 1201 string (ErrorMsg.spanToString loc),
1202 string ", mysql_error(conn->conn));", 1202 string ": Error executing DML: %s\\n%s\", ",
1203 dml,
1204 string ", mysql_error(conn->conn));"]
1205 | Settings.None => string "uw_errmsg = mysql_error(conn->conn);",
1203 newline, 1206 newline,
1204 newline] 1207 newline]
1205 1208
1206 fun dml loc = 1209 fun dml (loc, mode) =
1207 box [string "uw_conn *conn = uw_get_db(ctx);", 1210 box [string "uw_conn *conn = uw_get_db(ctx);",
1208 newline, 1211 newline,
1209 string "MYSQL_STMT *stmt = mysql_stmt_init(conn->conn);", 1212 string "MYSQL_STMT *stmt = mysql_stmt_init(conn->conn);",
1210 newline, 1213 newline,
1211 string "if (stmt == NULL) uw_error(ctx, FATAL, \"", 1214 string "if (stmt == NULL) uw_error(ctx, FATAL, \"",
1218 string (ErrorMsg.spanToString loc), 1221 string (ErrorMsg.spanToString loc),
1219 string ": error preparing statement: %s\\n%s\", dml, mysql_error(conn->conn));", 1222 string ": error preparing statement: %s\\n%s\", dml, mysql_error(conn->conn));",
1220 newline, 1223 newline,
1221 newline, 1224 newline,
1222 1225
1223 dmlCommon {loc = loc, dml = string "dml"}, 1226 dmlCommon {loc = loc, dml = string "dml", mode = mode},
1224 1227
1225 string "uw_pop_cleanup(ctx);", 1228 string "uw_pop_cleanup(ctx);",
1226 newline] 1229 newline]
1227 1230
1228 fun dmlPrepared {loc, id, dml, inputs} = 1231 fun dmlPrepared {loc, id, dml, inputs, mode} =
1229 box [string "uw_conn *conn = uw_get_db(ctx);", 1232 box [string "uw_conn *conn = uw_get_db(ctx);",
1230 newline, 1233 newline,
1231 string "MYSQL_BIND in[", 1234 string "MYSQL_BIND in[",
1232 string (Int.toString (length inputs)), 1235 string (Int.toString (length inputs)),
1233 string "];", 1236 string "];",
1469 string ": error binding parameters\");", 1472 string ": error binding parameters\");",
1470 newline, 1473 newline,
1471 1474
1472 dmlCommon {loc = loc, dml = box [string "\"", 1475 dmlCommon {loc = loc, dml = box [string "\"",
1473 string (String.toCString dml), 1476 string (String.toCString dml),
1474 string "\""]}] 1477 string "\""], mode = mode}]
1475 1478
1476 fun nextval {loc, seqE, seqName} = 1479 fun nextval {loc, seqE, seqName} =
1477 box [string "uw_conn *conn = uw_get_db(ctx);", 1480 box [string "uw_conn *conn = uw_get_db(ctx);",
1478 newline, 1481 newline,
1479 string "char *insert = ", 1482 string "char *insert = ",