On Wed, 30 Apr 2008 03:34:16 -0700 (PDT) Olli Wang <[EMAIL PROTECTED]> wrote:
> > Hi, I'm trying to determine whether the url's database exists or not, > but didn't find any approach. I created a sqlite engine: > > engine = create_engine('sqlite:///test.sqlite') > > And tried to connect it: > > engine.connect() > > But it just created the database file if not existed. So is there any > way to achieve what I expect? Thanks. > Since the part after 'sqlite:///' is just a regular path on the filesystem, so one solution could be to use OS calls like stat() to test for the file: import os engine = create_engine('sqlite:///test.sqlite') try: os.stat(engine.url.database) # Code for when the database exists, such as: engine.connect() except OSError: # Code for when the database does not exist I don't think there's any way to get that information directly from the engine, because I don't think SQLite's API provides for it. Maybe someone can correct me if I'm wrong. Good luck, Kyle --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---