Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #57798
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <burak.arslan@arskom.com.tr> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'schema': 0.05; 'exist,': 0.09; 'lookup': 0.09; 'try:': 0.09; 'burak': 0.16; 'flow.': 0.16; 'from:addr:arskom.com.tr': 0.16; 'from:addr:burak.arslan': 0.16; 'from:name:burak arslan': 0.16; 'message-id:@arskom.com.tr': 0.16; 'received:arskomhosting.com': 0.16; 'sqlite': 0.16; 'subject:flow': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'select': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'controlling': 0.24; 'entries': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'database,': 0.30; 'existence': 0.31; 'file': 0.32; 'open': 0.33; 'table': 0.34; 'there,': 0.34; "i'd": 0.34; 'created': 0.35; 'except': 0.35; 'something': 0.35; 'acceptable': 0.36; 'hi,': 0.36; 'should': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'remove': 0.60; 'protect': 0.79; 'victor': 0.84 |
| Date | Mon, 28 Oct 2013 10:17:26 +0200 |
| From | Burak Arslan <burak.arslan@arskom.com.tr> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Try-except for flow control in reading Sqlite |
| References | <ac7cf18f-d4f4-41ef-966d-a35d2d0e39a8@googlegroups.com> |
| In-Reply-To | <ac7cf18f-d4f4-41ef-966d-a35d2d0e39a8@googlegroups.com> |
| X-Enigmail-Version | 1.5.2 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1686.1382948833.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1382948833 news.xs4all.nl 15878 [2001:888:2000:d::a6]:42920 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:57798 |
Show key headers only | View raw
On 10/28/13 05:43, Victor Hooi wrote:
> Hi,
>
> I'd like to double-check something regarding using try-except for controlling flow.
>
> I have a script that needs to lookup things in a SQLite database.
>
> If the SQLite database file doesn't exist, I'd like to create an empty database, and then setup the schema.
>
> Is it acceptable to use try-except in order to achieve this? E.g.:
>
> try:
> # Try to open up the SQLite file, and lookup the required entries
> except OSError:
> # Open an empty SQLite file, and create the schema
>
this doesn't protect against a partially-created schema. do you have
something like a "version" table in your database as the last created
table? you can check for its existence in the except block and if it's
not there, you should remove the file and re-create it.
to get a list of tables:
select * from sqlite_master where type='table';
best,
burak
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Try-except for flow control in reading Sqlite Victor Hooi <victorhooi@gmail.com> - 2013-10-27 20:43 -0700
Re: Try-except for flow control in reading Sqlite Steven D'Aprano <steve@pearwood.info> - 2013-10-28 06:18 +0000
Re: Try-except for flow control in reading Sqlite Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-10-28 10:48 +0100
Re: Try-except for flow control in reading Sqlite Chris Angelico <rosuav@gmail.com> - 2013-10-28 17:36 +1100
Re: Try-except for flow control in reading Sqlite Victor Hooi <victorhooi@gmail.com> - 2013-10-27 23:57 -0700
Re: Try-except for flow control in reading Sqlite Chris Angelico <rosuav@gmail.com> - 2013-10-28 18:01 +1100
Re: Try-except for flow control in reading Sqlite Steven D'Aprano <steve@pearwood.info> - 2013-10-28 07:19 +0000
Re: Try-except for flow control in reading Sqlite Chris Angelico <rosuav@gmail.com> - 2013-10-28 18:02 +1100
Re: Try-except for flow control in reading Sqlite Burak Arslan <burak.arslan@arskom.com.tr> - 2013-10-28 10:17 +0200
Re: Try-except for flow control in reading Sqlite Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-28 19:43 -0400
Re: Try-except for flow control in reading Sqlite Victor Hooi <victorhooi@gmail.com> - 2013-10-31 16:08 -0700
Re: Try-except for flow control in reading Sqlite Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-31 22:45 -0400
csiph-web