Android direct execution SQL is execsql (String sql).
This method can execute arbitrary SQL statements. But changing this is not flexible enough.
Query This method can be a good solution to this problem.
-
Because we're just introducing a sqlite approach, we don't explain the structure of the project or anything.
We won't say anything about building a table.
(Cursor) query (string table, string[] columns, string selection, string[] Selectionargs, String groupBy, string having, St Ring, String limit)
-
Now the explanation of the parameters
String table: The table to query
string[] Columns: Returns that column, and if the argument is null, all columns are returned.
(but this is not recommended)
String selection: Returns the filter for that row.
(format is the where of SQL, set to NULL, return all rows of this table)
-
string[] Selectionargs: '? ' may be used in the selection field The form to add some extra parameters.
String GroupBy: How to Group a filter. (not grouped if set to null)
-
String having: the filter condition of the aggregation after grouping. (The function is the same as the SQL statement)
String ORDER By: Sort, in the same format as the SQL order.
(set NULL to use the default (unordered Unonder) arrangement.) )
-
String limit: The number of rows returned, set to NULL to indicate no restriction clauses.
Examples such as:
-
Query returns a cursor.
There are also a number of ways to target cursors (cursor)
GetCount (): Total number of records
IsFirst (): Determine if the first record
Islast (): Determine if the last record
Movetofirst (): Move to first record
Movetolast (): Move to last record
Move (int offset): Moves to the specified record
MoveToNext (): Move to scare a record
Movetoprevious (): Move to previous record
Getcolumnindex (String columnName): Gets the int type value of the specified column index
-
The aggregation functions in the SQL statement are written for example: SUM, COUNT, MAX, AVG, and so on. The fundamental difference between these functions and other functions is that they generally function on more than one record. SELECT SUM (population) from BBC
-
In an SQL statement, there is a filter after grouping (group by), and the filter in the grouped data group is filtered before grouping.
By using the GROUP BY clause, you can have the sum and COUNT functions work on data that belongs to a group.
The HAVING clause allows us to filter the group data after the group. The WHERE clause filters the records before aggregating. That is, it works before the GROUP BY clause and the HAVING clause. The HAVING clause filters the group records after aggregation.
END
Precautions