Re: [android-group-japan: 19296] SQLiteDatabaseクラスのrawQueryメソッドの引数sqlについて

567 views
Skip to first unread message

Tatsuo Nagamatsu

unread,
Jul 31, 2012, 10:59:49 AM7/31/12
to android-g...@googlegroups.com
sqlite3の tokenizerでは勝手に最後の semicolonは付けてくれるので、不要。

> The tokenizer appends a semicolon to the end of input if necessary. This ensures
> that every SQL statement is terminated by a semicolon.

> H41040: When the tokenizer reaches the end of input where the last token sent to
> the parser was not a SEMI token, it shall send a SEMI token to the parser.

http://www.sqlite.org/draft/tokenreq.html#H41040

ここに書かれている statementの diagramでは、最後の semicolonは不要となる!?

http://www.sqlite.org/syntaxdiagrams.html#sql-stmt-list

それに対し sqliteのコマンドラインでは、最後の semicolonは必要

http://www.sqlite.org/sqlite.html

--

2012/7/31 Yasuhiro Ito <yasuhiro...@gmail.com>
>
> SQLiteDatabaseクラスのrawQueryメソッドの引数sqlについてわからないことがあります。
> Android Developerのリファレンスを見ると引数sqlの説明は
>
> the SQL query. The SQL string must not be ; terminated
>
> と書いてあります。
> 英語には自信がないのですが、must not で禁止だから
> 「SQL文字列はセミコロンで終わってはいけない。」
> という意味だと思ってます。
>
>
> しかし、自分が持っている本や "android rawQuery" で検索で上位に
> 出てくる日本語のサイトのサンプルコードを見ると
> だいたいセミコロンで終わるSQL文を引数sqlにセットしています。
>
> 実際に試してみると
> db.rawQuery("SELECT * FROM SampleTable", null);
> と
> db.rawQuery("SELECT * FROM SampleTable;", null);
> はどちらも思ったように動くのですが、
> リファレンスに「セミコロン付けるな」と書いてあるのに、
> 本やWEBサイトの多くのサンプルコードにセミコロンが付いているのが
> なんだか気になります。
>
>
> 実際、どのように書くべきなんでしょうか?
>
> --
> このメールは Google グループのグループ「日本Androidの会」の登録者に送られています。
> このディスカッションをウェブ上で閲覧するには、https://groups.google.com/d/msg/android-group-japan/-/ttACROTq7-wJ にアクセスしてください。
> このグループに投稿するには、android-g...@googlegroups.com にメールを送信してください。
> このグループから退会するには、android-group-j...@googlegroups.com にメールを送信してください。
> 詳細については、http://groups.google.com/group/android-group-japan?hl=ja からこのグループにアクセスしてください。

Yasuhiro Ito

unread,
Aug 3, 2012, 9:48:59 AM8/3/12
to android-g...@googlegroups.com
nagamatuさん、回答ありがとうございます。
sqliteがセミコロンを付けてくれるんですね。すっきりしました。
 
Reply all
Reply to author
Forward
0 new messages