inserting/reading Base64 strings with SQLite

I tried to insert a base64 encoded string into my SQLite database, but when I read back the value, I get a different result than what I saved. More specifically, every time my string contains a "+" character, it gets stored as '?' in my db.

I thought maybe the two non-alpha-numeric characters in base64-- namely, '+' and '/' are sensitive characters in SQLite, so I did some research and saw this page: http://www.sqlite.org/lang_expr.html

I see that + is a unary operator, and / is a binary operator... but still, if I insert the string containing these characters into my table, it shouldn't cause any problems right?

Also, this may be unrelated to the problem but I am coding with Javascript, the SQLite I'm using is a client side database for Firefox.

As for the code, I'm storing with this API provided by Firefox:

db.record({COLNAME:MY_BASE64_STRING})

and I'm reading with this:

let db_query = "SELECT * FROM " + dbstore._tableName + " WHERE col_1 = :row_id";
let statement = dbstore._createStatement(db_query);
statement.params.row_id=base64_string;

It seems that they are doing some input sanitization for XSS defense. That's why the b64 encoded strings are not stroring properly.

链接地址: http://www.djcxy.com/p/43716.html

上一篇: 如何在node.js中执行Base64编码?

下一篇: 用SQLite插入/读取Base64字符串