【发布时间】:2016-04-12 23:16:51
【问题描述】:
我想在我的数据库中使用多语言字符串的 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');
【问题讨论】:
-
你的数据库字符集和排序规则是什么?
-
我是windows的初学者,我知道在Android中它会自动运行,我在哪里可以设置你的
character set和collation -
我不熟悉 SQLite,所以你可能想看看这里:stackoverflow.com/questions/1188749/… - 请注意,如果这是 原因,则意味着您的原始数据已插入并且已损坏,因此这只会解决您的插入问题在排序规则更改
-
SQLite 总是使用 Unicode。问题一定出在 I/O 上。
-
你可能需要parameterize your queries:
conn.Execute("INSERT OR REPLACE INTO my_tab (id,name) VALUES(?, ?)", 1, "some characters");
标签: c# sqlite win-universal-app