comparison src/sqlite.sml @ 1266:459a334345ae

-moduleOf command-line option; compatibility fixes and better error messages for SQLite
author Adam Chlipala <adamc@hcoop.net>
date Thu, 27 May 2010 16:36:17 -0400
parents 134da5110bf7
children 514be09d5018
comparison
equal deleted inserted replaced
1265:e8d68fd8ed4b 1266:459a334345ae
56 string q, 56 string q,
57 string "\", -1, &stmt, NULL) != SQLITE_OK) {", 57 string "\", -1, &stmt, NULL) != SQLITE_OK) {",
58 newline, 58 newline,
59 box [string "sqlite3_close(conn->conn);", 59 box [string "sqlite3_close(conn->conn);",
60 newline, 60 newline,
61 string "uw_error(ctx, FATAL, \"Query preparation failed:\\n", 61 string "uw_error(ctx, FATAL, \"Query preparation failed:<br />",
62 string q, 62 string q,
63 string "\");", 63 string "\");",
64 newline], 64 newline],
65 string "}", 65 string "}",
66 newline, 66 newline,
75 newline, 75 newline,
76 box [string "sqlite3_finalize(stmt);", 76 box [string "sqlite3_finalize(stmt);",
77 newline, 77 newline,
78 string "sqlite3_close(conn->conn);", 78 string "sqlite3_close(conn->conn);",
79 newline, 79 newline,
80 string "uw_error(ctx, FATAL, \"No row returned:\\n", 80 string "uw_error(ctx, FATAL, \"No row returned:<br />",
81 string q, 81 string q,
82 string "\");", 82 string "\");",
83 newline], 83 newline],
84 string "}", 84 string "}",
85 newline, 85 newline,
88 newline, 88 newline,
89 box [string "sqlite3_finalize(stmt);", 89 box [string "sqlite3_finalize(stmt);",
90 newline, 90 newline,
91 string "sqlite3_close(conn->conn);", 91 string "sqlite3_close(conn->conn);",
92 newline, 92 newline,
93 string "uw_error(ctx, FATAL, \"Error getting row:\\n", 93 string "uw_error(ctx, FATAL, \"Error getting row:<br />",
94 string q, 94 string q,
95 string "\");", 95 string "\");",
96 newline], 96 newline],
97 string "}", 97 string "}",
98 newline, 98 newline,
102 newline, 102 newline,
103 box [string "sqlite3_finalize(stmt);", 103 box [string "sqlite3_finalize(stmt);",
104 newline, 104 newline,
105 string "sqlite3_close(conn->conn);", 105 string "sqlite3_close(conn->conn);",
106 newline, 106 newline,
107 string "uw_error(ctx, FATAL, \"Bad column count:\\n", 107 string "uw_error(ctx, FATAL, \"Bad column count:<br />",
108 string q, 108 string q,
109 string "\");", 109 string "\");",
110 newline], 110 newline],
111 string "}", 111 string "}",
112 newline, 112 newline,
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.toString s ^ "\\n%s") ["msg"]], 245 ^ String.toString s ^ "<br />%s") ["msg"]],
246 string "}", 246 string "}",
247 newline] 247 newline]
248 end) 248 end)
249 ss, 249 ss,
250 250
351 newline, 351 newline,
352 box [string "return 0;", 352 box [string "return 0;",
353 newline], 353 newline],
354 string "else {", 354 string "else {",
355 newline, 355 newline,
356 box [string "fprintf(stderr, \"Begin error: %s\\n\", sqlite3_errmsg(conn->conn));", 356 box [string "fprintf(stderr, \"Begin error: %s<br />\", sqlite3_errmsg(conn->conn));",
357 newline, 357 newline,
358 string "return 1;", 358 string "return 1;",
359 newline], 359 newline],
360 string "}", 360 string "}",
361 newline, 361 newline,
369 newline, 369 newline,
370 box [string "return 0;", 370 box [string "return 0;",
371 newline], 371 newline],
372 string "else {", 372 string "else {",
373 newline, 373 newline,
374 box [string "fprintf(stderr, \"Commit error: %s\\n\", sqlite3_errmsg(conn->conn));", 374 box [string "fprintf(stderr, \"Commit error: %s<br />\", sqlite3_errmsg(conn->conn));",
375 newline, 375 newline,
376 string "return 1;", 376 string "return 1;",
377 newline], 377 newline],
378 string "}", 378 string "}",
379 newline, 379 newline,
389 newline, 389 newline,
390 box [string "return 0;", 390 box [string "return 0;",
391 newline], 391 newline],
392 string "else {", 392 string "else {",
393 newline, 393 newline,
394 box [string "fprintf(stderr, \"Rollback error: %s\\n\", sqlite3_errmsg(conn->conn));", 394 box [string "fprintf(stderr, \"Rollback error: %s<br />\", sqlite3_errmsg(conn->conn));",
395 newline, 395 newline,
396 string "return 1;", 396 string "return 1;",
397 newline], 397 newline],
398 string "}", 398 string "}",
399 newline, 399 newline,
520 newline, 520 newline,
521 newline, 521 newline,
522 522
523 string "if (r != SQLITE_DONE) uw_error(ctx, FATAL, \"", 523 string "if (r != SQLITE_DONE) uw_error(ctx, FATAL, \"",
524 string (ErrorMsg.spanToString loc), 524 string (ErrorMsg.spanToString loc),
525 string ": query step failed: %s\\n%s\", ", 525 string ": query step failed: %s<br />%s\", ",
526 query, 526 query,
527 string ", sqlite3_errmsg(conn->conn));", 527 string ", sqlite3_errmsg(conn->conn));",
528 newline, 528 newline,
529 newline] 529 newline]
530 530
532 box [string "uw_conn *conn = uw_get_db(ctx);", 532 box [string "uw_conn *conn = uw_get_db(ctx);",
533 newline, 533 newline,
534 string "sqlite3_stmt *stmt;", 534 string "sqlite3_stmt *stmt;",
535 newline, 535 newline,
536 newline, 536 newline,
537 string "if (sqlite3_prepare_v2(conn->conn, query, -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: %s\\n%s\", sqlite3_errmsg(conn->conn));", 537 string "if (sqlite3_prepare_v2(conn->conn, query, -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: %s<br />%s\", sqlite3_errmsg(conn->conn), query);",
538 newline, 538 newline,
539 newline, 539 newline,
540 string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);", 540 string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);",
541 newline, 541 newline,
542 newline, 542 newline,
652 652
653 string "if (sqlite3_prepare_v2(conn->conn, \"", 653 string "if (sqlite3_prepare_v2(conn->conn, \"",
654 string (String.toString query), 654 string (String.toString query),
655 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ", 655 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ",
656 string (String.toString query), 656 string (String.toString query),
657 string "\\n%s\", sqlite3_errmsg(conn->conn));", 657 string "<br />%s\", sqlite3_errmsg(conn->conn));",
658 newline, 658 newline,
659 if nested then 659 if nested then
660 box [string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);", 660 box [string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);",
661 newline] 661 newline]
662 else 662 else
701 newline, 701 newline,
702 newline, 702 newline,
703 703
704 string "if (r != SQLITE_DONE) uw_error(ctx, FATAL, \"", 704 string "if (r != SQLITE_DONE) uw_error(ctx, FATAL, \"",
705 string (ErrorMsg.spanToString loc), 705 string (ErrorMsg.spanToString loc),
706 string ": DML step failed: %s\\n%s\", ", 706 string ": DML step failed: %s<br />%s\", ",
707 dml, 707 dml,
708 string ", sqlite3_errmsg(conn->conn));", 708 string ", sqlite3_errmsg(conn->conn));",
709 newline] 709 newline]
710 710
711 fun dml loc = 711 fun dml loc =
712 box [string "uw_conn *conn = uw_get_db(ctx);", 712 box [string "uw_conn *conn = uw_get_db(ctx);",
713 newline, 713 newline,
714 string "sqlite3_stmt *stmt;", 714 string "sqlite3_stmt *stmt;",
715 newline, 715 newline,
716 newline, 716 newline,
717 string "if (sqlite3_prepare_v2(conn->conn, dml, -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: %s\\n%s\", dml, sqlite3_errmsg(conn->conn));", 717 string "if (sqlite3_prepare_v2(conn->conn, dml, -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: %s<br />%s\", dml, sqlite3_errmsg(conn->conn));",
718 newline, 718 newline,
719 newline, 719 newline,
720 string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);", 720 string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);",
721 newline, 721 newline,
722 newline, 722 newline,
740 newline, 740 newline,
741 box [string "if (sqlite3_prepare_v2(conn->conn, \"", 741 box [string "if (sqlite3_prepare_v2(conn->conn, \"",
742 string (String.toString dml), 742 string (String.toString dml),
743 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ", 743 string "\", -1, &stmt, NULL) != SQLITE_OK) uw_error(ctx, FATAL, \"Error preparing statement: ",
744 string (String.toString dml), 744 string (String.toString dml),
745 string "\\n%s\", sqlite3_errmsg(conn->conn));", 745 string "<br />%s\", sqlite3_errmsg(conn->conn));",
746 newline, 746 newline,
747 string "conn->p", 747 string "conn->p",
748 string (Int.toString id), 748 string (Int.toString id),
749 string " = stmt;", 749 string " = stmt;",
750 newline], 750 newline],