#include "dba/dba.h"
#include <iostream>
class Foo : public dba::Storeable {
DECLARE_STORE_TABLE();
public:
int mIntVal;
};
BEGIN_STORE_TABLE(Foo, dba::Storeable, "foo_table")
BIND_INT(Foo::mIntVal,dba::Int,"intval")
END_STORE_TABLE()
const char* counter_create =
"CREATE TABLE debea_object_count ("
" id INT"
")";
const char* counter_init =
"INSERT INTO debea_object_count VALUES (1)";
const char* foo_create =
"CREATE TABLE foo_table ("
" id INT PRIMARY KEY,"
" intval INT"
")";
void
cloneFoo(dba::SQLArchive& pAr) {
dba::SQLOStream ostream = pAr.getOStream();
ostream.open();
Foo one;
one.mIntVal = 1;
ostream.put(&one);
std::cout << "Foo was stored with id = " << one.getId() << std::endl;
{
dba::IdLocker l;
Foo one_clone(one);
ostream.put(&one_clone);
std::cout << "Foo was cloned with id = "
<< one_clone.getId() << std::endl;
};
ostream.destroy();
std::cout << "Foo data:" << std::endl;
std::auto_ptr<dba::DbResult> res(pAr.getIStream().sendQuery(
"SELECT id, intval FROM foo_table"
));
while(res->fetchRow()) {
std::cout << "id: "<< res->getInt(0) << " intval: "
<< res->getInt(1) << std::endl;
};
std::cout << "=======================" << std::endl;
};
int
main (int argc, char** argv) {
try {
dba::SQLArchive ar;
ar.setIdFetcher(new dba::GenericFetcher());
unlink("foobasefile.sqt3");
ar.open("dbasqlite3-static", "dbname=foobasefile.sqt3");
ar.getOStream().sendUpdate(counter_create);
ar.getOStream().sendUpdate(counter_init);
ar.getOStream().sendUpdate(foo_create);
cloneFoo(ar);
return 0;
} catch (const dba::SQLException& pEx) {
std::cout << "SQL Error: " << pEx.what() << std::endl;
std::cout << "While executing: " << std::endl
<< pEx.getQuery() << std::endl;
} catch (const dba::Exception& pEx) {
std::cout << "Error: " << pEx.what() << std::endl;
return -1;
};
};