Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SqLite near field error
#1
I wrote this code. When I run it I don't get errors but I can't get the values inserted in the table, I end up with a database with table1 that's empty. Any help?

TabelName = 'table1'
values = [1, 1, 1.0, 1.0, 0]
columnsNmes =['Day', 'Month', 'Hour', 'HOY', 'Sun Falling on Tower Facade']
fieldTypes = [REAL,REAL,REAL,REAL,REAL]
filepath = 'C:\xampp\htdocs\FT-test9.db'
conn = sqlite3.connect(filePath)

c = conn.cursor()
try:
    c.execute('CREATE TABLE IF NOT EXISTS {tn} ({nf} {ft})'\
                .format(tn=tableName, nf=columnsNames[0], ft=fieldTypes[0]))
        
       
    for i, j in zip(columnsNames[1:], fieldTypes[1:]):
        c.execute("ALTER TABLE {tn} ADD COLUMN '{cn}' {ct}"\
                    .format(tn=tableName, cn=i, ct=j))
    
    except:
        pass

newColumnsNmes = []

for d in data:
    m =float(d)
    newColumnsNames.append(m)
        
for m,n in zip(newColumnsNames, data):     
    c.execute("INSERT INTO {tn} {cn} VALUES {vn}"\
        .format(tn=tableName, cn=m, vn= n))
conn.commit()
conn.close()
Reply


Messages In This Thread
SqLite near field error - by raniat123 - May-24-2018, 02:35 PM
RE: SqLite near field error - by Larz60+ - May-24-2018, 02:42 PM
RE: SqLite near field error - by raniat123 - May-24-2018, 02:42 PM
RE: SqLite near field error - by Larz60+ - May-24-2018, 02:46 PM
RE: SqLite near field error - by raniat123 - May-24-2018, 02:56 PM
RE: SqLite near field error - by Larz60+ - May-24-2018, 03:00 PM
RE: SqLite near field error - by raniat123 - May-24-2018, 05:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help With Python SQLite Error Extra 10 15,898 May-04-2022, 11:42 PM
Last Post: Extra
  Error while transferring data from sqlite to elasticsearch - please help! ps96068 1 2,785 Jun-12-2021, 09:24 AM
Last Post: ibreeden
  UPDATE SQLITE TABLE - Copy a fields content to another field. andrewarles 14 4,661 May-08-2021, 04:58 PM
Last Post: ibreeden
  Bug ? when dataclass field name == field type Cyril 0 1,619 Oct-22-2020, 03:26 AM
Last Post: Cyril
  SQLite Unique constraint failed error djwilson0495 3 13,817 Aug-14-2020, 05:23 PM
Last Post: ndc85430
  Error SQLite objects created in a thread can only be used in that same thread. binhduonggttn 3 15,887 Jan-31-2020, 11:08 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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