if it only has 2 states, first change it to be bool type and use true and false instead of 1 and 0 unless you have a requirement to do otherwise.
you can use it in a condition, and usually would:
if(sql_checkexists(stuff....) )
do something with thing that existed
else
cout complaint about not existing
also prefer to avoid wordy code.
just say
return (ColName[i], ColData[i] ? ColData[i] : "NULL") == "1";
ColName[i] is evaluated but its value is never used as the rightmost value of a , operator is used. If ColData[i] is null, then the return value is "NULL" (char*). Also ColData[i] is of type char*. So a type char* is then compared to "1" using == ......... In the OP original, the intermediate value was converted to type std::string before the comparison so that the == was appropriate.
Ok Thanks. This worked but I am confused on how it works?!!!
1 2 3 4
int rc = sqlite3_exec(sqldb, sql.c_str(), sql_checkexists, (void*)data.c_str(), NULL);
if (sqlite3_exec(sqldb, sql.c_str(), sql_checkexists, (void*)data.c_str(), NULL)) {
cout << "Error! Record Already Exists!";
}
If you have an explanation, I want to know.
I was thinking to store the value of sql_checkexists in a variable and use it for IF statement, but how it get stored into "rc" because that's for sqlite3_exec, isn't it?