I would like to make a simple data base with two tables. So I use this code to make it and fill with my .csv data:
import sqlite3
import pandas as pd
import os
conn = sqlite3.connect("base.db")
c = conn.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS table_1 (
Name TEXT,
Index INTEGER,
Sample_ID TEXT PRIMARY KEY);
''')
c.execute('''
CREATE TABLE IF NOT EXISTS table_2 (
Other_id TEXT PRIMARY KEY,
info TEXT);
''')
cmd1 = """sqlite3 base.db <<< ".import table_1.csv table_1" """
cmd2 = """sqlite3 base.db <<< ".import table_2.csv table_2" """
rc1 = os.system(cmd1)
rc2 = os.system(cmd2)
conn.commit()
conn.close()
I get a file with database, but when I use this command SELECT COUNT(*) FROM table_2; in DBeaver I get zero counts. Moreover, the size of .db file is 20,5 kB (20 480 bytes).
How can I fix it? Why is my database empty?
I use this:
- Ubuntu 20.04
- Python 3.8.5
- sqlite3 3.31.1
- DBeaver 21.0.4
base.dbalso look if you saw any error when os. system ran cmd1 and cmd2.