Permalink
Browse files

begin type coercion for libpq

  • Loading branch information...
1 parent 47591d6 commit b76ced71444a695c945f3cc9e3a452b3b2352cf0 bmc committed Mar 1, 2011
Showing with 35 additions and 6 deletions.
  1. +18 −1 lib/native.js
  2. +9 −2 src/binding.cc
  3. +2 −2 test/cli.js
  4. +5 −0 test/integration/client/api-tests.js
  5. +1 −1 wscript
View
@@ -136,7 +136,24 @@ var NativeQuery = function(text, values, callback) {
sys.inherits(NativeQuery, EventEmitter);
var p = NativeQuery.prototype;
-p.handleRow = function(row) {
+//maps from native rowdata into api compatible row object
+var mapRowData = function(row) {
+ var result = {};
+ for(var i = 0, len = row.length; i < len; i++) {
+ var item = row[i];
+ switch(item.type) {
+ case 23:
+ result[item.name] = parseInt(item.value);
+ break;
+ default:
+ result[item.name] = item.value;
+ }
+ }
+ return result;
+}
+
+p.handleRow = function(rowData) {
+ var row = mapRowData(rowData);
if(this.callback) {
this.rows.push(row);
}
View
@@ -330,11 +330,18 @@ class Connection : public EventEmitter {
int rowCount = PQntuples(result);
for(int rowNumber = 0; rowNumber < rowCount; rowNumber++) {
//create result object for this row
- Local<Object> row = Object::New();
+ Local<Array> row = Array::New();
int fieldCount = PQnfields(result);
for(int fieldNumber = 0; fieldNumber < fieldCount; fieldNumber++) {
+ Local<Object> field = Object::New();
char* fieldName = PQfname(result, fieldNumber);
- row->Set(String::New(fieldName), WrapFieldValue(result, rowNumber, fieldNumber));
+ int fieldType = PQftype(result, fieldNumber);
+ char* fieldValue = PQgetvalue(result, rowNumber, fieldNumber);
+ //TODO use symbols here
+ field->Set(String::New("name"), String::New(fieldName));
+ field->Set(String::New("value"), String::New(fieldValue));
+ field->Set(String::New("type"), Integer::New(fieldType));
+ row->Set(Integer::New(fieldNumber), field);
}
//not sure about what to dealloc or scope#Close here
View
@@ -38,8 +38,8 @@ for(var i = 0; i < args.length; i++) {
case '-t':
case '--test':
config.test = args[++i];
- case '--libpq':
- config.libpq = (args[++i] == "true");
+ case '--native':
+ config.native = (args[++i] == "true");
default:
break;
}
@@ -1,5 +1,10 @@
var helper = require(__dirname + '/../test-helper');
var pg = require(__dirname + '/../../../lib');
+
+if(helper.args.native) {
+ pg = require(__dirname + '/../../../lib/native')
+}
+
if(helper.args.libpq) {
pg = require(__dirname + "/../../../lib/binding");
}
View
@@ -1,6 +1,6 @@
import Options, Utils
from os import unlink, symlink, popen
-from os.path import exists
+from os.path import exists
srcdir = '.'
blddir = 'build'

0 comments on commit b76ced7

Please sign in to comment.