[pgsql-jp: 32161] Re: Rule と Lock

Tsunehisa Kazawa kazawa @ ca2.so-net.ne.jp
2004年 1月 31日 (土) 15:45:36 JST


石井さん、谷田さん、どうもありがとうございます。加澤です。

>>On Thu, 29 Jan 2004 13:39:17 +0900
>>TANIDA Yutaka <tanida @ sra.co.jp> wrote:
>>
>>>># executeQuery に insert 文を入れるのはかなり違和感があります(笑。
>>>
>>>それを言うなら検索結果を返すinsert文の方がよっぽど違和感が・・・:-)
>>
>>Statement#executeQuery()のjavadocには
>>--
>>Executes the given SQL statement, which returns a single ResultSet object.
>>--
>>とあるので、insertであろうがなんだろうが、ResultSetを返すなら
>>executeQuery()であって、仕様上何の問題もありません。
>>
>># 抵抗感はありますが。

なるほど〜。勉強になります。

# 違和感の原因はやっぱり「an SQL statement to be sent to the database,
# typically a static SQL SELECT statement(※)」という記述あたりでしょ
# うか…(^^;。
※http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html より

Tatsuo Ishii wrote:
> この件について本家MLで聞いたところ,JDBCドライバのメインテナ(?)の
> Kris Jurkaさんから,
> 
>>On Thu, 29 Jan 2004, Tatsuo Ishii wrote:
>>>Hi,
>>>
>>>It seems JDBC driver does not handle if a INSERT SQL statement
>>>performed by executeUpdate() is actually a SELECT, which is rewritten
>>>by the rule system.
>>
>>The JDBC spec says an exception should be thrown if "the given SQL
>>statement produces a ResultSet object" which it does.  As you note using
>>executeQuery works, but won't if there isn't a rule.  Perhaps using plain
>>execute() would be the most appropriate thing to do.
>>
>>Kris Jurka
> 
> ということで,executeUpdate()が例外を投げるのは仕様通り.こういうケー
> スでは,execute()を使うのがいいのではないか,というフォローがありまし
> た.

なるほど、PostgreSQL の場合 rule システムによって同一 SQL が ResultSet
を返したり返さなかったりすることがあり得るとすると、(rule システムを利用
することが分かっているなら) あらかじめ execute を利用する、という手も確
かにアリですね。

逆に executeQuery/executeUpdate を用いた一般的なやり方で作る場合は、rule
の使い方に気をつけましょう、ということですね。

本当にいろいろどうもありがとうございました。

-- 
  ◇   加澤恒央 Tsunehisa KAZAWA
◇  ◇ mailto:kazawa @ ca2.so-net.ne.jphttp://www.digitune.org/




pgsql-jp メーリングリストの案内