Show
Ignore:
Timestamp:
05/24/09 19:38:28 (16 months ago)
Author:
sjamaan
Message:

Get rid of value/oid pair option. It complicates the code too much and isn't really useful at all. Besides, it also messes with the option to support list datatypes; how would you distinguish between a value/oid pair and a list?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • release/4/postgresql/trunk/postgresql.scm

    r14755 r14758  
    595595  (let* ((unparsers (pg-connection-type-unparsers conn)) 
    596596         (unparse (lambda (x) 
    597                     (cond (raw x) 
    598                           ((find (lambda (parse?) 
     597                    (cond ((find (lambda (parse?) 
    599598                                   ((car parse?) x)) 
    600599                                 unparsers) => (lambda (parse) 
     
    604603          (map   ;; See if this can be moved into C 
    605604           (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)))) 
    608606               (when (and (not (string? obj)) 
    609607                          (not (blob? obj)) 
    610608                          (not (sql-null? obj))) 
    611609                 (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) 
    613612                  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)) 
    619614         (send-query 
    620615          (foreign-lambda* 
     
    622617                 (int num) (scheme-object params) (int resfmt)) 
    623618           "int res = 0, i = 0, *lens = NULL;" 
    624            "Oid *types = NULL;" 
    625619           "char **vals = NULL;" 
    626620           "int *fmts = NULL;" 
    627621           "C_word obj, cons;" 
    628622           "if (num > 0) {" 
    629            "    types = C_malloc(num * sizeof(Oid));" 
    630623           "    vals = C_malloc(num * sizeof(char *));" 
    631624           "    lens = C_malloc(num * sizeof(int));" 
     
    634627           "for (i=0,cons=params; i < num; ++i,cons=C_u_i_cdr(cons)) {" 
    635628           "    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) {" 
    638630           "        fmts[i] = 0; /* don't care */" 
    639631           "        lens[i] = 0;" 
    640632           "        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) {" 
    642634           "        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);" 
    645637           "    } else {" 
    646638           "        /* text needs to be copied; it expects ASCIIZ */" 
    647639           "        fmts[i] = 0; /* text */" 
    648            "        lens[i] = C_header_size(C_u_i_car(obj));" 
     640           "        lens[i] = C_header_size(obj);" 
    649641           "        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]);" 
    651643           "        vals[i][lens[i]] = '\\0';" 
    652644           "    }" 
    653645           "}" 
    654            "res = PQsendQueryParams(conn, query, num, " 
    655            "                        types, vals, lens, fmts, resfmt);" 
     646           "res = PQsendQueryParams(conn, query, num, NULL," 
     647           "                        vals, lens, fmts, resfmt);" 
    656648           "for (i=0,cons=params; i < num; ++i,cons=C_u_i_cdr(cons)) {" 
    657649           "    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)" 
    660651           "        free(vals[i]); /* Clear copied strings only */" 
    661652           "}" 
     
    664655           "    free(lens);" 
    665656           "    free(vals);" 
    666            "    free(types);" 
    667657           "}" 
    668658           "C_return(res);")))