Re: problem to insert data

Jens.Toerring_at_physik.fu-berlin.de
Date: 11/25/04


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


Relevant Pages

  • Re: Problems with Delete Command
    ... The SQL could get fairly messy if you need to construct it in code, ... ContactID, and WebComID, and create your on-the-fly SQL on that saved query, ... to find the list of ContactIDs from the junction table, ... This is a style/readability thing: if you are going to use string ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Need help with Code Please!!!
    ... posted in response to my last post was some SQL, but this is not the SQL that ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)
  • RE: Web Part and Access database
    ... I dont know if it is possible to connect to access,but you can download SQL ... Server Error in '/Webparts' Application. ... The connection string specifies a local Sql Server Express instance ... String user, String password, Boolean trusted, String connectionString) ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: INDEXES: BTRIEVE vs EXTFH (cobol)
    ... In SQL, you can specify just about anything, but at the lower MKDE ... the engine has to pick the right Btrieve ... When COBOL needs to find this value, it knows that the key is a string. ...
    (comp.databases.btrieve)
  • Re: INDEXES: BTRIEVE vs EXTFH (cobol)
    ... Bill Bach wrote: ... In SQL, you can specify just about anything, but at the lower MKDE ... the engine has to pick the right Btrieve ... When COBOL needs to find this value, it knows that the key is a string. ...
    (comp.databases.btrieve)