SQLite.Net.Async.SQLiteAsyncConnection Questions.

Issue #74 invalid
Sumesh Chandran created an issue

Hello all, Could someone advise whether the code I have here is right or not? I am using the async version of SQLite.Net.Async-PCL library.

using SQLite.Net;using SQLite.Net.Async;using SQLite.Net.Attributes;
    string databasePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Scheduler.sqlite");
        public static SQLiteAsyncConnection db;
     var conFunction = new Func<SQLiteConnectionWithLock>(() =>
                new SQLiteConnectionWithLock(new SQLitePlatformWinRT(),
                    new SQLiteConnectionString(databasePath, false)));
            var connectionString = new SQLiteConnectionString(databasePath, false);
            var connectionWithLock = new SQLiteConnectionWithLock(new SQLitePlatformWinRT(), connectionString);
            db = new SQLiteAsyncConnection(() => connectionWithLock);

This code doesn't show any red squiggly's, but it doesn't work.

var existing = await App.db.QueryAsync<Schedule>("select * from Schedule where Date = ? order by ShiftStart", theWeek.AddDays(i));

The above line is inside a try statement, the moment the compiler hits this line, it goes to the catch block. I am pretty there is nothing wrong with the Query Statement as I was using this with the other SQLiteAsyncConnection library. Please advise?

Comments (4)

  1. Guillermo Gutiérrez

    Async methods will execute on a different thread, so you cannot just step-in in the debugger like any other method, because the thread that you are debugging will continue executing elsewhere. However you can set a breakpoint at the following line and it should stop there when that statement finishes.

    As a side note, that query can also be written like this (haven't tested it):

    var existing = await App.db.Table<Schedule>.Select(s => s == theWeek.AddDays(i)).OrderBy(s => s.ShiftStart).ToListAsync();
    

    This way is much more refactor friendly.

  2. Sumesh Chandran reporter

    Thanks Guillermo. I am just wondering how do I write a connection statement using this library which is SQLite.Net.Async. What are the Nuget Packages that I need to add to my project? Please advise.

  3. Guillermo Gutiérrez

    Hi Sumesh,

    I don't understand your question. The code that you attached already creates a SQLiteAsyncConnection and the required NuGet packages are specified in the realm file.

  4. Log in to comment