sqlite-net-pcl query without Class Model

Willie Phillips 21 Reputation points
2021-08-24T15:34:41.347+00:00

Hi,
If I don't know what fields query will return how can I access table? I mean without Class, is there a way to get field names with some sort of fields index or something? I am new to Xamarin/C# but not new to programming and databases.

Thank you

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2021-08-25T08:51:36.073+00:00

    Hello,
    Welcome to our Microsoft Q&A platform!
    TodoItem is a model class I used in this demo, if you don't konw the model class , you could replace it by object.

    public Task<List<object>> GetItemsNotDoneAsync()  
            {  
                //return Database.QueryAsync<TodoItem>("SELECT * FROM [TodoItem] WHERE [Done] = 0");  
                return Database.QueryAsync<object>("SELECT * FROM [TodoItem] WHERE [Done] = 0");  
            }  
    

    However, if you don't known the table name, I'm afraid it is impossible. If you use sqlite-net-pcl package, this CreateTableAsync<T> method to creat table is necessary, T is a type of the model class you define. When you query the database via the QueryAsync method, it also based on the model class.
    For more information you can refer to
    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/databases
    https://learn.microsoft.com/en-us/xamarin/get-started/tutorials/local-database/?tabs=vswin
    https://github.com/praeclarum/sqlite-net

    Best Regards,
    Wenyan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Alessandro Caliaro 4,196 Reputation points
    2021-08-24T15:40:29.483+00:00

    I think you can take a look to documentation: wiki


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.