Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95609
| References | <871teum9c2.fsf@Equus.decebal.nl> <mailman.34.1440338643.17298.python-list@python.org> <87bndxkl3e.fsf@Equus.decebal.nl> |
|---|---|
| Date | 2015-08-24 21:26 +1000 |
| Subject | Re: Is this the way to go with SQLite |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11.1440415612.11709.python-list@python.org> (permalink) |
On Mon, Aug 24, 2015 at 9:00 PM, Cecil Westerhof <Cecil@decebal.nl> wrote:
> On Sunday 23 Aug 2015 16:03 CEST, Chris Angelico wrote:
>
>> On Sun, Aug 23, 2015 at 11:18 PM, Cecil Westerhof <Cecil@decebal.nl> wrote:
>>> Also an URL is unique, so I need to check that if it is found, the
>>> values are the same as the ones I wanted to insert.
>>
>> And if they aren't? Currently, all you do is print out a message and
>> continue on; what happens if you get the same URL coming up more
>> than once?
>
> That is all what I want at the moment: to get notified when an URL has
> two different descriptions. It is just a script to do an initial fill
> of the table. When run again I do not insert the URLs that are already
> in the database. But just skipping is not enough, when it has a
> different description I did something wrong and should investigate
> that.
Sounds to me like you mostly want an error, but in some cases, you'll
suppress the error (ie it's exactly the same description and
datestamp).
>> error). The risk normally is of a race condition; you could execute
>> your SELECT query, find no results, and then have someone else
>> insert one just a moment before you do. But with SQLite, you're
>> probably assuming no other writers anyway - an assumption which (I
>> think) you can mandate simply by opening a transaction and holding
>> it through the full update procedure - which would make this safe.
>
> I start with:
> conn = sqlite3.connect('links.sqlite')
> c = conn.cursor()
>
> and end with:
> conn.commit()
> conn.close()
>
> Taken from:
> https://docs.python.org/2/library/sqlite3.html
>
> This takes care of the transaction, or not?
Yep, I think so. If not, you should be able to ensure transactional
integrity by simply adding an explicit "BEGIN" query.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is this the way to go with SQLite Cecil Westerhof <Cecil@decebal.nl> - 2015-08-23 15:18 +0200
Re: Is this the way to go with SQLite Chris Angelico <rosuav@gmail.com> - 2015-08-24 00:03 +1000
Re: Is this the way to go with SQLite Cecil Westerhof <Cecil@decebal.nl> - 2015-08-24 13:00 +0200
Re: Is this the way to go with SQLite Chris Angelico <rosuav@gmail.com> - 2015-08-24 21:26 +1000
Re: Is this the way to go with SQLite Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-08-23 12:17 -0400
Re: Is this the way to go with SQLite Chris Angelico <rosuav@gmail.com> - 2015-08-24 02:22 +1000
csiph-web