1

我正在为我的程序使用 SQLite 数据库。当我在数据库路径中使用英文字符时,一切正常。但是当我想在其路径中打开带有波斯字符的 SQLite 数据库时,它无法打开。我在互联网上搜索并找到了两个其他语言的答案,但它不适用于波斯语。两个选项:

第一个选项:

         var dbPath2 =
Path.Combine(Windows.Storage.ApplicationData.Current.RoamingFolder.Path,
"test.db");
            string utf8String = String.Empty;
            // Get UTF16 bytes and convert UTF16 bytes to UTF8 bytes
            byte[] utf16Bytes = Encoding.Unicode.GetBytes(dbPath2);
            byte[] utf8Bytes = Encoding.Convert(Encoding.Unicode,
Encoding.UTF8, utf16Bytes);
            // Fill UTF8 bytes inside UTF8 string
            for (int i = 0; i < utf8Bytes.Length; i++)
            {
                // Because char always saves 2 bytes, fill char with 0
                byte[] utf8Container = new byte[2] { utf8Bytes[i], 0 };
                utf8String += BitConverter.ToChar(utf8Container, 0);
            }
            string dbPath = utf8String;
            var db = new SQLite.SQLiteConnection(dbPath)

第二个选项(在 Sqlite.cs 中添加引用时出现)

        public SQLiteConnection(string databasePath, bool
storeDateTimeAsTicks = false)
        {
            DatabasePath = databasePath;
            Sqlite3DatabaseHandle handle;
            var r = SQLite3.Open16(DatabasePath, out handle);
            Handle = handle;
            if (r != SQLite3.Result.OK)
            {
                throw SQLiteException.New(r, String.Format("Could not
open database file: {0} ({1})", DatabasePath, r));
            }
            _open = true;
            StoreDateTimeAsTicks = storeDateTimeAsTicks;
            BusyTimeout = TimeSpan.FromSeconds(0.1);
        }

谢谢

4

0 回答 0