Skip to content

Initialization? #20

@Michael-B-G

Description

@Michael-B-G

I'm experiencing an interesting issue. Basically, I have incorporated this module into a larger Python program (or more accurately, I use the "orchestrating" program to issue a command-line call to run this Python program), and I am creating four tables, which is done in a loop. The name I specify for the database file is typically of a file that has not yet been created, e.g. "test_database.db". Because of the way Python's sqlite3 library works, when a database file is connected to it will use the following logic:

  1. If the database file exists and it's in the current path (or the full path has been specified), connect to it.

  2. If the database file does not exist, create it and connect to it.

Now, for each run of my overall program, this Python program is run four times, one for each table. For the first run of this, the file will be created, obviously. So far so good, right?

The next step of my overall program is to run a SQL query on this newly created db file. In a separate function, a new connection is made to the database and then a query is executed on it. However, if the database file was just created in this run of the overall program, I will get an error saying that whatever table I was running a query on was not found, i.e.

sqlite3.OperationalError: no such table: <table_name>

However, if I run my overall program again, with the same table name, I will get the expected results. The thing is, for the purposes of this program I would like to delete the table file each time I run the program if it exists, so that it does not keep growing and growing with the same tables over and over again each time it is run.

I would like to find a way to run my overall program--which consists of creating a DB file and adding the tables to it using csv2sqlite and THEN running some SQL queries on it--in a single go without running into an error.

Has anyone else experienced anything like this? If so, how did you solve it?

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions