Mercurial > urweb
comparison src/sqlite.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 |
---|---|
686 box [] | 686 box [] |
687 else | 687 else |
688 box [string "uw_pop_cleanup(ctx);", | 688 box [string "uw_pop_cleanup(ctx);", |
689 newline]] | 689 newline]] |
690 | 690 |
691 fun dmlCommon {loc, dml} = | 691 fun dmlCommon {loc, dml, mode} = |
692 box [string "int r;", | 692 box [string "int r;", |
693 newline, | 693 newline, |
694 | 694 |
695 string "if ((r = sqlite3_step(stmt)) == SQLITE_BUSY) {", | 695 string "if ((r = sqlite3_step(stmt)) == SQLITE_BUSY) {", |
696 box [string "sleep(1);", | 696 box [string "sleep(1);", |
699 newline], | 699 newline], |
700 string "}", | 700 string "}", |
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) ", |
705 string (ErrorMsg.spanToString loc), | 705 case mode of |
706 string ": DML step failed: %s<br />%s\", ", | 706 Settings.Error => box [string "uw_error(ctx, FATAL, \"", |
707 dml, | 707 string (ErrorMsg.spanToString loc), |
708 string ", sqlite3_errmsg(conn->conn));", | 708 string ": DML step failed: %s<br />%s\", ", |
709 dml, | |
710 string ", sqlite3_errmsg(conn->conn));"] | |
711 | Settings.None => string "uw_errmsg = sqlite3_errmsg(conn->conn);", | |
709 newline] | 712 newline] |
710 | 713 |
711 fun dml loc = | 714 fun dml (loc, mode) = |
712 box [string "uw_conn *conn = uw_get_db(ctx);", | 715 box [string "uw_conn *conn = uw_get_db(ctx);", |
713 newline, | 716 newline, |
714 string "sqlite3_stmt *stmt;", | 717 string "sqlite3_stmt *stmt;", |
715 newline, | 718 newline, |
716 newline, | 719 newline, |
719 newline, | 722 newline, |
720 string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);", | 723 string "uw_push_cleanup(ctx, (void (*)(void *))sqlite3_finalize, stmt);", |
721 newline, | 724 newline, |
722 newline, | 725 newline, |
723 | 726 |
724 dmlCommon {loc = loc, dml = string "dml"}, | 727 dmlCommon {loc = loc, dml = string "dml", mode = mode}, |
725 | 728 |
726 string "uw_pop_cleanup(ctx);", | 729 string "uw_pop_cleanup(ctx);", |
727 newline] | 730 newline] |
728 | 731 |
729 fun dmlPrepared {loc, id, dml, inputs} = | 732 fun dmlPrepared {loc, id, dml, inputs, mode = mode} = |
730 box [string "uw_conn *conn = uw_get_db(ctx);", | 733 box [string "uw_conn *conn = uw_get_db(ctx);", |
731 newline, | 734 newline, |
732 p_pre_inputs inputs, | 735 p_pre_inputs inputs, |
733 string "sqlite3_stmt *stmt = conn->p", | 736 string "sqlite3_stmt *stmt = conn->p", |
734 string (Int.toString id), | 737 string (Int.toString id), |
759 p_inputs loc inputs, | 762 p_inputs loc inputs, |
760 newline, | 763 newline, |
761 | 764 |
762 dmlCommon {loc = loc, dml = box [string "\"", | 765 dmlCommon {loc = loc, dml = box [string "\"", |
763 string (String.toCString dml), | 766 string (String.toCString dml), |
764 string "\""]}, | 767 string "\""], mode = mode}, |
765 | 768 |
766 string "uw_pop_cleanup(ctx);", | 769 string "uw_pop_cleanup(ctx);", |
767 newline, | 770 newline, |
768 string "uw_pop_cleanup(ctx);", | 771 string "uw_pop_cleanup(ctx);", |
769 newline] | 772 newline] |