Skip to content

UTF-8 strings get encoded incorrectly #147

Closed
@Aurora12

Description

@Aurora12

I'm building a universal store project for Windows 8.1 and Windows Phone 8.1.

  • SQLite for Windows Runtime (Windows 8.1) v. 3.8.8.3
  • SQLite.Net.Async PCL v. 2.5.1
  • SQLite.Net PCL - WinRT Platform v. 2.5.1

I insert data into tables both through ORM objects and through direct requests.
This works fine through ORM or via requests with @params in query, but writing a direct request breaks text encoding.

Is this an expected behaviour? Do I need to encode text somehow?

[Table("Tests")]
public class Test { public string a { get; set; } }
Connection = new SQLiteConnectionWithLock(
  new SQLitePlatformWinRT(),
  new SQLiteConnectionString(
    Path.Combine(ApplicationData.Current.LocalFolder.Path, "test123.db"),
    true
  )
);

Database = new SQLiteAsyncConnection(() => Connection);
await Database.ExecuteAsync("PRAGMA encoding='UTF-8'");

await Database.DropTableAsync<Test>();
await Database.CreateTableAsync<Test>();

// 1: works fine
await Database.InsertOrReplaceAsync(new Test() {
  a = "Through ORM: ЩЫИЯ"
});

// 2: breaks encoding
await Database.ExecuteAsync("INSERT OR REPLACE INTO Tests(a) VALUES ('Via direct request: ЩЫИЯ')");

// 3: works fine
await Database.ExecuteAsync(
  "INSERT OR REPLACE INTO Tests(a) VALUES (@param)", 
  "Via direct request w/param: ЩЫИЯ"
);

List<Test> list = await Database.Table<Test>().ToListAsync();

Debug.WriteLine(list[0].a); // Through ORM: ЩЫИЯ
Debug.WriteLine(list[1].a); // Via direct request: ����
Debug.WriteLine(list[2].a); // Via direct request w/param: ЩЫИЯ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions