[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Exceptions on delete in pysqlite

Wildemar Wildenburger

1/26/2008 12:13:00 AM

Hi there,

Using pysqlite, I'd like to check if some dataset that I removed has
been in the database at all. Ideally I'd like pysqlite to raise an
Exception if deleting does nothing. Is that possible?

Codewise, I'd like the following, but without me checking for and
raising the exception myself:

cur = con.execute("""DELETE FROM SomeTable WHERE id=? AND name=?""",
(ID, NAME))
if cur.rowcount == 0:
raise Exception


/W
3 Answers

Gabriel Genellina

1/27/2008 5:45:00 PM

0

En Fri, 25 Jan 2008 22:12:57 -0200, Wildemar Wildenburger
<lasses_weil@klapptsowieso.net> escribi�:

> Using pysqlite, I'd like to check if some dataset that I removed has
> been in the database at all. Ideally I'd like pysqlite to raise an
> Exception if deleting does nothing. Is that possible?

I don't think so. It isn't an error, like a SELECT which returns an empty
set isn't an error either.

> Codewise, I'd like the following, but without me checking for and
> raising the exception myself:
>
> cur = con.execute("""DELETE FROM SomeTable WHERE id=? AND name=?""",
> (ID, NAME))
> if cur.rowcount == 0:
> raise Exception

Write a function to do that.

--
Gabriel Genellina

Gabriel Genellina

1/27/2008 5:45:00 PM

0

En Fri, 25 Jan 2008 22:12:57 -0200, Wildemar Wildenburger
<lasses_weil@klapptsowieso.net> escribi�:

> Using pysqlite, I'd like to check if some dataset that I removed has
> been in the database at all. Ideally I'd like pysqlite to raise an
> Exception if deleting does nothing. Is that possible?

I don't think so. It isn't an error, like a SELECT which returns an empty
set isn't an error either.

> Codewise, I'd like the following, but without me checking for and
> raising the exception myself:
>
> cur = con.execute("""DELETE FROM SomeTable WHERE id=? AND name=?""",
> (ID, NAME))
> if cur.rowcount == 0:
> raise Exception

Write a function to do that.

--
Gabriel Genellina

Wildemar Wildenburger

1/27/2008 6:05:00 PM

0

Gabriel Genellina wrote:
> En Fri, 25 Jan 2008 22:12:57 -0200, Wildemar Wildenburger
> <lasses_weil@klapptsowieso.net> escribi�:
>
>> Using pysqlite, I'd like to check if some dataset that I removed has
>> been in the database at all. Ideally I'd like pysqlite to raise an
>> Exception if deleting does nothing. Is that possible?
>
> I don't think so. It isn't an error, like a SELECT which returns an
> empty set isn't an error either.
>
Of course, but you know ... I was hoping.


>> Codewise, I'd like the following, but without me checking for and
>> raising the exception myself:
>>
>> cur = con.execute("""DELETE FROM SomeTable WHERE id=? AND name=?""",
>> (ID, NAME))
>> if cur.rowcount == 0:
>> raise Exception
>
> Write a function to do that.
>
Yeah well you see, I have several similar functions for inserting,
updating and deleting on different tables. And I wanted them all to
behave uniformly, raising some exception when the operation did not do
quite right (in this case: delete something that is not there.). That
way, all those functions would even have looked similar, and I would
have liked that for readability. Or for my autism, you pick. :)

Well, thanks anyway. :)
/W