|
Home > Archive > MySQL PlusPlus > November 2005 > How can I implement the following logic?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How can I implement the following logic?
|
|
| Steve Povilaitis 2005-11-04, 9:23 am |
| 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?uns...sie.nctu.edu.tw
| |
| David Parker 2005-11-04, 11:43 am |
| 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 & #91;mailto:spovilait
is@aegistg.com]=20
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=20
Technologies' e-mail services and may contain company sensitive and/or=20
privileged information. If you are not the intended recipient, please=20
notify the sender immediately by return e-mail, delete this e-mail and=20
destroy any copies. Any dissemination or use of this information by a=20
person other than the intended recipient is unauthorized and may be=20
illegal.
--=20
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe:
http://lists.mysql.com/plusplus? un...
yrad.com
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?uns...sie.nctu.edu.tw
|
|
|
|
|