Using SQLite in a Python program

后端 未结 8 731
逝去的感伤
逝去的感伤 2020-12-31 06:28

I have created a Python module that creates and populates several SQLite tables. Now, I want to use it in a program but I don\'t really know how to call it properly. All the

8条回答
  •  温柔的废话
    2020-12-31 07:11

    Don't make this more complex than it needs to be. The big, independent databases have complex setup and configuration requirements. SQLite is just a file you access with SQL, it's much simpler.

    Do the following.

    1. Add a table to your database for "Components" or "Versions" or "Configuration" or "Release" or something administrative like that.

      CREATE TABLE REVISION( RELEASE_NUMBER CHAR(20) );

    2. In your application, connect to your database normally.

    3. Execute a simple query against the revision table. Here's what can happen.
      • The query fails to execute: your database doesn't exist, so execute a series of CREATE statements to build it.
      • The query succeeds but returns no rows or the release number is lower than expected: your database exists, but is out of date. You need to migrate from that release to the current release. Hopefully, you have a sequence of DROP, CREATE and ALTER statements to do this.
      • The query succeeds, and the release number is the expected value. Do nothing more, your database is configured correctly.

提交回复
热议问题