Local<Value> BuildCell (PGresult *result, int row, int col) { HandleScope scope; if (PQgetisnull(result, row, col)) return scope.Close(Null()); char *string = PQgetvalue(result, row, col); int32_t n = 0, i = 0; Oid t = PQftype(result, col); Handle<Value> cell; switch (t) { case BOOLOID: cell = *string == 't' ? True() : False(); break; case INT8OID: case INT4OID: case INT2OID: for (i = string[0] == '-' ? 1 : 0; string[i]; i++) { n *= 10; n += string[i] - '0'; } if (string[0] == '-') n = -n; cell = Integer::New(n); break; default: #ifndef NDEBUG // printf("Unhandled OID: %d\n", t); #endif cell = String::New(string); } return scope.Close(cell); } |