Merge pull request #172 from linearray/fixbytea
#161: Fixed bytea decode and added 'hex' for pg >= 9.0.
This commit is contained in:
commit
66b569c3fc
@ -119,9 +119,32 @@ var parseInterval = function(val) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var parseByteA = function(val) {
|
var parseByteA = function(val) {
|
||||||
return new Buffer(val.replace(/\\([0-7]{3})/g, function (full_match, code) {
|
if(/^\\x/.test(val)){
|
||||||
return String.fromCharCode(parseInt(code, 8));
|
// new 'hex' style response (pg >9.0)
|
||||||
}).replace(/\\\\/g, "\\"), "binary");
|
return new Buffer(val.substr(2), 'hex');
|
||||||
|
}else{
|
||||||
|
out = ""
|
||||||
|
i = 0
|
||||||
|
while(i < val.length){
|
||||||
|
if(val[i] != "\\"){
|
||||||
|
out += val[i]
|
||||||
|
++i
|
||||||
|
}else{
|
||||||
|
if(val.substr(i+1,3).match(/[0-7]{3}/)){
|
||||||
|
out += String.fromCharCode(parseInt(val.substr(i+1,3),8))
|
||||||
|
i += 4
|
||||||
|
}else{
|
||||||
|
backslashes = 1
|
||||||
|
while(i+backslashes < val.length && val[i+backslashes] == "\\")
|
||||||
|
backslashes++
|
||||||
|
for(k=0; k<Math.floor(backslashes/2); ++k)
|
||||||
|
out += "\\"
|
||||||
|
i += Math.floor(backslashes / 2) * 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Buffer(out,"binary");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxLen = Number.MAX_VALUE.toString().length
|
var maxLen = Number.MAX_VALUE.toString().length
|
||||||
|
Loading…
Reference in New Issue
Block a user