1

I'm trying to query a data base in the form of an SQL file I have downloaded on my computer to use the data in a machine learning project. I've looked at the database source code, and there is no password setting statement, so I'm very confused at the error I keep getting, which is 'DatabaseError: file is encrypted or is not a database.'

import sqlite3 as lite

con  = None
con = lite.connect('haiku1aip1.sql')
cur =  con.cursor()
cur.execute('SELECT * FROM haiku1aip1')
rows = cur.fetchall()
poems = []
for row in rows:
    poems.append(row)
print(poems)
1
  • Is haiku1aip1.sql a sqlite database or something else (like a text file full of SQL statements)? Commented Dec 12, 2018 at 17:58

1 Answer 1

1

con = lite.connect('haiku1aip1.sql')

This line is trying to connect to a database named "haiku1aip1.sql", but .sql is not the correct file extension for a database file. Your database file would end in .db.

.sql files contain SQL queries, inserts, and other statements (similar to your "SELECT * FROM haiku1aip1" query).

Sign up to request clarification or add additional context in comments.

2 Comments

So would the solution be to create the data base from the file of sql commands I have, and then to access it with this code, with the exception of changing the file extension like you mentioned?
@anonymous_duck It depends on what statements are inside the SQL file. Is it queries (eg. SELECT ...)? Or does it also create tables or insert data (eg. CREATE ..., INSERT ...)?

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.