0

I am trying to print the entire table from all the tables inside of a db that I have created.

When I try to print all columns for each table I get an error and it seems that the script tries to parse trough one of the inside elements (first column and first row data) and therefore bringing back an error by saying that there is no such a table.

Here is my code:

import sqlite3
conn = sqlite3.connect('amazon_pages.db')
c = conn.cursor()
all_tables_list = c.execute("select name from sqlite_master where type = 'table'")
for table in all_tables_list:
    argument_execute = 'SELECT * FROM ' + table[0]
    print(argument_execute)
    c.execute(argument_execute)

This is the error that I get:

SELECT * FROM Apple_charger
Traceback (most recent call last):
SELECT * FROM B07JGMC714
  File "/Users/Amato/PycharmProjects/Refine/Amazon_pages_sql_database_creator.py", line 36, in <module>
    c.execute(argument_execute)
sqlite3.OperationalError: no such table: B07JGMC714

Process finished with exit code 1

How do I print all the entire tables from the db?

1 Answer 1

1

fetch the result first:

all_tables_list = c.execute("select name from sqlite_master where type = 'table'")
rows = all_tables_list.fetchall()
for row in rows:
    print(row)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.