Esempio n. 1
0
VALUE typecast_detect(const char *data, size_t size, int type) {
    VALUE value;
    char *bytea;
    size_t bytea_len;
    switch (type) {
        case SWIFT_TYPE_INT:
            return rb_cstr2inum(data, 10);
        case SWIFT_TYPE_FLOAT:
            return rb_float_new(atof(data));
        case SWIFT_TYPE_NUMERIC:
            return rb_funcall(cBigDecimal, fnew, 1, rb_str_new(data, size));
        case SWIFT_TYPE_BOOLEAN:
            return (data && (data[0] =='t' || data[0] == '1')) ? Qtrue : Qfalse;
        case SWIFT_TYPE_BLOB:
            bytea = PQunescapeBytea(data, &bytea_len);
            value = rb_str_new(bytea, bytea_len);
            PQfreemem(bytea);
            return rb_funcall(cStringIO, fnew, 1, value);
        case SWIFT_TYPE_TIMESTAMP:
            return datetime_parse(cSwiftDateTime, data, size);
        case SWIFT_TYPE_DATE:
            return date_parse(cSwiftDateTime, data, size);
        default:
            return rb_enc_str_new(data, size, rb_utf8_encoding());
    }
}
Esempio n. 2
0
void
polezero_comment_datetime(char *p, pzmeta_t *meta, pzcomment_t *c) {
        char *pp;
        datetime **s;
        s = (datetime **) ((char *)meta + c->off);
        *s = NULL;
        pp = polezero_comment_token( p );
        if(!pp || !*pp) {
          datetime_free(*s);
          return;
        }
        *s = datetime_parse( pp, *s);
        if(!*s) {
          fprintf(stdout, "polezero-comment: Error parsing datetime: '%s'\n", p);
        }
}