ryan
ryan

Reputation: 3

sqlite3.OperationalError:near syntax error

my code is the following:

import sqlite3 as sql

def execute_sql(sql_command, sql_cursor):
    result = sql_cursor.execute(sql_command)
    return result


def print_0th_col(sql_result):
    for next_record in sql_result:
        print(next_record[0])

def create_tables(sql_cursor):
    sql_command = '''CREATE TABLE artist
    (artist_id INTEGER UNIQUE
    artist_name VARCHAR(100),
    age INTEGER,
    members INTEGER,
    formation VARCHAR(4))
    '''
    execute_sql(sql_command,sql_cursor)
    sql_command = '''CREATE TABLE songs
    (song_id INTEGER UNIQUE,
    song_name VARCHAR(100),
    Band_id INTEGER UNIQUE)
    '''
    execute_sql(sql_command, sql_cursor) 

    conn = sql.connect('ex9.db')

    sql_cursor = conn.cursor() 

    conn.commit() 
    conn.close()



 def drop_table(sql_cursor,table_name):
  sql_command = '''DROP TABLE ''' + table_name
  execute_sql(sql_command, sql_cursor) 

and when i debug it, it says sqlite3.OperationalError:near "artist_name":syntax error.


can anyone tell me what is wrong with the code?

Upvotes: 0

Views: 3715

Answers (1)

MattDMo
MattDMo

Reputation: 102842

The artist_id line should be:

(artist_id INTEGER UNIQUE,

Your code is missing the comma , at the end.

Upvotes: 2

Related Questions