From: r.albanese at qut.edu.au (Rico Albanese)
Date: Tue, 20 Apr 1999 12:51:19 +1000
Subject: Date/Time conversions
Message-ID: <371BEBA7.5DBC1B0F@qut.edu.au>
Content-Length: 2222
X-UID: 911                                                  

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").

This is part of the code:
.
import dbi,odbc  #For ODBC stuff
import time  #For ODBC and time related stuff
import rexec  #For executing the SQL query
import cgi  #For processing the form stuff
import re  #For regular expression and pattern matching

#-------------------------------------------------------------------------------------------------------

form = cgi.SvFormContentDict()
.
.
.
Caller=Ph=Loc=Sch=JbDes=JbPr=None
Caller=form['Name']
Ph=form['PhNumb']
Loc=form['Locn']
Sch=form['Schl']
JbDes=form['JobDesc']
JbPr=form['urgency']
.
.
logtm=time.time()    #a floating point
logtime=int(logtm)    #an integer
.
.
frontpar='('
backpar=')'

#Build the SQL statement string

thesql="INSERT INTO CSJobs.compjobs
(LogTime,Caller,Phone_Extension,Caller_Category,Location,Job_Description,Job_Priority,LogNumb,Log_Date,Finished)
VALUES "
thesql=thesql + frontpar + logtime + ","
The inclusion of this variable ^ (ie logtime) causes this script to
fail.  When it is removed, it works ok.

thesql= thesql + "'" + Caller + "'" + ","
thesql=thesql + "'" + Ph + "'" + "," + "'" + Sch + "'" + ","
thesql=thesql + "'" + Loc + "'" + "," + "'" + JbDes + "'"
thesql=thesql + "," + "'" + JbPr + "'" + "," + "'" + LogN + "'" + "," +
"'" + logdate + "'" + "," + "'" + "n" + "'"
thesql=thesql + backpar
thesql='"""' + thesql + '"""'
thesql=frontpar + thesql + backpar
thecode='crsr.execute' + thesql
.
.
exec(thecode)

Any suggestions as to what I am doing wrong??

Thanks in advance for any assistance.

Rico

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/19990420/60eb3e32/attachment.html>


