comparison src/cjr_print.sml @ 687:a3ddf05fb3e3

On start-up, delete/nullify rows mentioning clients or channels
author Adam Chlipala <adamc@hcoop.net>
date Thu, 02 Apr 2009 11:42:26 -0400
parents f0224c7f12bb
children 829887ca47a6
comparison
equal deleted inserted replaced
686:3b46548f701b 687:a3ddf05fb3e3
1935 newline] 1935 newline]
1936 | DSequence x => box [string "/* SQL sequence ", 1936 | DSequence x => box [string "/* SQL sequence ",
1937 string x, 1937 string x,
1938 string " */", 1938 string " */",
1939 newline] 1939 newline]
1940 | DDatabase (s, n) => box [string "static void uw_db_validate(uw_context);", 1940 | DDatabase {name, expunge, initialize} =>
1941 newline, 1941 box [string "static void uw_db_validate(uw_context);",
1942 string "static void uw_db_prepare(uw_context);", 1942 newline,
1943 newline, 1943 string "static void uw_db_prepare(uw_context);",
1944 newline, 1944 newline,
1945 string "void uw_db_init(uw_context ctx) {", 1945 newline,
1946 newline, 1946 string "void uw_db_init(uw_context ctx) {",
1947 string "PGconn *conn = PQconnectdb(\"", 1947 newline,
1948 string (String.toString s), 1948 string "PGconn *conn = PQconnectdb(\"",
1949 string "\");", 1949 string (String.toString name),
1950 newline, 1950 string "\");",
1951 string "if (conn == NULL) uw_error(ctx, BOUNDED_RETRY, ", 1951 newline,
1952 string "\"libpq can't allocate a connection.\");", 1952 string "if (conn == NULL) uw_error(ctx, BOUNDED_RETRY, ",
1953 newline, 1953 string "\"libpq can't allocate a connection.\");",
1954 string "if (PQstatus(conn) != CONNECTION_OK) {", 1954 newline,
1955 newline, 1955 string "if (PQstatus(conn) != CONNECTION_OK) {",
1956 box [string "char msg[1024];", 1956 newline,
1957 newline, 1957 box [string "char msg[1024];",
1958 string "strncpy(msg, PQerrorMessage(conn), 1024);", 1958 newline,
1959 newline, 1959 string "strncpy(msg, PQerrorMessage(conn), 1024);",
1960 string "msg[1023] = 0;", 1960 newline,
1961 newline, 1961 string "msg[1023] = 0;",
1962 string "PQfinish(conn);", 1962 newline,
1963 newline, 1963 string "PQfinish(conn);",
1964 string "uw_error(ctx, BOUNDED_RETRY, ", 1964 newline,
1965 string "\"Connection to Postgres server failed: %s\", msg);"], 1965 string "uw_error(ctx, BOUNDED_RETRY, ",
1966 newline, 1966 string "\"Connection to Postgres server failed: %s\", msg);"],
1967 string "}", 1967 newline,
1968 newline, 1968 string "}",
1969 string "uw_set_db(ctx, conn);", 1969 newline,
1970 newline, 1970 string "uw_set_db(ctx, conn);",
1971 string "uw_db_validate(ctx);", 1971 newline,
1972 newline, 1972 string "uw_db_validate(ctx);",
1973 string "uw_db_prepare(ctx);", 1973 newline,
1974 newline, 1974 string "uw_db_prepare(ctx);",
1975 string "}", 1975 newline,
1976 newline, 1976 string "}",
1977 newline, 1977 newline,
1978 string "void uw_db_close(uw_context ctx) {", 1978 newline,
1979 newline, 1979 string "void uw_db_close(uw_context ctx) {",
1980 string "PQfinish(uw_get_db(ctx));", 1980 newline,
1981 newline, 1981 string "PQfinish(uw_get_db(ctx));",
1982 string "}", 1982 newline,
1983 newline, 1983 string "}",
1984 newline, 1984 newline,
1985 1985 newline,
1986 string "int uw_db_begin(uw_context ctx) {", 1986
1987 newline, 1987 string "int uw_db_begin(uw_context ctx) {",
1988 string "PGconn *conn = uw_get_db(ctx);", 1988 newline,
1989 newline, 1989 string "PGconn *conn = uw_get_db(ctx);",
1990 string "PGresult *res = PQexec(conn, \"BEGIN ISOLATION LEVEL SERIALIZABLE\");", 1990 newline,
1991 newline, 1991 string "PGresult *res = PQexec(conn, \"BEGIN ISOLATION LEVEL SERIALIZABLE\");",
1992 newline, 1992 newline,
1993 string "if (res == NULL) return 1;", 1993 newline,
1994 newline, 1994 string "if (res == NULL) return 1;",
1995 newline, 1995 newline,
1996 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", 1996 newline,
1997 box [string "PQclear(res);", 1997 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
1998 newline, 1998 box [string "PQclear(res);",
1999 string "return 1;", 1999 newline,
2000 newline], 2000 string "return 1;",
2001 string "}", 2001 newline],
2002 newline, 2002 string "}",
2003 string "return 0;", 2003 newline,
2004 newline, 2004 string "return 0;",
2005 string "}", 2005 newline,
2006 newline, 2006 string "}",
2007 newline, 2007 newline,
2008 2008 newline,
2009 string "int uw_db_commit(uw_context ctx) {", 2009
2010 newline, 2010 string "int uw_db_commit(uw_context ctx) {",
2011 string "PGconn *conn = uw_get_db(ctx);", 2011 newline,
2012 newline, 2012 string "PGconn *conn = uw_get_db(ctx);",
2013 string "PGresult *res = PQexec(conn, \"COMMIT\");", 2013 newline,
2014 newline, 2014 string "PGresult *res = PQexec(conn, \"COMMIT\");",
2015 newline, 2015 newline,
2016 string "if (res == NULL) return 1;", 2016 newline,
2017 newline, 2017 string "if (res == NULL) return 1;",
2018 newline, 2018 newline,
2019 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", 2019 newline,
2020 box [string "PQclear(res);", 2020 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
2021 newline, 2021 box [string "PQclear(res);",
2022 string "return 1;", 2022 newline,
2023 newline], 2023 string "return 1;",
2024 string "}", 2024 newline],
2025 newline, 2025 string "}",
2026 string "return 0;", 2026 newline,
2027 newline, 2027 string "return 0;",
2028 string "}", 2028 newline,
2029 newline, 2029 string "}",
2030 newline, 2030 newline,
2031 2031 newline,
2032 string "int uw_db_rollback(uw_context ctx) {", 2032
2033 newline, 2033 string "int uw_db_rollback(uw_context ctx) {",
2034 string "PGconn *conn = uw_get_db(ctx);", 2034 newline,
2035 newline, 2035 string "PGconn *conn = uw_get_db(ctx);",
2036 string "PGresult *res = PQexec(conn, \"ROLLBACK\");", 2036 newline,
2037 newline, 2037 string "PGresult *res = PQexec(conn, \"ROLLBACK\");",
2038 newline, 2038 newline,
2039 string "if (res == NULL) return 1;", 2039 newline,
2040 newline, 2040 string "if (res == NULL) return 1;",
2041 newline, 2041 newline,
2042 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", 2042 newline,
2043 box [string "PQclear(res);", 2043 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
2044 newline, 2044 box [string "PQclear(res);",
2045 string "return 1;", 2045 newline,
2046 newline], 2046 string "return 1;",
2047 string "}", 2047 newline],
2048 newline, 2048 string "}",
2049 string "return 0;", 2049 newline,
2050 newline, 2050 string "return 0;",
2051 string "}", 2051 newline,
2052 newline, 2052 string "}",
2053 newline, 2053 newline,
2054 2054 newline,
2055 string "void uw_expunger(uw_context ctx, uw_Basis_client cli) {", 2055
2056 newline, 2056 string "void uw_expunger(uw_context ctx, uw_Basis_client cli) {",
2057 box [p_enamed env n, 2057 newline,
2058 string "(ctx, cli);", 2058 box [p_enamed env expunge,
2059 newline], 2059 string "(ctx, cli);",
2060 string "}", 2060 newline],
2061 newline] 2061 string "}",
2062 newline,
2063 newline,
2064
2065 string "void uw_initializer(uw_context ctx) {",
2066 newline,
2067 box [p_enamed env initialize,
2068 string "(ctx, uw_unit_v);",
2069 newline],
2070 string "}",
2071 newline]
2062 2072
2063 | DPreparedStatements [] => 2073 | DPreparedStatements [] =>
2064 box [string "static void uw_db_prepare(uw_context ctx) {", 2074 box [string "static void uw_db_prepare(uw_context ctx) {",
2065 newline, 2075 newline,
2066 string "}"] 2076 string "}"]
2760 string "int uw_db_commit(uw_context ctx) { return 0; };", 2770 string "int uw_db_commit(uw_context ctx) { return 0; };",
2761 newline, 2771 newline,
2762 string "int uw_db_rollback(uw_context ctx) { return 0; };", 2772 string "int uw_db_rollback(uw_context ctx) { return 0; };",
2763 newline, 2773 newline,
2764 string "void uw_expunger(uw_context ctx, uw_Basis_client cli) { };", 2774 string "void uw_expunger(uw_context ctx, uw_Basis_client cli) { };",
2775 newline,
2776 string "void uw_initializer(uw_context ctx) { };",
2765 newline]] 2777 newline]]
2766 end 2778 end
2767 2779
2768 fun p_sql env (ds, _) = 2780 fun p_sql env (ds, _) =
2769 let 2781 let