Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue inserting timestamp value in MySQL
    text
    copied!<p>There are some other questions where people have problems with timestamp being all zeros. I have checked them and this is not a duplicate.</p> <p>I declare a table like this:</p> <pre><code>CREATE TABLE `my_db`.`my_table` ( `time_stamp` timestamp NOT NULL, `author` varchar() NOT NULL, `text` text NOT NULL, `md5` int(11) NOT NULL, PRIMARY KEY (`time_stamp`) ) ; </code></pre> <p>I also have a second table which will have a timestamp as primary key and they should have the same value.</p> <p>Coding in Delphi, I use <code>SELECT CURRENT_TIMESTAMP</code> which returns something like <code>'19/6/2010 4:56:17 AM'</code> which I then use in an INSERT statement. The INSERT succeeds, but the timestamp is all zeros.</p> <p>What am I doing wrong?</p> <p>Here's the INSERT code:</p> <pre><code> sqlCommand := 'INSERT INTO my_db.my_table(time_stamp, author, text, md5) VALUES ("' + timestamp + '", "mawg", ' + '"Hello, world"' + 0 + '");'; Result := DoSQlCommandWithNoResultSet(sqlCommand, AdoConnection); </code></pre> <p>Insertion will be extremely low rate, one entry every few weeks or maybe months, so I am happy with timestamp as primary key. I am keeping "versions" of things, so timestamp makes sense to me.</p> <p>I am begging to think that this is an ADO problem, although I would expect ADO to just "pass through". I don't see any other solution. In a console, the output is "correct", but when run through ADO in Delphi then it is wrong </p> <p>Can I specify to MySQL how it ought to format its dates?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload