Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix for char fields in UTF encoding, fix to stream

  • Loading branch information...
commit 30d2d8f9640890191ff5e0a01768e9e7809e698c 1 parent fbb7311
@xdenser authored
View
8 config.js
@@ -0,0 +1,8 @@
+exports.cfg = {
+ // Database connection settings
+ db: "localhost:test.fdb",
+ user: "sysdba",
+ password: "masterkey",
+ role: ""
+ };
+
View
4 firebird.js
@@ -127,6 +127,8 @@ exports.createConnectionPool = function(settings){
// Allows further extention
exports.binding = binding;
+function Stream(blob){
+
var buf = null;
function allocBuf(){
buf = new Buffer(SchunkSize);
@@ -154,7 +156,7 @@ function ReadStream(strm) {
});
};
-function Stream(blob){
+
if(!(blob instanceof binding.FBblob )) {
throw new Error('Expecting blob');
//blob = new binding.FBblob();
View
36 src/fb-bindings-fbresult.cc
@@ -89,6 +89,7 @@ Handle<Value>
break;
case SQL_TEXT: var->sqldata = new char[var->sqllen + 1];
memset(var->sqldata, ' ', var->sqllen);
+ //memset(var->sqldata, 0, var->sqllen);
var->sqldata[var->sqllen] = '\0';
break;
case SQL_VARYING: var->sqldata = new char[var->sqllen + 3];
@@ -325,6 +326,21 @@ Handle<Value> FBResult::set_params(XSQLDA *sqlda, const Arguments& args)
}
return Undefined();
}
+
+short getCharsetSize(XSQLVAR *var){
+ switch(var->sqlsubtype & 0xFF){
+ case 0: case 1: case 2: case 10: case 11: case 12: case 13: case 14:
+ case 19: case 21: case 22: case 39: case 45: case 46: case 47:
+ case 50: case 51: case 52: case 53: case 54: case 55: case 58: return 1;
+
+ case 5: case 6: case 8: case 44: case 56: case 57: case 64: return 2;
+
+ case 3: return 3;
+
+ case 4: case 59: return 4;
+ }
+ return 0;
+}
Local<Value>
FBResult::GetFieldValue(XSQLVAR *var, Connection* conn)
@@ -336,7 +352,8 @@ Local<Value>
ISC_QUAD bid;
time_t rawtime;
double time_val;
- int days;
+ int days;
+ short bpc, chars; // bytes per char
HandleScope scope;
@@ -344,7 +361,7 @@ Local<Value>
Local<Function> con;
Local<Value> argv[7];
- Local<Object> js_date;
+ Local<Object> js_date, js_obj;
Local<Value> js_field = Local<Value>::New(Null());
dtype = var->sqltype & ~1;
if ((var->sqltype & 1) && (*var->sqlind < 0))
@@ -356,8 +373,19 @@ Local<Value>
switch (dtype)
{
case SQL_TEXT:
- //js_field = String::New(var->sqldata,var->sqllen);
- js_field = String::New(var->sqldata);
+ bpc = getCharsetSize(var);
+ chars = var->sqllen/(bpc != 0 ? bpc : 1);
+ js_field = String::New(var->sqldata,var->sqllen );
+ if(Local<String>::Cast(js_field)->Length() > chars )
+ {
+ js_obj = js_field->ToObject();
+ argv[0] = Integer::New(0);
+ argv[1] = Integer::New(chars);
+ js_field = Local<Function>::Cast(js_obj->Get(String::New("slice")))->Call(js_obj,2,argv);
+ }
+
+ // printf(" char lengh %d/%d, %d, 1 %hx, 2 %hx, 3 %hx, 4 %hx \n",var->sqllen,Local<String>::Cast(js_field)->Length(), var->sqlsubtype, var->sqldata[0],var->sqldata[1],var->sqldata[2],var->sqldata[3]);
+ // js_field = String::New(var->sqldata);
break;
case SQL_VARYING:
View
5 tests/def/test-datatypes.js
@@ -63,8 +63,9 @@ module.exports = testCase({
test.done();
},
charMAX:function(test){
+ // return;
test.expect(1);
- var len = 32737;
+ var len = Math.ceil(32737/4);
var Data = '';
var chars = 'abcdefghABSD01234689q';
for(var i=0; i<len;i++) Data+=chars.charAt(Math.floor(Math.random()*chars.length));
@@ -226,7 +227,7 @@ module.exports = testCase({
},
VarcharMAX:function(test){
test.expect(1);
- var len = 32737;
+ var len = Math.ceil(32737/4);
var Data = '';
var chars = 'abcdefghABSD01234689q';
for(var i=0; i<len;i++) Data+=chars.charAt(Math.floor(Math.random()*chars.length));
View
9 tests/perf/select-full-async.js
@@ -15,12 +15,15 @@ http.createServer(function (req, res) {
var con = fb.createConnection();
con.connect(cfg.db, cfg.user, cfg.password, cfg.role,function(){
con.query('select * from rdb$relations',function(err,rs){
- var rows = [];
+ //var rows = [];
+ res.write('[');
rs.fetch("all",true,function(r){
- rows.push(r);
+ //rows.push(r);
+ res.write(JSON.stringify(r)+',');
}, function(err){
con.disconnect();
- res.end(util.inspect(rows));
+ //res.end(util.inspect(rows));
+ res.end(']');
});
});
View
2  tests/perf/select-full-sync.js
@@ -17,6 +17,6 @@ http.createServer(function (req, res) {
var rs = con.querySync('select * from rdb$relations');
var rows = rs.fetchSync("all",true);
con.disconnect();
- res.end(util.inspect(rows));
+ res.end(JSON.stringify(rows));
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
View
8 tests/perf/select-prep-async-pool.js
@@ -74,11 +74,13 @@ http.createServer(function (req, res) {
var exec = function(){
con.stmt.exec();
con.stmt.once('result',function(err){
- var rows = [];
+ // var rows = [];
+ res.write('[');
con.stmt.fetch("all",true,function(r){
- rows.push(r);
+ //rows.push(r);
+ res.write(JSON.stringify(r)+',');
}, function(err){
- res.end(util.inspect(rows));
+ res.end(']');
con.conn.commit(function(){
pool.release(con);
});
View
8 tests/perf/select-prep-async-trans.js
@@ -21,11 +21,13 @@ http.createServer(function (req, res) {
var exec = function(){
stmt.exec();
stmt.once('result',function(err){
- var rows = [];
+ //var rows = [];
+ res.write('[');
stmt.fetch("all",true,function(r){
- rows.push(r);
+ // rows.push(r);
+ res.write(JSON.stringify(r)+',');
}, function(err){
- res.end(util.inspect(rows));
+ res.end(']');
con.commit(function(err){
//if(err) return;
stmt.lock = false;
Please sign in to comment.
Something went wrong with that request. Please try again.