Hi,
In my project I use the sql_create_compete_XXX macro for creating C++ database table
abstractions. For example table host:
sql_create_complete_3(host, 1, 3,
mysqlpp::sql_int_unsigned, _host_id, "host_id",
mysqlpp::sql_smallint_unsigned, _session_id, "session_id",
mysqlpp::sql_smallint_unsigned, _sort_order, "sort_order");
In a .cpp file I have:
const char* host::table_ = "host";
const char* host::names[] = {
"host_id",
"session_id",
"sort_order"
};
Now host_id is the primary key with auto increment. When I insert a new host in the
table, I want to primary key to be auto-inserted. I now I can do this by defining another
sql_create_complete_2 without the host_id, but I rather create this insert-query from the
same class. The reason is that I want to derive from the host class like this:
class sub_host : public host
{
sub_host(unsigned session_id, unsigned sort_order) :
host(session_id, sort_order)
{ }
void db_insert()
{
// ... Get mysqlpp::query ...
query.insert(*this);
query.execute();
_host_id = query.insert_id();
}
};
But the insert(*this) query adds the host_id to the SQL-query for obvious reasons. Is
there another way to quickly generate an insert SQL-query without its primary
auto-increment column?
Thank you,
Andrej