comparison src/sqlite.sml @ 1656:3e7c7e200713

Fix handling of quotes in generating C literals
author Adam Chlipala <adam@chlipala.net>
date Mon, 02 Jan 2012 17:08:39 -0500
parents 969b90b1f2f9
children ac141fbb313a
comparison
equal deleted inserted replaced
1655:b694f9153faa 1656:3e7c7e200713
1 (* Copyright (c) 2009-2010, Adam Chlipala 1 (* Copyright (c) 2009-2010, Adam Chlipala
2 * All rights reserved. 2 * All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: 5 * modification, are permitted provided that the following conditions are met:
6 * 6 *
228 string s]) args, 228 string s]) args,
229 string ");", 229 string ");",
230 newline] 230 newline]
231 in 231 in
232 box [string "if (sqlite3_prepare_v2(conn->conn, \"", 232 box [string "if (sqlite3_prepare_v2(conn->conn, \"",
233 string (String.toCString s), 233 string (Prim.toCString s),
234 string "\", -1, &conn->p", 234 string "\", -1, &conn->p",
235 string (Int.toString i), 235 string (Int.toString i),
236 string ", NULL) != SQLITE_OK) {", 236 string ", NULL) != SQLITE_OK) {",
237 newline, 237 newline,
238 box [string "char msg[1024];", 238 box [string "char msg[1024];",
240 string "strncpy(msg, sqlite3_errmsg(conn->conn), 1024);", 240 string "strncpy(msg, sqlite3_errmsg(conn->conn), 1024);",
241 newline, 241 newline,
242 string "msg[1023] = 0;", 242 string "msg[1023] = 0;",
243 newline, 243 newline,
244 uhoh false ("Error preparing statement: " 244 uhoh false ("Error preparing statement: "
245 ^ String.toCString s ^ "<br />%s") ["msg"]], 245 ^ Prim.toCString s ^ "<br />%s") ["msg"]],
246 string "}", 246 string "}",
247 newline] 247 newline]
248 end) 248 end)
249 ss, 249 ss,
250 250
657 657
658 string "if (stmt == NULL) {", 658 string "if (stmt == NULL) {",
659 newline], 659 newline],
660 660
661 string "if (sqlite3_prepare_v2(conn->conn, \"", 661 string "if (sqlite3_prepare_v2(conn->conn, \"",
662 string (String.toCString query), 662 string (Prim.toCString query),
663 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ", 663 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ",
664 string (String.toCString query), 664 string (Prim.toCString query),
665 string "<br />%s\", sqlite3_errmsg(conn->conn));", 665 string "<br />%s\", sqlite3_errmsg(conn->conn));",
666 newline, 666 newline,
667 if nested then 667 if nested then
668 box [string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);", 668 box [string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);",
669 newline] 669 newline]
683 683
684 p_inputs loc inputs, 684 p_inputs loc inputs,
685 newline, 685 newline,
686 686
687 queryCommon {loc = loc, cols = cols, doCols = doCols, query = box [string "\"", 687 queryCommon {loc = loc, cols = cols, doCols = doCols, query = box [string "\"",
688 string (String.toCString query), 688 string (Prim.toCString query),
689 string "\""]}, 689 string "\""]},
690 690
691 string "uw_pop_cleanup(ctx);", 691 string "uw_pop_cleanup(ctx);",
692 newline, 692 newline,
693 if nested then 693 if nested then
748 newline, 748 newline,
749 749
750 string "if (stmt == NULL) {", 750 string "if (stmt == NULL) {",
751 newline, 751 newline,
752 box [string "if (sqlite3_prepare_v2(conn->conn, \"", 752 box [string "if (sqlite3_prepare_v2(conn->conn, \"",
753 string (String.toCString dml), 753 string (Prim.toCString dml),
754 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ", 754 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ",
755 string (String.toCString dml), 755 string (Prim.toCString dml),
756 string "<br />%s\", sqlite3_errmsg(conn->conn));", 756 string "<br />%s\", sqlite3_errmsg(conn->conn));",
757 newline, 757 newline,
758 string "conn->p", 758 string "conn->p",
759 string (Int.toString id), 759 string (Int.toString id),
760 string " = stmt;", 760 string " = stmt;",
769 769
770 p_inputs loc inputs, 770 p_inputs loc inputs,
771 newline, 771 newline,
772 772
773 dmlCommon {loc = loc, dml = box [string "\"", 773 dmlCommon {loc = loc, dml = box [string "\"",
774 string (String.toCString dml), 774 string (Prim.toCString dml),
775 string "\""], mode = mode}, 775 string "\""], mode = mode},
776 776
777 string "uw_pop_cleanup(ctx);", 777 string "uw_pop_cleanup(ctx);",
778 newline, 778 newline,
779 string "uw_pop_cleanup(ctx);", 779 string "uw_pop_cleanup(ctx);",