Permalink
Browse files

Issue 11: allow inserting blobs directly.

(http://code.google.com/a/apache-extras.org/p/cassandra-node/issues/detail?id=28)
Patch by Christoph Tavan <christoph.tavan@gmail.com>

* buffers get converted to hex strings on the fly.
  • Loading branch information...
gdusbabek committed Jan 30, 2012
1 parent f92c58b commit 8e2e7d4f5823933d5948e573149d4daab954b73d
Showing with 9 additions and 26 deletions.
  1. +0 −18 lib/decoder.js
  2. +5 −3 lib/driver.js
  3. +1 −1 test/test_decoder.js
  4. +3 −4 test/test_driver.js
View
@@ -65,24 +65,6 @@ var bytesToBigLong = module.exports.bytesToBigLong = function(bytes) {
return bytesToBigInt(bytes);
};
// just what you think.
function byteToHex(n) {
if (n < 16) {
return '0' + n.toString(16);
} else {
return n.toString(16);
}
}
/** convert a buffer to a hex string suitable for use in cql statements. */
var bufferToString = module.exports.bufferToString = function(buf) {
var chars = [];
for (var i = 0; i < buf.length; i++) {
chars[i] = byteToHex(buf[i]);
}
return chars.join('');
};
// Cassandra datatypes according to
// http://www.datastax.com/docs/1.0/ddl/column_family
// Those commented out are not correctly dealt with yet and will appear as
View
@@ -23,7 +23,6 @@ var logTiming = require('logmagic').local('node-cassandra-client.driver.timing')
var util = require('util');
var constants = require('constants');
var Buffer = require('buffer').Buffer;
var EventEmitter = require('events').EventEmitter;
var thrift = require('thrift');
@@ -59,11 +58,14 @@ var DEFAULT_STEP_TIMEOUTS = {
/** converts object to a string using toString() method if it exists. */
function stringify(x) {
// node buffers should be hex encoded
if (x instanceof Buffer) {
return x.toString('hex');
}
if (x.toString) {
return x.toString();
} else {
return x;
}
return x;
}
/** wraps in quotes */
View
@@ -252,6 +252,6 @@ exports.testHexing = function(test, assert) {
buf[3] = 0x99;
buf[4] = 0xcc;
buf[5] = 0xff;
assert.strictEqual('00336699ccff', bufferToString(buf));
assert.strictEqual('00336699ccff', buf.toString('hex'));
test.finish();
};
View
@@ -438,14 +438,13 @@ exports.testBinary = function(test, assert) {
assert.ifError(err);
var key = 'binarytest';
var binaryParams = [util.randomBuffer(), util.randomBuffer(), util.randomBuffer()];
var stringParams = binaryParams.map(decoder.bufferToString);
con.execute('update CfBytes set ?=? where key=?', stringParams, function(updErr) {
con.execute('update CfBytes set ?=? where key=?', binaryParams, function(updErr) {
if (updErr) {
con.close();
assert.ok(false);
test.finish();
} else {
con.execute('select ? from CfBytes where key=?', [stringParams[0], stringParams[2]], function(selErr, rows) {
con.execute('select ? from CfBytes where key=?', [binaryParams[0], binaryParams[2]], function(selErr, rows) {
con.close();
assert.strictEqual(rows.rowCount(), 1);
var row = rows[0];
@@ -457,7 +456,7 @@ exports.testBinary = function(test, assert) {
});
}
});
});
});
};
exports.testLong = function(test, assert) {

0 comments on commit 8e2e7d4

Please sign in to comment.