El problema que estoy teniendo es que al intentar modificar la base me retorna el error 'No such column:' pero con el valor del nuevo dato y no con lo que seria una columna
def modify_db(self, campo, valor, telefono, tree):
self.modificar = 'UPDATE producto SET '+campo + \
' = '+valor+' where telefono = '+telefono
print(self.modificar)
self.CursorObj.execute(self.modificar)
self.con.commit()
self.read_db(tree)
El error que me devuelve seria este:
sqlite3.OperationalError: no such column:
Y a continuación de los dos puntos el valor que toma la variable de 'Valor'.
Lo raro es que me deja modificar la columna de 'telefono' pero no las demás.
Adjunto código de sqlite3:
import sqlite3
from sqlite3 import Error, Cursor
from modvali import *
from tkinter import *
class MyBd:
def __init__(self):
try: # Creacion de la base
self.con = sqlite3.connect('basedatos.db')
print('Se creo la base')
except Error:
print(Error)
self.CursorObj = self.con.cursor()
self.CursorObj.execute( # Creacion de la tabla
"""CREATE TABLE if not exists producto(nombre char NOT NULL,
apellido char NOT NULL, telefono INTEGER(12) NOT NULL,
direccion char NOT NULL)""")
def read_db(self, tree):
tree.delete(*tree.get_children())
self.CursorObj.execute('SELECT * FROM producto')
self.rows = self.CursorObj.fetchall()
for row in self.rows:
tree.insert('', END, values=row)
def modify_db(self, campo, valor, telefono, tree):
self.modificar = 'UPDATE producto SET '+campo + \
' = '+valor+' where telefono = '+telefono
print(self.modificar)
self.CursorObj.execute(self.modificar)
self.con.commit()
self.read_db(tree)
def ordenar_db(self, tree, orden):
print(orden)
tree.delete(*tree.get_children())
sql_orden = 'SELECT * FROM producto ORDER BY ' + orden + ' ASC'
print(sql_orden)
self.CursorObj.execute(sql_orden)
self.rows = self.CursorObj.fetchall()
for row in self.rows:
tree.insert('', END, values=row)
"""
self.query = 'SELECT * FROM producto ORDER BY ? ASC'
self.CursorObj.execute(self.query, (orden,))
self.con.commit()
self.read_db(tree)
"""
def borrado(self, telefono, tree):
self.query = 'DELETE FROM producto WHERE telefono = ?'
self.CursorObj.execute(self.query, (telefono,))
self.con.commit()
self.read_db(tree)
def insert_data(self, a, b, c, d, tree):
self.nombre = a.get()
self.apellido = b.get()
self.telefono = c.get()
self.direccion = d.get()
print(self.nombre, self.apellido, self.telefono, self.direccion)
self.validcam = validacioncam( # Validacion de campos vacios
self.nombre, self.apellido, self.telefono, self.direccion)
self.validpa = validacionpa(self.nombre) # Validacion de patron
if self.validcam is True and self.validpa is True:
self.agregar = """INSERT INTO producto (nombre, apellido, telefono, direccion)
VALUES(?,?,?,?) """
self.datos = (self.nombre, self.apellido,
self.telefono, self.direccion)
self.CursorObj.execute(self.agregar, self.datos)
self.read_db(tree)
self.con.commit()
base = MyBd()