在 UWP 中使用 SQLite-PCL 检查 table 是否存在

Check if table exist using SQLite-PCL in a UWP

我不知道如何检查 table 是否已经存在。 我一直在搜索,但像很多次一样,我找不到好的例子。

我在 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();
                }
            }
        }

您可以执行查询:

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);