Alfio D'Anna
Alfio D'Anna

Reputation: 11

SQLite query in Windows Store App return nothing

As i said in the title the query that i written retun nothing while the same tried in Valentina Studio to check the database work fine and i don't understand whats wrong. Here the code:

using System;
using System.Collections.Generic;
using System.Text;
using SQLite;

namespace SQLite_Analizer
{
    public class sqlite_master
    {
        public string name { get; set; }
    }

    public class manager
    {
        public List<string> GetListTables(string DBName)
        {
            List<string> tablesList = new List<string>();
            string itemName = null;
            var con = new SQLiteAsyncConnection(DBName);
            var query = con.QueryAsync<sqlite_master>("SELECT name FROM sqlite_master WHERE type='table' AND NOT SUBSTR(name,1,6) = 'sqlite' ORDER BY name").GetAwaiter().GetResult();        
            foreach(var tablesItem in query)
            {
                itemName = "\n" + tablesItem.name + "\n\n";
                tablesList.Add(itemName);
            }
            return tablesList;
        }
    }
}

Here the new code with a counter to check query result number.

using System;
using System.Collections.Generic;
using System.Text;
using SQLite;

namespace SQLite_Analizer
{ 
    public class sqlite_master
    {
        public string name { get; set; }
    }

    public class manager
    {
        private List<string> tablesList;
        private int count;

        public manager()
        {
            tablesList = new List<string>();
            count = 0;
        }

        public List<string> getList()
        {
            return tablesList;
        }

        public int getCount()
        {
            return count;
        }

        public async void GetListTables(string DBName)
        {
            string itemName = null;
            var con = new SQLiteAsyncConnection(DBName);
            var query = await con.QueryAsync<sqlite_master>("SELECT name FROM sqlite_master WHERE type='table' AND NOT SUBSTR(name,1,6) = 'sqlite' ORDER BY name");
            foreach (var tablesItem in query)
            {
                itemName = "\n" + tablesItem.name + "\n\n";
                tablesList.Add(itemName);
            }
            count = query.Count;
        }
    }
}

Upvotes: 1

Views: 77

Answers (1)

Ken Tucker
Ken Tucker

Reputation: 4156

I would try something like this

    public async List<string> GetListTables(string DBName)
    {
        List<string> tablesList = new List<string>();
        string itemName = null;
        var con = new SQLiteAsyncConnection(DBName);
        var query = await con.QueryAsync<sqlite_master>("SELECT name FROM sqlite_master WHERE type='table' AND NOT SUBSTR(name,1,6) = 'sqlite' ORDER BY name");        
        foreach(var tablesItem in query)
        {
            itemName = "\n" + tablesItem.name + "\n\n";
            tablesList.Add(itemName);
        }
        return tablesList;
    }

Upvotes: 1

Related Questions