I get accounthead title names from user and insert them in table after verifying its existance already. If already existed I just inform the user that it already exists and try some other title. But, For example, if the table already has a name like 'building'
and if the user again enters as 'Building' (first letter upper case'B") it is accepting. This has to be avoided.
public long insertData(String name) {
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues contentvalues = new ContentValues();
contentvalues.put(VivzHelper.NAME, name);
long id = db.insert(VivzHelper.TABLE_NAME, null, contentvalues);
return id;
}
In the following code I search for existance:
public String getData(String sub1) {
SQLiteDatabase db = helper.getWritableDatabase();
String[] columns = new String[]{VivzHelper.NAME};
String[] selectionArgs = {sub1};
Cursor cursor = db.query(VivzHelper.TABLE_NAME, columns, VivzHelper.NAME+" =?",
selectionArgs, null,null,null);
StringBuffer buffer = new StringBuffer();
while(cursor.moveToNext())
{
int accountNameIDX=cursor.getColumnIndex(VivzHelper.NAME);
String accountName=cursor.getString(accountNameIDX);
buffer.append(accountName +"\n");
}
cursor.close();
if (buffer.toString().equals(""))
{
existsYesorNo="N";
}
else
{
existsYesorNo="Y";
}
return buffer.toString();
}