S
S
StepanKoliada2021-02-24 18:15:17
Python
StepanKoliada, 2021-02-24 18:15:17

How to do an action on a variable in sql?

I'm making a program, I need it to take cash from the number I need (input). Tried a lot of things, nothing helped. Tell me how to do it ... Here is the program:

import sqlite3

global db
global sql
db = sqlite3.connect('serversi.db')
sql = db.cursor()

sql.execute("""CREATE TABLE IF NOT EXISTS users (
  cash INT,
  ware INT,
  de INT
)""")
db.commit()



def casino():
  number = input("Сколько грамм:")
  if number == '40':
    print('Ваш баланс повышен на 40')
    sql.execute('UPDATE users SET cash = cash + 40')
    db.commit()
  elif number == '100':
    print("Ваш баланс повышен на 100")
    sql.execute('UPDATE users SET cash = cash + 100')
    db.commit()
  elif number == 'del':
    den = input("Сколько снять:")
    de = '1'
    kk = '2'
    sql.execute('INSERT INTO users VALUES (?,?,?)', (den, de, kk))
    sql.execute('UPDATE users SET cash = cash - de')
    print("Баланс снят на " + de)	
    db.commit()

def enter():
  for i in sql.execute('SELECT cash FROM users'):
    print(i)
  for u in sql.execute('SELECT ware FROM users'):
    print(u)

def main():
  casino()
  enter()
main()

Outputs:

d:\python>pdf.py
How many grams:del
How many to withdraw:1
Traceback (most recent call last):
File "D:\python\pdf.py", line 45, in
main()
File "D:\ python\pdf.py", line 43, in main
casino()
File "D:\python\pdf.py", line 32, in casino
sql.execute('UPDATE users SET cash = cash - de')
sqlite3.OperationalError : no such column: de

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
idShura, 2021-02-24
@StepanKoliada

Read about string concatenation in python

sql.execute('UPDATE users SET cash = cash - ' + de)

You don’t have a condition (Where) in any sql query, do you understand exactly what you write?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question