1

Estoy intentando introducir una fecha en la base de datos pero no se introduce.

printdata.py

now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

data_list = list(zip(maclist, signallist))
conn = sqlite3.connect('db/users.db')
c = conn.cursor()
if (id == 1):
    try:
        c.executemany("INSERT OR REPLACE INTO node1 (MAC,SIGNAL,FECHA) VALUES(?,?,?)", data_list, now)
    except Exception as exc:
        c.executemany("REPLACE INTO node1 (MAC,SIGNAL) VALUES(?,?)", data_list)

table info

cid         name        type        notnull     dflt_value  pk        
----------  ----------  ----------  ----------  ----------  ----------
0           ID          INTEGER     0                       1         
1           MAC         CHAR(100)   1                       0         
2           SIGNAL      CHAR(100)   1                       0         
3           FECHA       DATETIME    0                       0
3
  • Intenta agregar la fecha a data_list y pasarlo todo junto a executemany.
    – loki
    el 6 jun. 2019 a las 2:18
  • Tu primer insert no se executa porque executemany sólo toma dos parametros, el string sql y una lista de datos. Como tienes un except esta parte no te falla. El segundo replace no se por que no te funciona. Tienes definido un default para esta columna? Le hiciste commit a la conexión?
    – loki
    el 6 jun. 2019 a las 3:07
  • Se puede saber que error muestra?, para insertar la fecha, lo hago de esta manera. .strftime('%Y/%m/%d') el 6 jun. 2019 a las 11:09

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.