0

here's the code:

import sqlite3
cx = sqlite3.connect("test.db")
cu = cx.cursor()

# create table 1.
cu.execute("create table user_info1 (user_id text primary key,followers integer, asks integer, answers integer, goods integer)")

# create table 2
cu.execute("create table user_info2 (user_id text primary key,followers integer, asks integer, answers integer, goods integer)")

Now I'm wondering to see how many tables are in test.db:

cu.execute('.tables') # doesn't work.

cu.execute('select * from test.sqlite_master where type = "table"')
# OperationalError: no such table: test.sqlite_master

The methods above doesn't work for me. Have any hint? Thanks!

zihaolucky
  • 196
  • 1
  • 11

1 Answers1

2

The name of your database is not test (that would be part of the file name) but main:

cu.execute("SELECT * FROM main.sqlite_master WHERE type = 'table'")

And main is the default database name, so you do not even need to specifiy it:

cu.execute("SELECT * FROM sqlite_master WHERE type = 'table'")
CL.
  • 173,858
  • 17
  • 217
  • 259