I am using the following C++ (Visual Studio .Net 2002) code to determine
whether or not a given object exists in a table.If it DOES exist, it adds
it.
 
<snip>
query.Format("SELECT catID FROM Categories WHERE category=\"%s\" AND
subcategory=\"%s\"",
   currentObject->category, currentObject->subcategory);
if (!sqlCon.ExecuteQuery(query))
{
 sqlCon.QueryError(query);
 delete currentObject;
 currentObject = NULL;
 return;
}
 
if (sqlCon.res.size() == 0) //then doesn't exist, need to add it
{
 query.Format("INSERT INTO Categories (category, subcategory) VALUES(\"%s\",
\"%s\")",
   currentObject->category, currentObject->subcategory);
 if (!sqlCon.ExecuteQuery(query))
 {
  sqlCon.QueryError(query);
  delete currentObject;
  currentObject = NULL;
  return;
 }
 
 ....
</snip>
 
What I just began getting is the case where the selected results have a size
of 0 (indicating that the specified object does not exist), but then when I
try to insert that very same item, it gives me a key violation.  I just
upgraded this program to be using a 4.0.17 server - was previously using
4.0.12 and did not have this problem.  Any ideas on what might be wrong?
 
Adam Clauss
[EMAIL PROTECTED]
 

Reply via email to