src/evsql/util.c
changeset 30 d8fabd347a8e
parent 29 5de62ca9a5aa
child 31 7804cd7b5cd5
equal deleted inserted replaced
29:5de62ca9a5aa 30:d8fabd347a8e
    62         default:
    62         default:
    63             FATAL("res->evsql->type");
    63             FATAL("res->evsql->type");
    64     }
    64     }
    65 }
    65 }
    66 
    66 
    67 int evsql_result_binary (const struct evsql_result_info *res, size_t row, size_t col, const char **ptr, size_t size, int nullok) {
    67 int evsql_result_buf (const struct evsql_result_info *res, size_t row, size_t col, const char **ptr, size_t *size, int nullok) {
    68     *ptr = NULL;
    68     *ptr = NULL;
    69 
    69 
    70     switch (res->evsql->type) {
    70     switch (res->evsql->type) {
    71         case EVSQL_EVPQ:
    71         case EVSQL_EVPQ:
    72             if (PQgetisnull(res->result.pq, row, col)) {
    72             if (PQgetisnull(res->result.pq, row, col)) {
    77             }
    77             }
    78 
    78 
    79             if (PQfformat(res->result.pq, col) != 1)
    79             if (PQfformat(res->result.pq, col) != 1)
    80                 ERROR("[%zu:%zu] PQfformat is not binary: %d", row, col, PQfformat(res->result.pq, col));
    80                 ERROR("[%zu:%zu] PQfformat is not binary: %d", row, col, PQfformat(res->result.pq, col));
    81     
    81     
    82             if (size && PQgetlength(res->result.pq, row, col) != size)
    82             *size = PQgetlength(res->result.pq, row, col);
    83                 ERROR("[%zu:%zu] field size mismatch: %zu -> %d", row, col, size, PQgetlength(res->result.pq, row, col));
    83             *ptr  = PQgetvalue(res->result.pq, row, col);
    84 
       
    85             *ptr = PQgetvalue(res->result.pq, row, col);
       
    86 
    84 
    87             return 0;
    85             return 0;
    88 
    86 
    89         default:
    87         default:
    90             FATAL("res->evsql->type");
    88             FATAL("res->evsql->type");
    91     }
    89     }
       
    90 
       
    91 error:
       
    92     return -1;
       
    93 }
       
    94 
       
    95 int evsql_result_binary (const struct evsql_result_info *res, size_t row, size_t col, const char **ptr, size_t size, int nullok) {
       
    96     size_t real_size;
       
    97 
       
    98     if (evsql_result_buf(res, row, col, ptr, &real_size, nullok))
       
    99         goto error;
       
   100 
       
   101     if (size && real_size != size)
       
   102         ERROR("[%zu:%zu] field size mismatch: %zu -> %zu", row, col, size, real_size);
       
   103      
       
   104     return 0;
    92 
   105 
    93 error:
   106 error:
    94     return -1;
   107     return -1;
    95 }
   108 }
    96 
   109