Changeset 14725 in project


Ignore:
Timestamp:
05/21/09 22:12:46 (10 years ago)
Author:
sjamaan
Message:

Improve binary mode result fetching by sticking it into a blob.
The user should figure out what the fuck to do with it :)
(the internal representation is used on the wire and this may change, especially for complex datatypes)

Location:
release/4/postgresql/trunk
Files:
2 edited

Legend:

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

    r14724 r14725  
    316316                       (int row)
    317317                       (int col))
    318         "C_word *fin; char *val; int len;"
     318        "C_word fin, *str; char *val; int len;"
    319319        "len = PQgetlength(res, row, col);"
    320         "fin = C_alloc(C_bytestowords(len + sizeof(C_header)));"
     320        "str = C_alloc(C_bytestowords(len + sizeof(C_header)));"
    321321        "val = PQgetvalue(res, row, col);"
    322         "C_return(C_string(&fin, len, val));")
     322        "fin = C_string(&str, len, val);"
     323        "if (PQfformat(res, col) == 1) /* binary? */"
     324        "        C_string_to_bytevector(fin);"
     325        "C_return(fin);")
    323326       (pg-result-ptr result) row column)))
    324327
  • release/4/postgresql/trunk/tests/run.scm

    r14724 r14725  
    116116  ;; performs another string interpretation. Yes, this is kinda confusing...
    117117  (test "Result value for null-terminated normal string"
    118         "h\\000ello"
     118        "h\\000ello" ;; This would then be decoded using unescape-bytea
    119119        (result-value
    120120         (car (exec-query conn "SELECT E'h\\\\000ello'::bytea")) 0 0))
    121   (test "Result value string for binary values"
    122         "hello"
     121  (test "Result value blob for binary string"
     122        (string->blob "hello")
    123123        (result-value
    124124         (cadr (exec-query conn
    125125                           (conc "DECLARE b1 BINARY CURSOR FOR SELECT 'hello';"
     126                                 "FETCH FORWARD 1 FROM b1;"
     127                                 "CLOSE b1"))) 0 0))
     128  (test "Result value blob for binary integer"
     129        (u8vector->blob (u8vector 0 0 0 1))
     130        (result-value
     131         (cadr (exec-query conn
     132                           (conc "DECLARE b1 BINARY CURSOR FOR SELECT 1::int4;"
    126133                                 "FETCH FORWARD 1 FROM b1;"
    127134                                 "CLOSE b1"))) 0 0))
    128135  (test "Result value for null-terminated binary string"
    129         "h\x00ello"
     136        (string->blob "h\x00ello")
    130137        (result-value
    131138         (cadr (exec-query conn
Note: See TracChangeset for help on using the changeset viewer.