Sqlite_orm: Can't deal with binary data in where query

Created on 26 Feb 2019  路  4Comments  路  Source: fnc12/sqlite_orm

The following example causes a SQL logic error on the iterate<Test>.

#include "sqlite_orm.h"

#include <vector>
#include <string>
#include <iostream>

using namespace sqlite_orm;

struct Test {
  int64_t id;
  std::vector<char> key;
};

int main() {
  auto db = make_storage("test",
    make_table("Test",
      make_column("key", &Test::key),
      make_column("id", &Test::id, autoincrement(), primary_key()))
  );
  db.sync_schema(true);

  std::vector<char> key;
  key.resize(255);
  for (int i = 0; i < 255; i++)
    key[i] = i;

  Test v;
  v.key = key;

  db.insert(v);

  for (auto& w : db.iterate<Test>(
        where(c(&Test::key) == key))) {
    std::cout << w.id << std::endl;
  }
}
bug

Most helpful comment

@bwesterb hi. Thanks for using the lib. You found a bug. The reason of it is that iterate returns an adapter view_t which stores query is string but blob cannot be presented as a raw string in a query. So to fix this I need to change query representation in view_t. I'll try to make it in a week if you don't mind.
Thanks

All 4 comments

@bwesterb hi. Thanks for using the lib. You found a bug. The reason of it is that iterate returns an adapter view_t which stores query is string but blob cannot be presented as a raw string in a query. So to fix this I need to change query representation in view_t. I'll try to make it in a week if you don't mind.
Thanks

Fixed it in dev branch. Please check it out

@fnc12 thanks :)

Was this page helpful?
0 / 5 - 0 ratings