0

I am trying to run a tkinter+DuckDB program on M2 Macbook Air and the following error is coming: enter image description here

The program works without any errors on my Windows machine. This is the line specified in the error.

try:
        conn = duckdb.connect(database=dbPathString, read_only=True)
    except:
        constructDatabase()
        conn = duckdb.connect(database=dbPathString, read_only=True)

I am not sure if this is a problem with the code (but this works on my Windows) or with Mac.

Also in my construct database function, I have the sequence that comes up in the error:

# Create schema and serial sequences
    conn.execute(
        """
        -- Start database construction here.
        CREATE SCHEMA IF NOT EXISTS sam;

        -- Create sequences to allow auto-increment of non-null integers in tables.
        CREATE SEQUENCE IF NOT EXISTS __serial_sequence_location_id;
        CREATE SEQUENCE IF NOT EXISTS __serial_sequence_category_id;
        CREATE SEQUENCE IF NOT EXISTS __serial_sequence_material_id;
        CREATE SEQUENCE IF NOT EXISTS __serial_sequence_keyword_id;
    """
    )

Thanks

pr0grmr
  • 57
  • 5

1 Answers1

0

I'm not exactly sure how this code would work on windows. (Unless you created the database on a previous step).

The problem I see is that duckdb.connect() does not throw an exception for an empty database. Hence your constructDatabase() will never be called.

You probably want to do an os.path.exists(dbPathString), or check if the __serial_sequence_location_id exists in the db catalog, and if not call your constructDatabase() function.

Pedro Holanda
  • 261
  • 1
  • 3
  • So I added an if statement which checks if os path exists for dbPathString. If it doesn't it calls out the construct database function which has the line to "Create SEQUENCE IF NOT EXISTS". However, I am still getting the same error. I put a print statement to check if constructDatabase() is called and it sure is. And on Windows, even if I dont have the .duckdb database file, it works without any issues. It recreates it automatically. – pr0grmr Aug 21 '22 at 12:07
  • Can you share a minimum reproducible example (i.e., a full script, hence including the definition of constructDatabase()? – Pedro Holanda Aug 22 '22 at 09:31