Reputation: 1754
I'd like to use UTF-8 standard for multi language strings into my db, for example I want to insert some strings in russian and retrieve them for later use. At the moment I get ??? signs instead of russian characters in my db. Is there a way to set my db to work with multiple language characters?
I found some posts about PRAGMA
, but I can't get it work, something like:
await Database.ExecuteAsync("PRAGMA encoding='UTF-8'");
I am using SQLite.Net-PCL, System.Data.SQLite and SQLite for Universal Windows Platform as references.
My actual database creation code:
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();
}
}
}
EDIT My insert query is:
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();
}
}
}
where singSqlQuery
is a usual sql query like:
INSERT OR REPLACE INTO my_tab (id,name) VALUES('1','some characters');
Upvotes: 0
Views: 1079
Reputation: 1375
SQLite fully supports storage of Unicode data by default. You don't need to do anything special, It Just Works. If you're not getting out what you're putting in, the problem is with your insert or retrieval. There's most likely a conversion happening somewhere that you don't intend. You may want to use a parameterized query for the insert if you aren't already doing so.
Upvotes: 2