Changeset 30226 in project


Ignore:
Timestamp:
12/27/13 21:55:01 (7 years ago)
Author:
sjamaan
Message:

postgresql: Make value-at* play nice with the stack even with arbitrary string lengths by allocating in Scheme. Unfortunately, this means a small drop in performance compared to the raw C_alloc() version :(

File:
1 edited

Legend:

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

    r30224 r30226  
    109109(define PQfmod (foreign-lambda int PQfmod (const pgresult*) int))
    110110(define PQgetisnull (foreign-lambda bool PQgetisnull (const pgresult*) int int))
     111(define PQgetlength (foreign-lambda int PQgetlength (const pgresult*) int int))
     112(define PQgetvalue-ptr (foreign-lambda (c-pointer char) PQgetvalue (const pgresult*) int int))
    111113(define PQcmdTuples (foreign-lambda nonnull-c-string PQcmdTuples pgresult*))
    112114(define PQoidValue (foreign-lambda oid PQoidValue pgresult*))
     
    637639;; Unchecked version, for speed
    638640(define (value-at* result column row #!key raw)
    639   (if (PQgetisnull (pg-result-ptr result) row column)
    640       (sql-null)
    641       (let ((value ((foreign-primitive
    642                      scheme-object ((c-pointer res) (int row) (int col))
    643                      "C_word fin, *str; char *val; int len;"
    644                      "len = PQgetlength(res, row, col);"
    645                      "str = C_alloc(C_SIZEOF_STRING(len));"
    646                      "val = PQgetvalue(res, row, col);"
    647                      "fin = C_string(&str, len, val);"
    648                      "if (PQfformat(res, col) == 1) /* binary? */"
    649                      "        C_string_to_bytevector(fin);"
    650                      "C_return(fin);")
    651                     (pg-result-ptr result) row column)))
    652         (if (or raw (blob? value))
    653             value
    654             ((vector-ref (pg-result-value-parsers result) column) value)))))
     641  (let ((ptr (pg-result-ptr result)))
     642   (if (PQgetisnull ptr row column)
     643       (sql-null)
     644       (let* ((len (PQgetlength ptr row column))
     645              (fmt (PQfformat ptr column))
     646              (value (case fmt
     647                       ((0) (make-string len))
     648                       ((1) (make-blob len))
     649                       (else (postgresql-error
     650                              'internal 'value-at
     651                              (conc "Unknown column format type: " fmt)
     652                              result column row raw)))))
     653       ((foreign-lambda c-pointer "C_memcpy" scheme-pointer c-pointer size_t)
     654          value (PQgetvalue-ptr ptr row column) len)
     655         (if (or raw (blob? value))
     656             value
     657             ((vector-ref (pg-result-value-parsers result) column) value))))))
    655658
    656659(define (value-at result #!optional (column 0) (row 0) #!key raw)
Note: See TracChangeset for help on using the changeset viewer.