简体   繁体   中英

Reading a Python generated SQLITE file into SQLITE

So I generated a simple sqlite database called example.db with a table called wasp in Python.

c.execute('''CREATE TABLE wasp
         (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT, x INTEGER, y INTEGER, z INTEGER, temp INTEGER, bat INTEGER)''')

I was able to use Python to add data and read the data. Now I want to import this file in SQLITE using the command line. I installed sqlite3 on linux and am trying to use the .import function but .import example.db wasp generates an error. It says wasp is not a table. It's a table in the example.db file but it's not a table within sqlite. So I recreated the table within sqlite and ran the command again, same problem.

What am I doing wrong?

You do not need to use the .import command to read the table you created from python. The .import command is intended to import tabular text data ( CSV data ).

The python sqlite module however writes native SQLite database files. Just open the example.db file with the sqlite3 command:

$ sqlite3 example.db
SQLite version 3.7.13 2012-06-11 02:05:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
wasp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM