samedi 13 juin 2015

ADD COLUMN WITH LOOP - sqlite python

I make a database (using sqlite3) for a scientific program (Python). This program build makes loops which gradually build the database. So the problem is to add column with a loop. I made an example. It shows that the problem is the variable which defines the new column name (Name 1).

import sqlite3
import os

conn=sqlite3.connect(':memory:')
c=conn.cursor()

c.execute('''CREATE TABLE TableName (Var1 REAL, Var2 REAL)''')

Name1='Test1'
c.execute('''ALTER TABLE TableName ADD COLUMN "+Name1+" INTEGER''')
Name1='Test2'
c.execute('''ALTER TABLE TableName ADD COLUMN "+Name1+" INTEGER''')

Does anyone have an advice to solve this problem please ? Thanks and have a nice day.

Aucun commentaire:

Enregistrer un commentaire