SQLite QueryAsync Problem RRS feed

  • Question

  • User239139 posted

    hi guys, I installed sqlite-net-pcl and created a table via ExecuteAsync like this: SQLiteAsyncConnection db = new SQLiteAsyncConnection(AppConstants.LocalDataBasePath); StringBuilder Query = new StringBuilder();
    Query.Append("CREATE TEMP TABLE tmpActivePlan") .Append(" ( PlanCode TEXT,") .Append(" CalculationMethod INT, PlanType INT,") .Append(" CustomerWithDiscount INT,") .Append(" ReferencePlanCode TEXT,") .Append(" CommercialSequence INT,") .Append(" BranchCode INT, Checked INT").Append(" )"); await db.ExecuteAsync(Query.ToString());

    everthing is well and working but when i want to run select query from QueryAsync like this:

    await db.QueryAsync(null, "select * from tmpActivePlan"); "QueryAsync" want to T class or table mapping but i dont have any class from "tmpActivePlan" my table is created via ExecuteAsync! is there any way to give data result from tmpActive_Plan without table mapping like "Cursor" in JAVA? sample java code is here:

    String Select = new StringBuilder() .append("SELECT CommercialSequence, ifnull(Checked, 0) AS Checked") .append(" FROM tmpActivePlan").append(" WHERE PlanCode = '") .append(PlanCode).append("'").toString(); Cursor cursor = DBA.DBAdapterSelect(Select, null);
    CommercialSequence = cursor.getInt(cursor.getColumnIndex("CommercialSequence")); Checked = cursor.getInt(cursor.getColumnIndex("Checked"));

    Commercial_Sequence and Checked given by Cursor!

    Sunday, September 13, 2020 7:18 AM


  • User369979 posted

    Cursor is an Android class: https://docs.microsoft.com/en-us/xamarin/android/user-interface/layouts/list-view/cursor-adapters#creating-the-cursor We could still use it in Xamarin Android. But Forms is a cross-platform technique. It doesn't have this object. We could consume it with a model like: public class Model { public string Plan_Code { set; get; } public int Calculation_Method { set; get; } public int Plan_Type { set; get; } public int Customer_With_Discount { set; get; } public string Reference_Plan_Code { set; get; } public int Commercial_Sequence { set; get; } public int Branch_Code { set; get; } public int Checked { set; get; } } And then we could easily create a table: SQLiteAsyncConnection db = new SQLiteAsyncConnection(AppConstants.LocalDataBasePath); await db.CreateTableAsync<Model>(); Query all the records:

    var items = await db.Table<Model>().ToListAsync();

    Refer to this documentation for more information: https://docs.microsoft.com/en-us/xamarin/get-started/quickstarts/database?pivots=windows

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, September 14, 2020 5:36 AM