logo       


Re: Inserting with a column that uses auto_increment: msg#00060

Subject: Re: Inserting with a column that uses auto_increment
Thanks Jim,

So if I have a table with 3 columns and the first column is the auto_increment column.

I can do this and it will work?

// Used for inserts
sql_create_2(insert, 1,2, int, some_id_2, int, some_id_3)

// Used for retrievals
sql_create_3(query, 1,2, int, auto_id_1, int, some_id_2, int, some_id_3)

Thanks again,
Graham

On Aug 11, 2007, at 8:29 PM, Jim Wallace wrote:

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:grahamreitz@xxxxxxx]
Sent: Saturday, August 11, 2007 2:27 AM
To: plusplus@xxxxxxxxxxxxxxx
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;
}


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus? unsub=grahamreitz@xxxxxxx



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:    
http://lists.mysql.com/plusplus?unsub=gcdmc-plusplus@xxxxxxxxxxx




Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe