# # # patch "database.cc" # from [df56a934550470268419722e13f261fbe5690a18] # to [2ca32f3c29813216c04c7a51dba8233885de7d9d] # # patch "database.hh" # from [71477ad5bb2636aee1e5032992eb0405c21cc275] # to [d7116e18a312495ebe9288c6dc465777e586680f] # ============================================================ --- database.cc df56a934550470268419722e13f261fbe5690a18 +++ database.cc 2ca32f3c29813216c04c7a51dba8233885de7d9d @@ -556,7 +556,7 @@ } void -database::execute(std::string const& query, std::vector const& args) +database::execute(std::string const& query, std::vector const& args) { results res; fetch(res, 0, 0, query, args); @@ -668,6 +668,7 @@ } res.push_back(row); } +L(F("got %d lines %d cols\n") % res.size() % ncol); if (rescode != SQLITE_DONE) assert_sqlite3_ok(sql()); @@ -688,7 +689,7 @@ int const want_cols, int const want_rows, std::string const& query, - std::vector const& args) + std::vector const& args) { res.clear(); res.resize(0); @@ -714,7 +715,10 @@ // we can use SQLITE_STATIC since the array is destructed after // fetching the parameters (and sqlite3_reset) - sqlite3_bind_blob(stmt.stmt(), param, args[param-1].data(), args[param-1].size(), SQLITE_STATIC); + if (args[param-1].binary) + sqlite3_bind_blob(stmt.stmt(), param, args[param-1].data(), args[param-1].size(), SQLITE_STATIC); + else + sqlite3_bind_text(stmt.stmt(), param, args[param-1].c_str(), -1, SQLITE_STATIC); assert_sqlite3_ok(sql()); } @@ -891,9 +895,9 @@ encode_gzip(dat, dat_packed); string insert = "INSERT INTO " + table + " VALUES(?, ?)"; - std::vector args; + std::vector args; args.push_back(ident()); - args.push_back(dat_packed()); + args.push_back(queryarg(dat_packed(),true)); execute(insert,args); } void @@ -909,10 +913,10 @@ gzip del_packed; encode_gzip(del, del_packed); - std::vector args; + std::vector args; args.push_back(ident()); args.push_back(base()); - args.push_back(del_packed()); + args.push_back(queryarg(del_packed(),true)); string insert = "INSERT INTO "+table+" VALUES(?, ?, ?)"; execute(insert, args); } ============================================================ --- database.hh 71477ad5bb2636aee1e5032992eb0405c21cc275 +++ database.hh d7116e18a312495ebe9288c6dc465777e586680f @@ -96,7 +96,18 @@ typedef std::vector< std::vector > results; void execute(char const * query, ...); - void execute(std::string const& query, std::vector const& args); + + // structure to distinguish between blob and string arguments + // in sqlite3 a blob never equals a string even when binary identical + // so we need to remember which type to pass to the query + struct queryarg : public std::string + { + bool binary; + queryarg(std::string const& s=std::string(), bool b=false) + : std::string(s), binary(b) {} + }; + + void execute(std::string const& query, std::vector const& args); statement& prepare(char const * query, int const want_cols); @@ -122,7 +133,7 @@ int const want_cols, int const want_rows, std::string const& query, - std::vector const& args); + std::vector const& args); bool exists(hexenc const & ident, std::string const & table);