1

I currently writing an android app with C#/Xamarin. The App uses a local SQLite Database. There i want to execute a query which is written in the app. The Tables are created through classes like this one:

class TestClass
{
    [PrimaryKey, AutoIncrement, Column("id")]
    public int Id { get; set; }
    [NotNull, Column("messagetext")]
    public string MessageText { get; set; }
    [Column("messagetype")]
    public int MessageType { get; set; }

    public TestClass(string mText, int mType)
    {
        MessageText = mText;
        MessageType = mType;
    }
}

The Database has multiple Tables.

The function

DBConnection.Execute("this is a query")

only executes the Query. Since I need to get a Result, i should use

DBConnection.Query

but while programming, I don't know what tables the query selects, joins... The Query Function requires a TableMapping or Class.

Is there a way to execute a query and get a result without knowing a tablemapping or something else?

Thanks.

Cyalit
  • 11
  • 6

1 Answers1

1

The generic parameter on the overloaded Query method indicates what type of value you want to return from the query.

For instance, say you want to select only the Id field from every row in your TestClass table. Since Id is an int the method call would look like this:

List<int> testIds = DBConnection.Query<int>("SELECT Id FROM TestClass");
Will Decker
  • 3,216
  • 20
  • 30
  • This is not exactly what i need. The SQL Statement is written on Runtime by the User. So i don't know if it is an Integer, String or if he for example selects * from 2 joined tables. – Cyalit Sep 13 '17 at 15:48
  • Okay, thanks for clarifying. If the query is written by the user, then it sounds like you need lower level access to the database connection than what is offered by this library. [Check out the accepted answer to this similar question](https://stackoverflow.com/questions/39106298/is-it-possible-to-return-dynamic-objects-or-dataset-from-a-sqlite-query) – Will Decker Sep 13 '17 at 16:08