Date/Time conversions

M.-A. Lemburg mal at lemburg.com
Wed Apr 21 04:31:19 EDT 1999


Rico Albanese wrote:
> 
> I am writing a web based database application and I am having problems
> in creating a string that contains an integer in it.   I wish to store
> the login time as an integer so that I may do some time difference
> calculations based  on the stored login time (ie. the integer).  The
> SQL statement string creation fails when I have the integer variable
> "logtime" in it but not when it is removed.  I believe that my problem
> is caused by trying to insert an integer into a string.  The database
> works fine (ie I can add integers to the column "LogTime").

Note that you should *bind* variables to parameters in the
SQL statement rather than insert them literaly into the statement
itself, e.g.

c.execute('insert into table values (?,?)',(123,'string'))

rather than use

c.execute('insert into table values (123,"string")')

See the database topic guide on www.python.org for more details.

-- 
Marc-Andre Lemburg                               Y2000: 254 days left
---------------------------------------------------------------------
          : Python Pages >>> http://starship.skyport.net/~lemburg/  :
           ---------------------------------------------------------





More information about the Python-list mailing list