0

Maybe someone can advise, how to correctly add code which returns epoch time. In MySQL I use following string, but this does not work with sqlite

 query = 'INSERT INTO '+ADS1115tableName+('(dateTime, usUnits, `interval`, ads_ch1, ads_ch2, ads_ch3, ads_ch4, pin1, pin2) VALUES(UNIX_TIMESTAMP(),  %i, %i, %.3f, %.3f, %.3f, %.3f, %.1f, %.1f)' %( units, gap, Voltage[0], Voltage[1], Voltage[2], Voltage[3], button1.value, button2.value ))

Where I can place strftime('%s', 'now') in my query?

Many Thanks

Andrej

battlmonstr
  • 5,841
  • 1
  • 23
  • 33

1 Answers1

1
  1. First, I would separate the query template from the code that populates query parameters.
  2. Then it would be easy to make the template "parametrized" as well and replace: UNIX_TIMESTAMP() with strftime('%s', 'now')

P.S. It's a best practice to use parametrized queries instead of direct interpolation of values such as here

battlmonstr
  • 5,841
  • 1
  • 23
  • 33