mercredi 29 mars 2017

Bind data for BLOB in POCO framework using SQLite wrapper

I am trying to bind a binary data to save the data in a BLOB column of SQLite using POCO framework, however, I can not figure out, how to achieve the desired results.

My code:

#include <Poco/Data/Session.h>
#include <Poco/Data/SessionPool.h>
#include <Poco/Data/SQLite/Connector.h>

. . .

const std::string dbSchemeDemo =
    "CREATE TABLE IF NOT EXISTS `demo` ("
    "\n\t`key`\tTEXT NOT NULL,"
    "\n\t`value`\tINTEGER DEFAULT NULL,"
    "\n\t`data`\tBLOB DEFAULT NULL,"
    "\n\tPRIMARY KEY(`key`)"
    "\n);"
    "\nCREATE INDEX IF NOT EXISTS idx_key ON demo(key);";

std::string sqlQueryDemo =
    "INSERT INTO demo"
    " (key, value, data)"
    " VALUES(?, ?, ?)";


auto dbPoolDemo = std::make_unique<Poco::Data::SessionPool>(Poco::Data::SQLite::Connector::KEY, "demo.db3");

Poco::Data::SQLite::Connector::registerConnector();

Poco::Data::Session dbDemo(dbPoolDemo->get());
dbDemo.setConnectionTimeout(2);
dbDemo << "PRAGMA foreign_keys = ON;", Poco::Data::Keywords::now;
dbDemo << dbSchemeDemo, Poco::Data::Keywords::now;

std::vector<unsigned char> data{ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };

Poco::Data::Statement insertDemo(dbDemo);
insertDemo << sqlQueryDemo,
    Poco::Data::Keywords::bind("ABCD"),
    Poco::Data::Keywords::bind(Poco::Nullable<int>(1)),
    Poco::Data::Keywords::bind(Poco::Nullable<std::vector<unsigned char>>(data)),
    Poco::Data::Keywords::now;

The exception "Not implemented" is thown. Any idea, how to bind a binary data from vector? Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire