Skip to content

SQLiteManager v1.0: Selecting data

Raphael Winkler edited this page May 29, 2022 · 1 revision

Selecting all rows from a table

Returning data from our database is pretty easy! If we have a TableStructure named "table" we can do:

ResultSet result = table.Select();

This will return all rows from the selected table, but we can limit our results by adding conditions.

Adding conditions to SELECT statements

We're using our DatabaseStructure class from before in this example. With the "Condition" object we can limit the results of our SELECT:

ResultSet result = structure.songs.Select(new Condition(new KeyValuePair<IColumn, dynamic>(structure.users["name"], "John Doe")));

Limiting the columns returned by SELECT

By adding a list of columns you can select which columns shall be returned in your result set

List<IColumn> columns = new List<IColumn>()
{
  structure.songs["email"],
  structure.songs["information"]
}

ResultSet result = structure.songs.Select(columns, new Condition(new KeyValuePair<IColumn, dynamic>(structure.users["name"], "John Doe")));

Or you can tell the database manager to exclude the tables you provide:

List<IColumn> columns = new List<IColumn>()
{
  structure.songs["id"],
  structure.songs["name"]
}

ResultSet result = structure.songs.Select(columns, true, new Condition(new KeyValuePair<IColumn, dynamic>(structure.users["name"], "John Doe")));

Next up: Add/Update/Delete