如何避免区分大小写 [英] how to avoid case sensitiveness
问题描述
我从用户那里获得了帐号头名称,并在验证其存在后将其插入表格中。如果已经存在,我只是通知用户它已经存在并尝试其他一些标题。但是,例如,如果表格已经有一个名称,如'building'
,如果用户再次输入'Building'(首字母大写'B'),则表示接受。可以避免。
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);
返回id;
}
以下代码我搜索存在:
public String getData(String sub1){
SQLiteDatabase db = helper.getWritableDatabase();
String [] columns = new String [] {VivzHelper.NAME};
String [] selectionArgs = {sub1};
Cursor cursor = db。查询(VivzHelper.TABLE_NAME,列s,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;
}
其他
{
existsYesorNo =Y;
}
返回buffer.toString();
}
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();
}
推荐答案
使用COLLATE
例如SELECT * FROM table COLLATE NOCASE
这篇关于如何避免区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!