簡體   English   中英

如何使用SQLite.Net設置多個PRAGMA?

[英]How to set multiple PRAGMAs using SQLite.Net?

打開與數據庫的連接后,我可以設置一個PRAGMA,但第二個總是失敗。 如何使用SQLite.Net-PCL 3.1.1設置這兩個PRAGMA? 這適用於通用Windows平台應用程序。

    public static SQLiteConnection Open()
    {
        if (db == null)
        {
            var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, DatabaseFileName);
            db = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath);
            db.Execute("PRAGMA foreign_keys = ON");
            db.Execute("PRAGMA journal_mode = WAL");
        }
        return db;
    }

在第二個執行語句之后,我立即從SQLite獲得“Row”異常。

請求的堆棧跟蹤:

  • 在SQLite.Net.SQLiteCommand.ExecuteNonQuery()
  • 在SQLite.Net.SQLiteConnection.Execute(String query,Object [] args)
  • 在SceneLocker.Models.DBConnection.Open()

編輯:添加被困異常的屏幕截圖:

被困的例外

在第二個執行語句之后,我立即從SQLite獲得“Row”異常。

“行”異常表示語句返回結果行, db.Execute不支持該行。

作為解決方法,您可以使用db.CreateCommand來執行該語句:

var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyDB.db");
db = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath);
db.Execute("PRAGMA journal_mode=DELETE");
var cmd=db.CreateCommand("PRAGMA journal_mode=WAL",new object[] { });//use db.CreateCommand
var result=cmd.ExecuteQuery<object>();//execute the command

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM