Is performing a SELECT prior to the INSERT out of the question? That
way you would not have to have the INSERT fail. Another faster but
non-SQL solution would be to keep a local copy of the id/text pairs in
an stl::map with the text field being the key and the id being the
value. This solution would only work if your table was small enough, or
your memory is big enough to hold it without serious performance impact.
From: Steve Povilaitis [mailto:spovilaitis@stripped]
Sent: Friday, November 04, 2005 6:56 AM
To: 'MySQL++ Mailing List'
Subject: How can I implement the following logic?
Most exalted ones,
What is the best way to implement the following functionality using
I have a table with two fields, one is an autogenerated primary key 'id'
field of type int, the other is a text field. The text field must have
unique values for each record. (table is created using the UNIQUE
for that field).
I want to insert a new record into the table, but only if it has text
is not already in a pre-existing record in the table. So if my new
has a text field that is already in the table, then the insert will of
course fail, which is fine. BUT, how can I get the 'id' of the already
existing record that has the matching text?
I hope this makes sense.
Thanks in advance for your help,
This e-mail and any attachments are provided through AEgis
Technologies' e-mail services and may contain company sensitive and/or
privileged information. If you are not the intended recipient, please
notify the sender immediately by return e-mail, delete this e-mail and
destroy any copies. Any dissemination or use of this information by a
person other than the intended recipient is unauthorized and may be
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus