Changeset 14758 for release/4/postgresql/trunk/postgresql.scm
- Timestamp:
- 05/24/09 19:38:28 (10 months ago)
- Files:
-
- 1 modified
-
release/4/postgresql/trunk/postgresql.scm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
release/4/postgresql/trunk/postgresql.scm
r14755 r14758 595 595 (let* ((unparsers (pg-connection-type-unparsers conn)) 596 596 (unparse (lambda (x) 597 (cond (raw x) 598 ((find (lambda (parse?) 597 (cond ((find (lambda (parse?) 599 598 ((car parse?) x)) 600 599 unparsers) => (lambda (parse) … … 604 603 (map ;; See if this can be moved into C 605 604 (lambda (p) 606 (let ((obj (unparse (if (pair? p) (car p) p))) 607 (oid (if (pair? p) (cdr p) 0))) 605 (let ((obj (if raw p (unparse p)))) 608 606 (when (and (not (string? obj)) 609 607 (not (blob? obj)) 610 608 (not (sql-null? obj))) 611 609 (postgresql-error 612 'exec-query (sprintf "Param value is not a string, sql-null or blob: ~S" p) 610 'exec-query 611 (sprintf "Param value is not a string, sql-null or blob: ~S" p) 613 612 conn query params format)) 614 (when (not (integer? oid)) 615 (postgresql-error 616 'exec-query (sprintf "Param type is not an oid: ~S" p) 617 conn query params format)) 618 (if (sql-null? obj) (cons #f oid) (cons obj oid)))) params)) 613 (if (sql-null? obj) #f obj))) params)) 619 614 (send-query 620 615 (foreign-lambda* … … 622 617 (int num) (scheme-object params) (int resfmt)) 623 618 "int res = 0, i = 0, *lens = NULL;" 624 "Oid *types = NULL;"625 619 "char **vals = NULL;" 626 620 "int *fmts = NULL;" 627 621 "C_word obj, cons;" 628 622 "if (num > 0) {" 629 " types = C_malloc(num * sizeof(Oid));"630 623 " vals = C_malloc(num * sizeof(char *));" 631 624 " lens = C_malloc(num * sizeof(int));" … … 634 627 "for (i=0,cons=params; i < num; ++i,cons=C_u_i_cdr(cons)) {" 635 628 " obj = C_u_i_car(cons);" 636 " types[i] = C_num_to_int(C_u_i_cdr(obj));" 637 " if (C_u_i_car(obj) == C_SCHEME_FALSE) {" 629 " if (obj == C_SCHEME_FALSE) {" 638 630 " fmts[i] = 0; /* don't care */" 639 631 " lens[i] = 0;" 640 632 " vals[i] = NULL;" 641 " } else if (C_header_bits( C_u_i_car(obj)) == C_BYTEVECTOR_TYPE) {"633 " } else if (C_header_bits(obj) == C_BYTEVECTOR_TYPE) {" 642 634 " fmts[i] = 1; /* binary */" 643 " lens[i] = C_header_size( C_u_i_car(obj));"644 " vals[i] = C_c_string( C_u_i_car(obj));"635 " lens[i] = C_header_size(obj);" 636 " vals[i] = C_c_string(obj);" 645 637 " } else {" 646 638 " /* text needs to be copied; it expects ASCIIZ */" 647 639 " fmts[i] = 0; /* text */" 648 " lens[i] = C_header_size( C_u_i_car(obj));"640 " lens[i] = C_header_size(obj);" 649 641 " vals[i] = malloc(lens[i] + 1);" 650 " memcpy(vals[i], C_c_string( C_u_i_car(obj)), lens[i]);"642 " memcpy(vals[i], C_c_string(obj), lens[i]);" 651 643 " vals[i][lens[i]] = '\\0';" 652 644 " }" 653 645 "}" 654 "res = PQsendQueryParams(conn, query, num, "655 " types,vals, lens, fmts, resfmt);"646 "res = PQsendQueryParams(conn, query, num, NULL," 647 " vals, lens, fmts, resfmt);" 656 648 "for (i=0,cons=params; i < num; ++i,cons=C_u_i_cdr(cons)) {" 657 649 " obj = C_u_i_car(cons);" 658 " if (!C_immediatep(C_u_i_car(obj)) &&" 659 " C_header_bits(C_u_i_car(obj)) == C_STRING_TYPE)" 650 " if (!C_immediatep(obj) && C_header_bits(obj) == C_STRING_TYPE)" 660 651 " free(vals[i]); /* Clear copied strings only */" 661 652 "}" … … 664 655 " free(lens);" 665 656 " free(vals);" 666 " free(types);"667 657 "}" 668 658 "C_return(res);")))
