If I set host_id to zero, it will simply insert a 0 for host_id. It's just another value,
nothing special about 0.
--- On Thu, 18/3/10, Chris Morgan <christopher.j.morgan@stripped> wrote:
From: Chris Morgan <christopher.j.morgan@stripped>
Subject: Re: insert query without primary key
To: "Andrej van der Zee" <mavdzee@stripped>, "plusplus@stripped"
<plusplus@stripped>
Date: Thursday, 18 March, 2010, 3:03
I think it will work if you set the _host_id to zero before the insert.
Chris
-- Sent from my Palm Pre
On Mar 17, 2010 18:52, Andrej van der Zee <mavdzee@stripped> wrote:
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
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsub=1