我想在我的数据库中使用UTF-8标准用于多语言字符串,例如我想用俄语插入一些字符串并检索它们以供以后使用。此刻我得到了???在我的数据库中标志而不是俄语字符。有没有办法将我的数据库设置为使用多个语言字符?
我发现了一些关于PRAGMA
的帖子,但我无法让它发挥作用,例如:
await Database.ExecuteAsync("PRAGMA encoding='UTF-8'");
我使用 SQLite.Net-PCL , System.Data.SQLite 和 SQLite for Universal Windows Platform 作为参考。
我的实际数据库创建代码:
public static string SQL_DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "my_db");
public static void createDbMethod() {
using (var conn = new SQLiteConnection(new SQLitePlatformWinRT(), SQL_DB_PATH)) {
try {
// Start transaction
conn.BeginTransaction();
try {
// Execute table creation commands...
conn.CreateTable<MyTableOne>();
conn.CreateTable<MyTableTwo>();
conn.CreateTable<MyTableThree>();
//Commit transaction
conn.Commit();
} catch (Exception ex) {
//handle exception
// Rollback transaction
conn.Rollback();
}
} catch (Exception e) {
//handle exception
} finally {
conn.Close();
}
}
}
修改 我的插入查询是:
public static void executeSqlQuery(string singSqlQuery) {
using (var conn = new SQLiteConnection(new SQLitePlatformWinRT(), SQL_DB_PATH)) {
// Open connection
try {
// Start transaction
conn.BeginTransaction();
try {
// Execute commands...
conn.Execute(singSqlQuery);
// Commit transaction
conn.Commit();
} catch (Exception ex) {
// Rollback transaction
conn.Rollback();
}
} catch (Exception e) {
//handle exception
} finally {
conn.Close();
}
}
}
其中singSqlQuery
是一个常见的SQL查询,如:
INSERT OR REPLACE INTO my_tab (id,name) VALUES('1','some characters');
答案 0 :(得分:2)
SQLite完全支持默认存储Unicode数据。你不需要做任何特别的事情,它只是工作。如果您没有找到您要放入的内容,则问题在于您的插入或检索。最不可能的转变发生在你不想要的地方。如果您还没有这样做,可能需要对插入使用参数化查询。