Re: Opening a DB Connection
Liam Clarke <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Rich Shepard wrote:
> In both the web site documentation and Mike Owens' excellent book (except
> for the index), the examples of opening a database connect are:
>
> con = sqlite3.connect("name.db")
>
> and there is no check for an error condition. As a long time C coder, and
> a newcomer to python, I feel uncomfortable assuming that the connection will
> be made without error when the application runs.
>
> Is my worry misplaced? If not, what is the desired way of wrapping the
> statement in a test for successful completion?
>
> Thanks,
>
> Rich
>
>
Hi Rich,
If a database doesn't exist, it'll create it. If it does fail, you'll
most likely get a OperationalError thrown. I couldn't get it to fail on
my machine, so I can't answer that with 100% certainty.
Regards,
Liam Clarke