0

I have a sqlite database in which So many profile names (String) are stored and i want to determine, whenever user enters a new profile name then app must have to check in the database that the same profile name is already exist or not in the case sensitivity manner . As if there exists "Normal" then again "normal" should not be entered.

for this if there is any query or anything else ,please suggest. Thanks for your consideration.

 public boolean isCaseSensitive(String rawprofile)
{
    openReadable();
    String profile=null;
    Cursor mCursor=m_sqLiteDatabase.rawQuery("SELECT Profile_Name FROM Profiles WHERE profile="+rawprofile+"",null);
    if(mCursor !=null &&  mCursor.getCount()>0){
        mCursor.moveToFirst();
        profile=mCursor.getString(0);
        if(profile.equals(rawprofile)){
            return  true;
        }
    }
    return false;
}
sam
  • 113
  • 1
  • 9
  • Any structure? Code you have tried? – Sunny R Gupta Jun 30 '16 at 11:38
  • http://stackoverflow.com/a/973785/982149 – Fildor Jun 30 '16 at 11:40
  • There are actually 2 approaches. 1. Insert everything in lower case and have a unique constraint on "name" column. 2. Create a unique lower-case index for the "name" column. – TheLostMind Jun 30 '16 at 11:40
  • @SunnyRGupta i have just posted it now – sam Jun 30 '16 at 11:47
  • yeah this question is asked earlier but i am not getting exactly how it works.....now i am using the following code but getting an exception – sam Jul 01 '16 at 05:24
  • android.database.sqlite.SQLiteException: no such column: g (code 1): , while compiling: SELECT Profile_Name FROM Profiles WHERE Profile_Name COLLATE BINARY =profileName – sam Jul 01 '16 at 05:25
  • this code i am using............... public boolean isCaseSensitive(String rawprofile) { openReadable(); Cursor mCursor=m_sqLiteDatabase.rawQuery("SELECT Profile_Name FROM Profiles WHERE Profile_Name COLLATE NOCASE ="+rawprofile+"",null); if(mCursor !=null && mCursor.getCount()>0){ return true; } return false; } – sam Jul 01 '16 at 05:25

0 Answers0