Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Check the database for existency.

Check the database for existency.

Scheduled Pinned Locked Moved Database
databasesqlitetutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T RATHA KRISHNAN
    wrote on last edited by
    #1

    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?

    A 1 Reply Last reply
    0
    • T T RATHA KRISHNAN

      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?

      A Offline
      A Offline
      Andy_L_J
      wrote on last edited by
      #2

      Look at the LIKE keyword... here...[^]

      I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

      T 1 Reply Last reply
      0
      • A Andy_L_J

        Look at the LIKE keyword... here...[^]

        I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife

        T Offline
        T Offline
        T RATHA KRISHNAN
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • T T RATHA KRISHNAN

          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

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups