Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android and SQLite: When to use semicolons to end statements?

Tags:

android

sqlite

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?

like image 936
Daniel Scocco Avatar asked Nov 02 '12 20:11

Daniel Scocco


People also ask

Does SQLite need semicolon?

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.

Why we use semicolon after SQL statements?

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.

Is it mandatory to close every SQL query with a semicolon?

The semicolon (;) is used in SQL code as a statement terminator. For most SQL Server T-SQL statements it is not mandatory.

Are SQL commands in SQLite case sensitive?

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.


2 Answers

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.

like image 117
Cat Avatar answered Oct 23 '22 06:10

Cat


I've never used semicolon in both and it works

like image 34
Alexander Kulyakhtin Avatar answered Oct 23 '22 07:10

Alexander Kulyakhtin