1

プログラムに SQLite データベースを使用しています。データベース パスに英語の文字を使用している場合、すべて正常に動作します。しかし、パスにペルシャ文字を含む SQLite データベースを開こうとすると、開くことができません。インターネットを検索したところ、他の言語について 2 つの回答が見つかりましたが、ペルシア語ではうまくいきませんでした。2 つのオプション:

最初のオプション:

         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)

2 番目のオプション (参照を追加すると、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