Android 和 SQLite:何时使用分号结束语句? [英] Android and SQLite: When to use semicolons to end statements?

查看:37
本文介绍了Android 和 SQLite:何时使用分号结束语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在 Android 上使用 SQLite 的 rawQuery()execSQL() 方法,什么时候应该使用分号来结束语句?

If you are using the rawQuery() or execSQL() methods of SQLite on Android, when should you use a semicolon to end your statement?

本教程为例,作者在create table 语句(通过 execSQL),而不是 select 语句(通过 rawQuery).例如:

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:

创建表语句:

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);

选择语句:

Cursor cursor = getReadableDatabase().
  rawQuery("select * from todo where _id = ?", new String[] { id });

是否会出现使用 execSQL() 方法的语句在末尾需要分号,而使用 rawQuery() 方法的语句不需要?>

Is it the case that statements using the execSQL() method need a semicolon at the end, but statements using the rawQuery() method don't?

推荐答案

SQLite 语句以分号 (;) 结束.如果指定了一个,则意味着它是命令的结尾,并且该分号后面可以有更多的命令.如果没有指定分号,则整个字符串被视为命令.

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.

在这种情况下,CREATE 语句中的分号无关紧要,因为它后面没有任何内容.

In this case, the semicolon in the CREATE statement does not matter, as nothing follows it.

这篇关于Android 和 SQLite:何时使用分号结束语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆