comparison src/postgres.sml @ 1094:db52c32dbe42

All three current protocols work with move to using uw_app
author Adam Chlipala <adamc@hcoop.net>
date Sun, 27 Dec 2009 10:37:24 -0500
parents b2311dfb3158
children bafb6a5a52a9
comparison
equal deleted inserted replaced
1093:8d3aa6c7cee0 1094:db52c32dbe42
247 newline] 247 newline]
248 end 248 end
249 249
250 fun init {dbstring, prepared = ss, tables, views, sequences} = 250 fun init {dbstring, prepared = ss, tables, views, sequences} =
251 box [if #persistent (currentProtocol ()) then 251 box [if #persistent (currentProtocol ()) then
252 box [string "void uw_client_init(void) {", 252 box [string "static void uw_db_validate(uw_context ctx) {",
253 newline,
254 box [string "uw_sqlfmtInt = \"%lld::int8%n\";",
255 newline,
256 string "uw_sqlfmtFloat = \"%g::float8%n\";",
257 newline,
258 string "uw_Estrings = 1;",
259 newline,
260 string "uw_sqlsuffixString = \"::text\";",
261 newline,
262 string "uw_sqlsuffixChar = \"::char\";",
263 newline,
264 string "uw_sqlsuffixBlob = \"::bytea\";",
265 newline,
266 string "uw_sqlfmtUint4 = \"%u::int4%n\";",
267 newline],
268 string "}",
269 newline,
270 newline,
271
272 string "static void uw_db_validate(uw_context ctx) {",
273 newline, 253 newline,
274 string "PGconn *conn = uw_get_db(ctx);", 254 string "PGconn *conn = uw_get_db(ctx);",
275 newline, 255 newline,
276 string "PGresult *res;", 256 string "PGresult *res;",
277 newline, 257 newline,
378 newline]) 358 newline])
379 ss, 359 ss,
380 360
381 string "}", 361 string "}",
382 newline, 362 newline,
383 newline,
384
385 string "void uw_db_close(uw_context ctx) {",
386 newline,
387 string "PQfinish(uw_get_db(ctx));",
388 newline,
389 string "}",
390 newline,
391 newline,
392
393 string "int uw_db_begin(uw_context ctx) {",
394 newline,
395 string "PGconn *conn = uw_get_db(ctx);",
396 newline,
397 string "PGresult *res = PQexec(conn, \"BEGIN ISOLATION LEVEL SERIALIZABLE\");",
398 newline,
399 newline,
400 string "if (res == NULL) return 1;",
401 newline,
402 newline,
403 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
404 box [string "PQclear(res);",
405 newline,
406 string "return 1;",
407 newline],
408 string "}",
409 newline,
410 string "return 0;",
411 newline,
412 string "}",
413 newline,
414 newline,
415
416 string "int uw_db_commit(uw_context ctx) {",
417 newline,
418 string "PGconn *conn = uw_get_db(ctx);",
419 newline,
420 string "PGresult *res = PQexec(conn, \"COMMIT\");",
421 newline,
422 newline,
423 string "if (res == NULL) return 1;",
424 newline,
425 newline,
426 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
427 box [string "PQclear(res);",
428 newline,
429 string "return 1;",
430 newline],
431 string "}",
432 newline,
433 string "return 0;",
434 newline,
435 string "}",
436 newline,
437 newline,
438
439 string "int uw_db_rollback(uw_context ctx) {",
440 newline,
441 string "PGconn *conn = uw_get_db(ctx);",
442 newline,
443 string "PGresult *res = PQexec(conn, \"ROLLBACK\");",
444 newline,
445 newline,
446 string "if (res == NULL) return 1;",
447 newline,
448 newline,
449 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
450 box [string "PQclear(res);",
451 newline,
452 string "return 1;",
453 newline],
454 string "}",
455 newline,
456 string "return 0;",
457 newline,
458 string "}",
459 newline,
460 newline] 363 newline]
461 else 364 else
462 box [string "static void uw_db_validate(uw_context ctx) { }", 365 box [string "static void uw_db_validate(uw_context ctx) { }",
463 newline, 366 newline,
464 string "static void uw_db_prepare(uw_context ctx) { }"], 367 string "static void uw_db_prepare(uw_context ctx) { }"],
465 368
466 newline, 369 string "static void uw_client_init(void) {",
467 newline, 370 newline,
468 371 box [string "uw_sqlfmtInt = \"%lld::int8%n\";",
469 string "void uw_db_init(uw_context ctx) {", 372 newline,
373 string "uw_sqlfmtFloat = \"%g::float8%n\";",
374 newline,
375 string "uw_Estrings = 1;",
376 newline,
377 string "uw_sqlsuffixString = \"::text\";",
378 newline,
379 string "uw_sqlsuffixChar = \"::char\";",
380 newline,
381 string "uw_sqlsuffixBlob = \"::bytea\";",
382 newline,
383 string "uw_sqlfmtUint4 = \"%u::int4%n\";",
384 newline],
385 string "}",
386 newline,
387 newline,
388
389 string "static void uw_db_close(uw_context ctx) {",
390 newline,
391 string "PQfinish(uw_get_db(ctx));",
392 newline,
393 string "}",
394 newline,
395 newline,
396
397 string "static int uw_db_begin(uw_context ctx) {",
398 newline,
399 string "PGconn *conn = uw_get_db(ctx);",
400 newline,
401 string "PGresult *res = PQexec(conn, \"BEGIN ISOLATION LEVEL SERIALIZABLE\");",
402 newline,
403 newline,
404 string "if (res == NULL) return 1;",
405 newline,
406 newline,
407 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
408 box [string "PQclear(res);",
409 newline,
410 string "return 1;",
411 newline],
412 string "}",
413 newline,
414 string "return 0;",
415 newline,
416 string "}",
417 newline,
418 newline,
419
420 string "static int uw_db_commit(uw_context ctx) {",
421 newline,
422 string "PGconn *conn = uw_get_db(ctx);",
423 newline,
424 string "PGresult *res = PQexec(conn, \"COMMIT\");",
425 newline,
426 newline,
427 string "if (res == NULL) return 1;",
428 newline,
429 newline,
430 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
431 box [string "PQclear(res);",
432 newline,
433 string "return 1;",
434 newline],
435 string "}",
436 newline,
437 string "return 0;",
438 newline,
439 string "}",
440 newline,
441 newline,
442
443 string "static int uw_db_rollback(uw_context ctx) {",
444 newline,
445 string "PGconn *conn = uw_get_db(ctx);",
446 newline,
447 string "PGresult *res = PQexec(conn, \"ROLLBACK\");",
448 newline,
449 newline,
450 string "if (res == NULL) return 1;",
451 newline,
452 newline,
453 string "if (PQresultStatus(res) != PGRES_COMMAND_OK) {",
454 box [string "PQclear(res);",
455 newline,
456 string "return 1;",
457 newline],
458 string "}",
459 newline,
460 string "return 0;",
461 newline,
462 string "}",
463
464 newline,
465 newline,
466
467 string "static void uw_db_init(uw_context ctx) {",
470 newline, 468 newline,
471 string "PGconn *conn = PQconnectdb(\"", 469 string "PGconn *conn = PQconnectdb(\"",
472 string (String.toString dbstring), 470 string (String.toString dbstring),
473 string "\");", 471 string "\");",
474 newline, 472 newline,