linuxdesire
linuxdesire

Reputation: 75

Python coding for SQLite is not populating the Database

I found a tutorial online that will let a user input a movie in the command line and it will search IMDB and return all the information. That is working.

So I decided I wanted to be able to import the movie data into a SQLite database. The database is being generated with the table but is not getting the information and I am not getting an error. Here is what I have.

Here is the SQLite code:

import sqlite3
from sqlite3 import Error
def sql_connection():
    try:
        con=sqlite3.connect('movies.db')
        return con
    except Error:
        print(Error)

def sql_table(con):
    cursorObj=con.cursor()
    cursorObj.execute("CREATE TABLE movies(id integer PRIMARY KEY,\ 
    tite text, year integer, full cast text, rating integer, plot \
    text )")

    con.commit()
con=sql_connection()
sql_table(con)

def sql_insert(con,entities):
    cursorObj=con.cursor()
    cursorObj.execute('INSERT INTO movies(id, title, year of \
    release, full cast, rating, cast) VALUES(?,?,?,?,?,?)',entities)\
    con.commit()
sql_insert(con,entities)
con.close()

Upvotes: -1

Views: 277

Answers (1)

Kate
Kate

Reputation: 1836

I see mistakes:

Typo: tite instead of title in:

cursorObj.execute("CREATE TABLE movies(id integer PRIMARY KEY,\ 
tite text, year integer, full cast text, rating integer, plot \
text )")

In the second statement, you are attempting to update field year of release, that doesn't exist (you named it year earlier).

cursorObj.execute('INSERT INTO movies(id, title, year of \
release, full cast, rating, cast) VALUES(?,?,?,?,?,?)',entities)\
con.commit()

If you are going to use column names containing spaces, you'll need back ticks or square brackets, something that I would avoid. So instead of full cast I would use the underscore character (_) to avoid spaces: full_cast. But in your create statement you called the field cast so the insert is not going to work.

Upvotes: 0

Related Questions