List:MySQL++« Previous MessageNext Message »
From:David Parker Date:November 4 2005 4:37pm
Subject:RE: How can I implement the following logic?
View as plain text  
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.

Dave Parker
IT SystemWorks

-----Original Message-----
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
mysql++?


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
constraint
for that field).

I want to insert a new record into the table, but only if it has text
that
is not already in a pre-existing record in the table. So if my new
record
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,

Steve


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 
illegal.

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


Thread
How can I implement the following logic?Steve Povilaitis4 Nov
RE: How can I implement the following logic?David Parker4 Nov
  • RE: How can I implement the following logic?Steve Povilaitis7 Nov