【问题标题】:Check if table exist using SQLite-PCL in a UWP在 UWP 中使用 SQLite-PCL 检查表是否存在
【发布时间】:2015-12-21 22:45:09
【问题描述】:

我不知道如何检查表是否已经存在。 我一直在搜索,但之前多次找不到好的示例。

我在 SQLite 上找到的那些不适用于 PCL 版本。不过我不明白为什么,所以如果有人有好的网站可以去,请随时添加。

这些是我用过的:

这是我的代码,显示了我如何尝试检查它,但它只检查始终存在的路径。当我想到它时,这不是一个聪明的解决方案。

private void LikeItButton_Click(object sender, RoutedEventArgs e)
        {
            var sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Filmdb.sqlite");

            using (SQLite.Net.SQLiteConnection conn =
                new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath))
            {
                if (File.Exists(sqlpath))
                {
                    AdMovieID();
                }
                else
                {
                    conn.CreateTable<MovieID>();
                    AdMovieID();
                }
            }
        }

【问题讨论】:

    标签: c# sqlite uwp


    【解决方案1】:

    你可以执行一个查询:

    SELECT name FROM sqlite_master WHERE type='table' AND name='MovieId';
    

    通过做

    var tableExistsQuery = "SELECT name FROM sqlite_master WHERE type='table' AND name='MovieId';"
    var result = conn.ExecuteScalar<string>(tableExistsQuery);
    

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 2017-04-22
      • 2012-12-21
      • 1970-01-01
      • 2017-02-16
      • 2022-01-21
      • 1970-01-01
      相关资源
      最近更新 更多