I have a projekt where i want to create an webapp. I want to make some calls to the sqllite db but run into the same error over and over.
This is the db code.
class Transaction(db.Model):
__tablename__ = 'Transaction'
transactionID = db.Column(db.Integer, primary_key=True)
sellerID = db.Column(db.Integer)
buyerID = db.Column(db.Integer)
propertyID = db.Column(db.Integer)
anzahlTokens = db.Column(db.Integer)
preisToken = db.Column(db.Float)
datum = db.Column(db.DateTime)
class Besitz(db.Model):
__tablename__ = 'Besitz'
besitzID = db.Column(db.Integer, primary_key=True)
userID = db.Column(db.Integer)
propertyID = db.Column(db.Integer)
anzahlToken = db.Column(db.Integer)
transactionID = db.Column(db.Integer)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "chaindomain.db")
con = sqlite3.connect(db_path)
cursor=con.cursor()
#besitz aus session hier eine form triggern
offerID = 1 #aus get
besitzID =1 #auch
besitzID = 1
userID = 1
propertyID = 1
anzahlToken = 1
transactionID = 1
#transaction
transactionID = 1
sellerID = 2
buyerID = 1
propertyID = 1
anzahlTokens = 1
preisToken = 1
datum = str(date.today())
sql = "INSERT INTO Besitz (userID,propertyID,anzahlToken,transactionID) VALUES (?,?,?,?)"
cursor.execute(sql,
(userID,propertyID,anzahlToken,transactionID,))
con.commit
con.close()
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "chaindomain.db")
con = sqlite3.connect(db_path)
cursor=con.cursor()
sql_1 = "INSERT INTO Transaction(sellerID,buyerID,propertyID,anzahlToken,preisToken,datum) VALUES (?,?,?,?,?,?)"
cursor.execute(sql_1,
(sellerID,buyerID,propertyID,anzahlToken,preisToken,datum))
con.commit
this is the code i try to execute
i dont understand why i only run into an error in the second qeuery.
How can i change my code to make it work?
The program stops at transaction in sql_1
many thanks in advance.
>Solution :
Transaction is a SQLite reserved keyword and can not be used as a table name, unless you quote it :
sql_1 = 'INSERT INTO "Transaction"(sellerID,buyerID,propertyID,anzahlToken,preisToken,datum) VALUES (?,?,?,?,?,?)'