Check if table exists using SQLite-PCL in UWP

I am stuck on how to check if an alredy table exists. I searched, but, how many times before I could not find good examples.

The ones that I find on SQLite do not work with the PCL version .. I can not understand why this is so. Therefore, if someone has a good website, where to go, feel free to add them.

These are the ones I used: http://blogs.u2u.be/diederik/post/2015/09/08/Using-SQLite-on-the-Universal-Windows-Platform.aspx

https://code.msdn.microsoft.com/windowsapps/Implement-SQLite-Local-8b13a307#content

This is my code on how I tried to test it, but it only checks the path .. that exists alwasy .. not a smart solution when I talk about it :).

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(); } } } 
+8
c # sqlite uwp
source share
1 answer

You can execute the request:

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

by doing

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

All Articles