comparison src/cjr_print.sml @ 683:9a2c18dab11d

Expunging non-nullable rows
author Adam Chlipala <adamc@hcoop.net>
date Sun, 29 Mar 2009 13:30:01 -0400
parents 5bbb542243e8
children f0224c7f12bb
comparison
equal deleted inserted replaced
682:5bbb542243e8 683:9a2c18dab11d
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 => box [string "static void uw_db_validate(uw_context);", 1940 | DDatabase (s, n) => box [string "static void uw_db_validate(uw_context);",
1941 newline, 1941 newline,
1942 string "static void uw_db_prepare(uw_context);", 1942 string "static void uw_db_prepare(uw_context);",
1943 newline, 1943 newline,
1944 newline, 1944 newline,
1945 string "void uw_db_init(uw_context ctx) {", 1945 string "void uw_db_init(uw_context ctx) {",
1946 newline, 1946 newline,
1947 string "PGconn *conn = PQconnectdb(\"", 1947 string "PGconn *conn = PQconnectdb(\"",
1948 string (String.toString s), 1948 string (String.toString s),
1949 string "\");", 1949 string "\");",
1950 newline, 1950 newline,
1951 string "if (conn == NULL) uw_error(ctx, BOUNDED_RETRY, ", 1951 string "if (conn == NULL) uw_error(ctx, BOUNDED_RETRY, ",
1952 string "\"libpq can't allocate a connection.\");", 1952 string "\"libpq can't allocate a connection.\");",
1953 newline, 1953 newline,
1954 string "if (PQstatus(conn) != CONNECTION_OK) {", 1954 string "if (PQstatus(conn) != CONNECTION_OK) {",
1955 newline, 1955 newline,
1956 box [string "char msg[1024];", 1956 box [string "char msg[1024];",
1957 newline, 1957 newline,
1958 string "strncpy(msg, PQerrorMessage(conn), 1024);", 1958 string "strncpy(msg, PQerrorMessage(conn), 1024);",
1959 newline, 1959 newline,
1960 string "msg[1023] = 0;", 1960 string "msg[1023] = 0;",
1961 newline, 1961 newline,
1962 string "PQfinish(conn);", 1962 string "PQfinish(conn);",
1963 newline, 1963 newline,
1964 string "uw_error(ctx, BOUNDED_RETRY, ", 1964 string "uw_error(ctx, BOUNDED_RETRY, ",
1965 string "\"Connection to Postgres server failed: %s\", msg);"], 1965 string "\"Connection to Postgres server failed: %s\", msg);"],
1966 newline, 1966 newline,
1967 string "}", 1967 string "}",
1968 newline, 1968 newline,
1969 string "uw_set_db(ctx, conn);", 1969 string "uw_set_db(ctx, conn);",
1970 newline, 1970 newline,
1971 string "uw_db_validate(ctx);", 1971 string "uw_db_validate(ctx);",
1972 newline, 1972 newline,
1973 string "uw_db_prepare(ctx);", 1973 string "uw_db_prepare(ctx);",
1974 newline, 1974 newline,
1975 string "}", 1975 string "}",
1976 newline, 1976 newline,
1977 newline, 1977 newline,
1978 string "void uw_db_close(uw_context ctx) {", 1978 string "void uw_db_close(uw_context ctx) {",
1979 newline, 1979 newline,
1980 string "PQfinish(uw_get_db(ctx));", 1980 string "PQfinish(uw_get_db(ctx));",
1981 newline, 1981 newline,
1982 string "}", 1982 string "}",
1983 newline, 1983 newline,
1984 newline, 1984 newline,
1985 1985
1986 string "int uw_db_begin(uw_context ctx) {", 1986 string "int uw_db_begin(uw_context ctx) {",
1987 newline, 1987 newline,
1988 string "PGconn *conn = uw_get_db(ctx);", 1988 string "PGconn *conn = uw_get_db(ctx);",
1989 newline, 1989 newline,
1990 string "PGresult *res = PQexec(conn, \"BEGIN ISOLATION LEVEL SERIALIZABLE\");", 1990 string "PGresult *res = PQexec(conn, \"BEGIN ISOLATION LEVEL SERIALIZABLE\");",
1991 newline, 1991 newline,
1992 newline, 1992 newline,
1993 string "if (res == NULL) return 1;", 1993 string "if (res == NULL) return 1;",
1994 newline, 1994 newline,
1995 newline, 1995 newline,
1996 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", 1996 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
1997 box [string "PQclear(res);", 1997 box [string "PQclear(res);",
1998 newline, 1998 newline,
1999 string "return 1;", 1999 string "return 1;",
2000 newline], 2000 newline],
2001 string "}", 2001 string "}",
2002 newline, 2002 newline,
2003 string "return 0;", 2003 string "return 0;",
2004 newline, 2004 newline,
2005 string "}", 2005 string "}",
2006 newline, 2006 newline,
2007 newline, 2007 newline,
2008 2008
2009 string "int uw_db_commit(uw_context ctx) {", 2009 string "int uw_db_commit(uw_context ctx) {",
2010 newline, 2010 newline,
2011 string "PGconn *conn = uw_get_db(ctx);", 2011 string "PGconn *conn = uw_get_db(ctx);",
2012 newline, 2012 newline,
2013 string "PGresult *res = PQexec(conn, \"COMMIT\");", 2013 string "PGresult *res = PQexec(conn, \"COMMIT\");",
2014 newline, 2014 newline,
2015 newline, 2015 newline,
2016 string "if (res == NULL) return 1;", 2016 string "if (res == NULL) return 1;",
2017 newline, 2017 newline,
2018 newline, 2018 newline,
2019 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", 2019 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
2020 box [string "PQclear(res);", 2020 box [string "PQclear(res);",
2021 newline, 2021 newline,
2022 string "return 1;", 2022 string "return 1;",
2023 newline], 2023 newline],
2024 string "}", 2024 string "}",
2025 newline, 2025 newline,
2026 string "return 0;", 2026 string "return 0;",
2027 newline, 2027 newline,
2028 string "}", 2028 string "}",
2029 newline, 2029 newline,
2030 newline, 2030 newline,
2031 2031
2032 string "int uw_db_rollback(uw_context ctx) {", 2032 string "int uw_db_rollback(uw_context ctx) {",
2033 newline, 2033 newline,
2034 string "PGconn *conn = uw_get_db(ctx);", 2034 string "PGconn *conn = uw_get_db(ctx);",
2035 newline, 2035 newline,
2036 string "PGresult *res = PQexec(conn, \"ROLLBACK\");", 2036 string "PGresult *res = PQexec(conn, \"ROLLBACK\");",
2037 newline, 2037 newline,
2038 newline, 2038 newline,
2039 string "if (res == NULL) return 1;", 2039 string "if (res == NULL) return 1;",
2040 newline, 2040 newline,
2041 newline, 2041 newline,
2042 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {", 2042 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
2043 box [string "PQclear(res);", 2043 box [string "PQclear(res);",
2044 newline, 2044 newline,
2045 string "return 1;", 2045 string "return 1;",
2046 newline], 2046 newline],
2047 string "}", 2047 string "}",
2048 newline, 2048 newline,
2049 string "return 0;", 2049 string "return 0;",
2050 newline, 2050 newline,
2051 string "}", 2051 string "}",
2052 newline] 2052 newline,
2053 newline,
2054
2055 string "void uw_expunger(uw_context ctx, uw_Basis_client cli) {",
2056 newline,
2057 box [p_enamed env n,
2058 string "(ctx, cli);",
2059 newline],
2060 string "}",
2061 newline]
2053 2062
2054 | DPreparedStatements [] => 2063 | DPreparedStatements [] =>
2055 box [string "static void uw_db_prepare(uw_context ctx) {", 2064 box [string "static void uw_db_prepare(uw_context ctx) {",
2056 newline, 2065 newline,
2057 string "}"] 2066 string "}"]