Re: problem to insert data
Jens.Toerring_at_physik.fu-berlin.de
Date: 11/25/04
- Next message: Bjørn Augestad: "Re: C... Why not c++?"
- Previous message: Richard Tobin: "Re: 1024 bites interleaving frequency???"
- In reply to: os2: "problem to insert data"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Nov 2004 17:40:41 GMT
os2 <marcpirat@yahoo.com> wrote:
> i have an insertion problem with my rtu table
> datatype for date1 field is: datetime
> i try to insert local date to the database (mysql)
> source code
> struct tm *date;
> struct timeval begin;
> struct timeval end;
> gettimeofday(&end, NULL);
> date = localtime(&end.tv_sec);
> strftime(datestr, 128, "%F %T", date);
> printf("date str %s", datestr);
> snprintf(query, 512, "INSERT INTO rtu (date1,duration,sensorid)
> VALUES(%s,%d,%d)",datestr, 0, 0);
> res=mysql_query(&my_connection,query);
> res display 1 (a error)
That's not a C question at all, it's some SQL problem, so you better
ask in a group that deals with mysql or SQL. The only C related thing
I guess you should do is checking the return value of sprintf(),
which is the length of the string (without the trailing '\0') that
would have been needed to write the complete string, and compare
that to the buffer length - if the buffer was too short and the
text thus truncated you should not try to pass it as a command to
mysql.
<OT>
> query variable return
> INSERT INTO rtu (date1,duration,sensorid) VALUES(2004-11-25
> 15:56:11,0,0)
Look at that again. You have a SQL syntax error - the string with
the date must be enlosed in single quotes (and are you sure that
you want to insert the data into _all_ records of the rtu table or
did you forget about the WHERE clause?) You better figure out how
to get at the error messages - but that's also not a C problem...
</OT>
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Next message: Bjørn Augestad: "Re: C... Why not c++?"
- Previous message: Richard Tobin: "Re: 1024 bites interleaving frequency???"
- In reply to: os2: "problem to insert data"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|