#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()
dba::SQL counter_create =
"CREATE TABLE debea_object_count ("
" id INT"
")";
dba::SQL 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();
int id, intval;
std::cout << "Foo data:" << std::endl;
std::auto_ptr<dba::DbResult> res(pAr.getIStream().sendQuery(
dba::SQL("SELECT id, intval FROM foo_table").into(id).into(intval)
));
while(res->fetchRow()) {
std::cout << "id: "<< id << " intval: "
<< intval << 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(foo_create);
ar.getOStream().sendUpdate(dba::SQL("INSERT INTO debea_object_count VALUES (:d)") << 1);
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;
};
};