I'm stuck with how to check if a table already exists. I have been searching but like many times before I can't find good examples.
The ones I find on SQLite don't work with the PCL version. I can't understand why though, so if anyone has a good site where to go please feel free to add them.
These are the ones I have 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 showing how I have tried to check it, but it only checks the path, which always exists. Not a smart solution when I thought 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();
}
}
}
SQLite-net is an open source and light weight library providing easy SQLite database storage for . NET, Mono, and Xamarin applications. This version uses SQLitePCLRaw to provide platform independent versions of SQLite.
You could execute a query:
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With