Check the database for existency.
-
Hi! I've to check the database for existency. i.e. My table has a field called name. I've to check whether a particular string is present in the field. e.g I've to check whether "ratha" is prsent in name. I'm using SQLite. How to do this? Which Query should I use?
-
Hi! I've to check the database for existency. i.e. My table has a field called name. I've to check whether a particular string is present in the field. e.g I've to check whether "ratha" is prsent in name. I'm using SQLite. How to do this? Which Query should I use?
-
If I use LIKE key word,it doesn't fully serve my purpose. This is my query:
irr::core::stringc test = "Select name from profile WHERE name LIKE '%";
test += str.trim();
test += "%'";
result.clear();
result = pManager->SQLdb.Query(test);With this query, I can't add a new name "sri" to the name field if "srinivasan" is already present in the name field. I don't want this. If "srinivasan" is present, I could not add names like "srinivasan","SRINIVASAN" or "SrInIvAsAn". i.e I've to check the exact name without regard to case. How to do this? Another question is: I've to restrict the number of records in a table. i.e I don't want to update the table if it already has 10 records in it. How to do this?
modified on Thursday, October 28, 2010 6:29 AM
-
If I use LIKE key word,it doesn't fully serve my purpose. This is my query:
irr::core::stringc test = "Select name from profile WHERE name LIKE '%";
test += str.trim();
test += "%'";
result.clear();
result = pManager->SQLdb.Query(test);With this query, I can't add a new name "sri" to the name field if "srinivasan" is already present in the name field. I don't want this. If "srinivasan" is present, I could not add names like "srinivasan","SRINIVASAN" or "SrInIvAsAn". i.e I've to check the exact name without regard to case. How to do this? Another question is: I've to restrict the number of records in a table. i.e I don't want to update the table if it already has 10 records in it. How to do this?
modified on Thursday, October 28, 2010 6:29 AM
T.RATHA KRISHNAN wrote:
If I use LIKE key word,it doesn't fully serve my purpose.
It does however answer your first question. With the additional detail that you have added then something like the following would be want you want. (Unless there are other yet unstated requirements.) select lower(name) from profile WHERE name LIKE 'sri%"
T.RATHA KRISHNAN wrote:
I've to restrict the number of records in a table. i.e I don't want to update the table if it already has 10 records in it. How to do this?
Odd requirement. But do you know what 'count' does? You might want to get a book or use the online documentation and read through all of the functions that are available as part of the database. And if this system is part of a commercial/publicly available system you should look up sql injection attacks and ways to prevent that. Sql injection attacks are still a significant security problem.