If you are using the rawQuery()
or execSQL()
methods of SQLite on Android, when should you use a semicolon to end your statement?
On this tutorial, for instance, the author uses the semicolon on the create table statement (via execSQL), but not on select statement (via rawQuery). For instance:
Create Table Statement:
private static final String DATABASE_CREATE = "create table "
+ TABLE_COMMENTS + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_COMMENT
+ " text not null);";
database.execSQL(DATABASE_CREATE);
Select Statement:
Cursor cursor = getReadableDatabase().
rawQuery("select * from todo where _id = ?", new String[] { id });
Is it the case that statements using the execSQL()
method need a semicolon at the end, but statements using the rawQuery()
method don't?
If you're using an interactive application, such as the sqlite3 command-line tool, then you'll need to use a semicolon to indicate the end of a statement. The semicolon is not strictly required for single statements, however, as it is properly a statement separator and not a statement terminator.
Some database systems require a semicolon at the end of each SQL statement. Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
The semicolon (;) is used in SQL code as a statement terminator. For most SQL Server T-SQL statements it is not mandatory.
Case Sensitivity The important point to be noted is that SQLite is case insensitive, i.e. the clauses GLOB and glob have the same meaning in SQLite statements.
SQLite statements are terminated by a semicolon (;
). If one is specified, it means it's the end of a command, and that more commands can follow that semicolon. If no semicolon is specified, the entire string is taken to be the command.
In this case, the semicolon in the CREATE
statement does not matter, as nothing follows it.
I've never used semicolon in both and it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With