Python Forum
I need help creating tables with Sqlite3
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help creating tables with Sqlite3
#1
I wish to make a function that creates tables from a tablename list i provide

import sqlite3


def creat_tables():
    conn = sqlite3.connect('listatest.db')
    c = conn.cursor()
    
    tablelist = ('unu','doi','trei')

    for tablename in tablelist:

        create = 'CREATE TABLE IF NOT EXISTS ' + tablename + ' (numar_par INTEGER PRIMARY KEY, echipa1 TEXT UNIQUE, scor1 TEXT, scor2 TEXT, echipa2 TEXT, '
        'cota FLOAT, miza INT, stare INT)'
        c.execute(create)
I get this error

Error:
"C:\Program Files\Python36\python.exe" "D:/pariuri/python/teste sqlite/TutorialSqlite.py" Traceback (most recent call last): File "D:/pariuri/python/teste sqlite/TutorialSqlite.py", line 6, in <module> creat_tables() File "D:\pariuri\python\teste sqlite\create_tables.py", line 17, in creat_tables c.execute(create) sqlite3.OperationalError: near " ": syntax error Process finished with exit code 1
Reply


Messages In This Thread
I need help creating tables with Sqlite3 - by Rius2 - Sep-24-2017, 12:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a table in SQLite3 djwilson0495 2 2,146 Aug-10-2020, 03:01 PM
Last Post: djwilson0495
  Creating Tables in SQL danteslion 2 49,129 Jun-22-2019, 08:13 PM
Last Post: Gribouillis
  sqlite3 table structure and db tables pythonNoob 7 5,052 May-16-2018, 02:19 PM
Last Post: pythonNoob

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020