executeUpdate() --- what does it actually return?
От | Tomisław Kityński |
---|---|
Тема | executeUpdate() --- what does it actually return? |
Дата | |
Msg-id | 000701c16de6$775a5940$b501a8c0@prod.id.pl обсуждение исходный текст |
Список | pgsql-jdbc |
Hello, I wonder, is this really correct what does executeUpdate() return? I have table with a.o. foreign key pointing to the same table's primary key (yes, it's parent_id). Aaaaand --- the reason of the problem --- I defined a RULE, which looks like this: CREATE RULE forum_articles_uplink AS ON DELETE TO forum_articles DO UPDATE forum_articles SET parent_id = OLD.parent_id WHERE parent_id = OLD.id_article; in short --- it places parent_id from deleted tuple into all tuples, which have parent_id set to id_article of the deleted one (erm... i guess the rule definition is easier to understand ;). Anyway --- in this case executeUpdate() returns amount of tuples modified by above rule instead of number of deleted tuples. Why instead? Because in PSQL console, the query (delete) returns with "1 row(s)" message, not with "5 row(s)" (if 5 articles were modified). It caused me a lot of troubles, since in some cases (when rule did not modify any tuple) executeUpdate() returned 0, and since further code execution were depending on the result (if tuple were delted, ie. result = 1 (in fact result > 0 didn't worked out too), then do something), it --- as you now see --- simply didn't work. So --- is the result of executeUpdate() really correct in cases, when rule applies? On the one hand it's nice to know, how many tuples were modified by the rule, but on the other hand --- it is very usefull to know, how many tuples were deleted, updated or inserted. Thank you for your attention. -- ===] Internet Designers SA, Programming Dept., senior programmer [=== ==] ul. Przedmiejska 6--10, 54-201 Wrocław, http://www.id.pl/ [== =] tel: 0048-71-350-04-45-(42) [= =] fax: 0048-71-373-59-46 [=
В списке pgsql-jdbc по дате отправления: