Closing ResultSets When Not Selecting

0 views
Skip to first unread message

michael...@gmail.com

unread,
Jul 16, 2007, 7:51:50 PM7/16/07
to Google Gears
Is there any need to close a resultset you're not selecting any rows?
It seems silly to have to assign the result of a database query to a
variable for the sole purpose of closing the resultset, but the docs
do not draw a distinction between resultsets from select operations
and update/delete operations.

Scott Hess

unread,
Jul 16, 2007, 8:16:04 PM7/16/07
to google...@googlegroups.com

We've been thinking of this, witness:
http://code.google.com/p/google-gears/wiki/DatabaseHelpers

From the Gears level, there's really no way to know whether something
is going to return results or not - it's all SQL! An idiom which
should be safe to use for now would be something like:

db.execute("INSERT INTO t VALUES (?)", [x]).close();

This should be safe, if execute() completes, the ResultSet is closed.
If execute() has an error, it will throw an exception and a ResultSet
should never be generated.

-scott

Scott Hess

unread,
Jul 16, 2007, 8:43:21 PM7/16/07
to google...@googlegroups.com
Aaron mentions that I'm subtley wrong.

If the statement succeeds but generates a result set which has no
columns, then the close() is called in execute(). You can close() it
again, but don't need to. So you should be able to safely drop
ResultSets from statements which only do data manipulation language
type statements. [I think this means anything but SELECT or PRAGMA
(which Gears disables) or EXPLAIN.]

Sorry for the misleading post.

-scott

michael...@gmail.com

unread,
Jul 16, 2007, 10:40:00 PM7/16/07
to Google Gears
Just to be 100% clear. You're saying that I do not need to close
ResultSets which do not SELECT rows?

-Mike

On Jul 16, 8:43 pm, "Scott Hess" <sh...@google.com> wrote:
> Aaron mentions that I'm subtley wrong.
>
> If the statement succeeds but generates a result set which has no
> columns, then the close() is called in execute(). You can close() it
> again, but don't need to. So you should be able to safely drop
> ResultSets from statements which only do data manipulation language
> type statements. [I think this means anything but SELECT or PRAGMA
> (which Gears disables) or EXPLAIN.]
>
> Sorry for the misleading post.
>
> -scott
>
> On 7/16/07, Scott Hess <sh...@google.com> wrote:
>

Aaron Boodman

unread,
Jul 16, 2007, 11:17:52 PM7/16/07
to google...@googlegroups.com
Just to be 100% clear. You're saying that I do not need to close
ResultSets which do not SELECT rows?

Yes, we close these ones for you before returning from execute().

- a

michael...@gmail.com

unread,
Jul 18, 2007, 10:53:39 AM7/18/07
to Google Gears
Thanks again!

On Jul 16, 11:17 pm, "Aaron Boodman" <a...@google.com> wrote:

Reply all
Reply to author
Forward
0 new messages