Mercurial > urweb
comparison src/cjr_print.sml @ 747:e42f08f96eb5
Extra checks on assumptions about SQL results
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 26 Apr 2009 12:47:53 -0400 |
parents | cd67c3a942e3 |
children | 8688e01ae469 |
comparison
equal
deleted
inserted
replaced
746:2c7244c066f1 | 747:e42f08f96eb5 |
---|---|
416 string "ERROR") | 416 string "ERROR") |
417 | 417 |
418 fun p_getcol wontLeakStrings env (tAll as (t, loc)) i = | 418 fun p_getcol wontLeakStrings env (tAll as (t, loc)) i = |
419 case t of | 419 case t of |
420 TOption t => | 420 TOption t => |
421 box [string "(PQgetisnull (res, i, ", | 421 box [string "(PQgetisnull(res, i, ", |
422 string (Int.toString i), | 422 string (Int.toString i), |
423 string ") ? NULL : ", | 423 string ") ? NULL : ", |
424 case t of | 424 case t of |
425 (TFfi ("Basis", "string"), _) => p_getcol wontLeakStrings env t i | 425 (TFfi ("Basis", "string"), _) => p_getcol wontLeakStrings env t i |
426 | _ => box [string "({", | 426 | _ => box [string "({", |
438 string "tmp;", | 438 string "tmp;", |
439 newline, | 439 newline, |
440 string "})"], | 440 string "})"], |
441 string ")"] | 441 string ")"] |
442 | _ => | 442 | _ => |
443 p_unsql wontLeakStrings env tAll | 443 box [string "(PQgetisnull(res, i, ", |
444 (box [string "PQgetvalue(res, i, ", | 444 string (Int.toString i), |
445 string (Int.toString i), | 445 string ") ? ", |
446 string ")"]) | 446 box [string "({", |
447 (box [string "PQgetlength(res, i, ", | 447 p_typ env tAll, |
448 string (Int.toString i), | 448 space, |
449 string ")"]) | 449 string "tmp;", |
450 newline, | |
451 string "uw_error(ctx, FATAL, \"Unexpectedly NULL field #", | |
452 string (Int.toString i), | |
453 string "\");", | |
454 newline, | |
455 string "tmp;", | |
456 newline, | |
457 string "})"], | |
458 string " : ", | |
459 p_unsql wontLeakStrings env tAll | |
460 (box [string "PQgetvalue(res, i, ", | |
461 string (Int.toString i), | |
462 string ")"]) | |
463 (box [string "PQgetlength(res, i, ", | |
464 string (Int.toString i), | |
465 string ")"]), | |
466 string ")"] | |
450 | 467 |
451 datatype sql_type = | 468 datatype sql_type = |
452 Int | 469 Int |
453 | Float | 470 | Float |
454 | String | 471 | String |
1564 string ": Query failed:\\n%s\\n%s\", ", | 1581 string ": Query failed:\\n%s\\n%s\", ", |
1565 case prepared of | 1582 case prepared of |
1566 NONE => string "query" | 1583 NONE => string "query" |
1567 | SOME _ => p_exp env query, | 1584 | SOME _ => p_exp env query, |
1568 string ", PQerrorMessage(conn));", | 1585 string ", PQerrorMessage(conn));", |
1586 newline], | |
1587 string "}", | |
1588 newline, | |
1589 newline, | |
1590 | |
1591 string "if (PQnfields(res) != ", | |
1592 string (Int.toString (length outputs)), | |
1593 string ") {", | |
1594 newline, | |
1595 box [string "int nf = PQnfields(res);", | |
1596 newline, | |
1597 string "PQclear(res);", | |
1598 newline, | |
1599 string "uw_error(ctx, FATAL, \"", | |
1600 string (ErrorMsg.spanToString loc), | |
1601 string ": Query returned %d columns instead of ", | |
1602 string (Int.toString (length outputs)), | |
1603 string ":\\n%s\\n%s\", ", | |
1604 case prepared of | |
1605 NONE => string "query" | |
1606 | SOME _ => p_exp env query, | |
1607 string ", nf, PQerrorMessage(conn));", | |
1569 newline], | 1608 newline], |
1570 string "}", | 1609 string "}", |
1571 newline, | 1610 newline, |
1572 newline, | 1611 newline, |
1573 | 1612 |