24 messages in com.mysql.lists.plusplusRE: Inserting with a column that uses...| From | Sent On | Attachments |
|---|---|---|
| Graham Reitz | 08 Aug 2007 20:17 | |
| Graham Reitz | 08 Aug 2007 20:49 | |
| Graham Reitz | 08 Aug 2007 21:03 | |
| Graham Reitz | 08 Aug 2007 21:14 | |
| Warren Young | 09 Aug 2007 05:04 | |
| Graham Reitz | 10 Aug 2007 16:58 | |
| Graham Reitz | 10 Aug 2007 17:41 | |
| Graham Reitz | 10 Aug 2007 22:45 | |
| Graham Reitz | 10 Aug 2007 23:26 | |
| Jim Wallace | 11 Aug 2007 18:28 | |
| Graham Reitz | 11 Aug 2007 20:50 | |
| Graham Reitz | 11 Aug 2007 21:10 | |
| Jim Wallace | 12 Aug 2007 11:42 | |
| Graham Reitz | 12 Aug 2007 13:07 | |
| Warren Young | 13 Aug 2007 15:51 | |
| Graham Reitz | 13 Aug 2007 20:49 | |
| Joel Fielder | 14 Aug 2007 00:41 | |
| Graham Reitz | 14 Aug 2007 13:18 | |
| Warren Young | 14 Aug 2007 15:11 | |
| Graham Reitz | 14 Aug 2007 18:37 | |
| Graham Reitz | 14 Aug 2007 20:41 | |
| Warren Young | 16 Aug 2007 05:00 | |
| Graham Reitz | 16 Aug 2007 16:00 | |
| Warren Young | 28 Dec 2007 02:36 |
| Subject: | RE: Inserting with a column that uses auto_increment![]() |
|---|---|
| From: | Jim Wallace (jwal...@kaneva.com) |
| Date: | 08/11/2007 06:28:50 PM |
| List: | com.mysql.lists.plusplus |
I use auto_increment often. The trick is to not include that column in the sql_create_* macro. This may mean you have > 1 macro for the same table, one for insert w/o that column, and one for retrieval with that column. I often have > 1 macro for the same table depending on how I'm using it.
HTH
-----Original Message----- From: Graham Reitz [mailto:grah...@mac.com] Sent: Saturday, August 11, 2007 2:27 AM To: plus...@lists.mysql.com Subject: Inserting with a column that uses auto_increment
How do you prevent an insert as shown in the code below from putting "bogus" data in an auto_increment field?
It seems like the billing_id field, in the code below, inserts a number based on the un-initialized value of client_id, instead of letting the database auto_increment the value. What's a good method to deal with this, that allows the database to auto_increment a database field?
Thanks, Graham
/************ CODE ************/
#include <mysql++.h> #include <custom.h>
using namespace mysqlpp;
sql_create_2(clients, 1, 2, unsigned int, client_id, // auto_incremented field unsigned int, billing_id)
void populate_client_info(clients& client_info) { client_info.billing_id = 1; }
int main (int argc, char* const argv[]) { Connection connection("db_name","ip_address","user", "password",3306, false);
Query client_query = connection.query();
clients a_client; populate_client_info(a_client);
client_query.insert(a_client); client_query.execute();
return 0; }




