Overview
Features
Download
Documentation
Community
Add-Ons & Services

Insert timestamp field into a MySQL table using Poco librari

Please post support and help requests here.
dbarzo
Posts: 40
Joined: 14 Jan 2013, 17:15
Location: Italy

Insert timestamp field into a MySQL table using Poco librari

Postby dbarzo » 03 Jun 2014, 15:14

I'm working with a MySQL DB and I have a table defined as:

Code: Select all

CREATE TABLE tbl_misure (
  m_rcd_id          INT NOT NULL AUTO_INCREMENT ,
  m_fon_id          INT,
  m_timestamp       TIMESTAMP,
  m_fon_rcd_id      INT,
  m_fon_Leq         FLOAT(4,2),
  m_fon_LsMax       FLOAT(4,2),
  m_Leq_state       INT,        /* Leq state: 0->OK, 1->FAIL*/
  m_LsMax_state     INT,        /* Ls  state: 0->OK, 1->FAIL*/

  PRIMARY KEY ( m_rcd_id )

  INDEX fon_key (m_fon_id),
  FOREIGN KEY (m_fon_id) REFERENCES tbl_users(fon_id)
  ON DELETE CASCADE
  ON UPDATE CASCADE,

) ENGINE = InnoDB;


Now, to add records I'm using the following code:

Code: Select all

EDBReturnValues DataHandler::AddFonMeasure(const TDBFonValues& in_values) {
  Poco::Int64 ts = in_values.timestamp.utcTime();

  try {
    *m_pSession << "INSERT INTO tbl_misure \
                   (m_fon_id, m_timestamp, m_fon_rcd_id, m_fon_Leq, m_fon_LsMax, m_Leq_state, m_LsMax_state) \
                   VALUES(?, ?, ?, ?, ?, ?, ?)",
                   use(in_values.fon_id),
                   use(ts),
                   use(in_values.fon_rcd_id),
                   use(in_values.fon_Leq),
                   use(in_values.fon_LsMax),
                   use(in_values.Leq_state),
                   use(in_values.LsMax_state),
                   now;                     
  }

  ....
}


Where in_values maps table fields in this way:

Code: Select all

typedef struct _TDBFonValues {

  _TDBFonValues() : fon_id(0),
                    fon_rcd_id(0),
                    fon_Leq(0),
                    fon_LsMax(0),
                    Leq_state(0),
                    LsMax_state(0)
  {};

  Poco::Timestamp timestamp;
  UINT            fon_id;
  LONG            fon_rcd_id;
  FLOAT           fon_Leq;
  FLOAT           fon_LsMax;
  UINT            Leq_state;        /* stato del Leq : 0->OK, 1->FAIL*/
  UINT            LsMax_state;      /* stato del Leq : 0->OK, 1->FAIL*/
} TDBFonValues;


But when I run the query and I look into the database I found that the timestamp field is '0000-00-00 00:00:00' (despite that 'ts' variable contains a correct value (136210925718910970)) and the fon_rcd_id field is 26668048 (while it should be 1234).

Could someone give me some suggestion on what I'm wrong?

Thanks in advance.

Return to “Support”

Who is online

Users browsing this forum: No registered users and 1 guest

cron