我正在开发一个同时支持英语 和土耳其语 的 Android 应用程序。 该应用程序包含 SQLite 数据库,其中包含一个表和 Autoincrement _id 列。
当此应用程序在英语设备上运行时,它运行良好,但在土耳其语 设备上运行时,数据库会停止自动生成 ID。
我试图提取数据库文件并在 SQLite 数据库浏览器上打开它,它正确地保存了所有列值,只有 _id 列的值在 Turkish Locale 中仍然为空
解决这个问题的想法?
编辑:
创建数据库:
public class DatabaseHandler extends SQLiteOpenHelper {
private final static String TAG = "DatabaseHandler";
private final static int DATABASE_VERSION = 3;
private final static String DATABASE_NAME = "app_main_database";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE tbl_item (_id INTEGER PRIMARY KEY NULL, _serverId TEXT NULL, _itemName TEXT NULL, _lastEditDate DATETIME NOT NULL)";
db.execSQL(query);
}
向表中插入行:
@Override
public void insert() {
ContentValues reVal = new ContentValues();
reVal.put(COL_ITEM_SERVER_ID, getItemServerId());
reVal.put(COL_ITEM_NAME, getItemName());
reVal.put(COL_LAST_EDIT_DATE, getLastEditDate());
SQLiteDatabase sqLite = new DatabaseHandler(this).getWritableDatabase();
sqLite.insert(tableName, null, obj.getContentValues());
}
最佳答案
您可以尝试打开您的数据库并将区域设置(使用 setLocale
)设置为英语。默认情况下,它将使用系统语言环境。
使用 openDatabase
你可以设置NO_LOCALIZED_COLLATORS
也标记(禁用每个 setLocale 并可以解决您的问题(但从未测试过它,现在只是一些研究))
public static final int NO_LOCALIZED_COLLATORS
Added in API level 1
Open flag: Flag for openDatabase(String, SQLiteDatabase.CursorFactory, int) to open the database without support for localized collators.
This causes the collator LOCALIZED not to be created. You must be consistent when using this flag to use the setting the database was created with. If this is set, setLocale(Locale) will do nothing.
Constant Value: 16 (0x00000010)
作为第一次尝试,我会在 datatabase
对象上测试 setLocale
。
关于Android SQLite 土耳其语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22359773/