Permalink
Browse files

db, bugfix: do not process the escape character '?' when the paramete…

…r is insufficient.
  • Loading branch information...
xicilion committed Jun 7, 2018
1 parent 1975188 commit d20292ab9cbf4a904bc820d061c906f0d034473c
Showing with 9 additions and 2 deletions.
  1. +1 −1 fibjs/src/db/db.cpp
  2. +8 −1 test/db_test.js
View
@@ -186,7 +186,7 @@ result_t _format(const char* sql, OptArgs args, bool mysql, bool mssql,
_appendValue(str, v, mysql, mssql);
} else
str.append("\'\'", 2);
str.append(1, '?');
cnt++;
}
View
@@ -17,12 +17,14 @@ describe("db", () => {
it("format", () => {
assert.equal(db.format("test?", [1, 2, 3, 4]), "test(1,2,3,4)");
assert.equal(db.format("test?", [1, [2, 3], 4]), "test(1,(2,3),4)");
assert.equal(db.format("test?"), "test?");
});
it("formatMySQL", () => {
assert.equal(db.formatMySQL("test?, ?, ?, ?", 123, 'ds\r\na',
new Date('1998-4-14 12:12:12')),
"test123, 'ds\\r\\na', '1998-04-14 12:12:12', ''");
"test123, 'ds\\r\\na', '1998-04-14 12:12:12', ?");
assert.equal(db.formatMySQL("test?"), "test?");
});
function _test(conn_str) {
@@ -58,6 +60,11 @@ describe("db", () => {
})
});
it("empty sql", () => {
var rs = conn.execute('select "?" as v');
assert.equal(rs[0].v, '?');
});
it("escape", () => {
var rs = conn.execute("select ? as t;", '123456\r\n\'\"\x1acccds');
assert.equal(rs[0].t, '123456\r\n\'\"\x1acccds');

0 comments on commit d20292a

Please sign in to comment.