Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » Creating a TIMESTAMP column in MySQL
Creating a TIMESTAMP column in MySQL [message #32213] Sun, 01 May 2011 16:46 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Hi, all!

Is there any .sch file macro for CREATEing a column like
'`my_column_id` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP'
in a MySQL DB?

Is it what MySqlSchema.h macro TIMESTAMP(ts) does, i.e. creates a column that defaults to CURRENT_TIMESTAMP?

If so, could anyone give me an example on how to use it?

I've tried
TIME_ (MY_COLUMN_ID) TIMESTAMP("CURRENT_TIMESTAMP")
,
it compiled fine, but the resulting CREATE TABLE statement defaults column to NULL.

I've searched the documentation and this forum but couldnīt find anything.

Thank you all in advance!


Re: Creating a TIMESTAMP column in MySQL [message #32216 is a reply to message #32213] Sun, 01 May 2011 18:23 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I figured out myself one way on how to do it:

COLUMN_("TIMESTAMP", Time, MY_COLUMN_ID, 0, 0)


The following column results from the code above:
MY_COLUMN_ID timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP


Now, how do I get rid of the 'ON UPDATE CURRENT_TIMESTAMP' part?

Many thanks!
Re: Creating a TIMESTAMP column in MySQL [message #32220 is a reply to message #32216] Sun, 01 May 2011 20:08 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
Hello, I don't know, what that TIMESTAMP(ts) is for, but you can use something like
COLUMN  ("timestamp", Time, RECORD_CREATED, 0, 0) NOT_NULL SQLDEFAULT(CURRENT_TIMESTAMP)


BTW any idea fom anybody about that TIMESTAMP(ts) macro in MySqlSchema.h?
Re: Creating a TIMESTAMP column in MySQL [message #32222 is a reply to message #32220] Sun, 01 May 2011 22:00 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I've tried that, but it doesn't compile. Actually, a file search for SQLDEFAULT produces
C:\upp\uppsrc\Oracle\OracleSchema.h(51):#define SQLDEFAULT(v)              INLINE_ATTRIBUTE("default " v)
C:\upp\uppsrc\plugin\sqlite3\Sqlite3Schema.h(74):#define SQLDEFAULT(v)              INLINE_ATTRIBUTE("default " #v)
C:\upp\uppsrc\PostgreSQL\PostgreSQLSchema.h(71):#define SQLDEFAULT(v)              INLINE_ATTRIBUTE("default " #v)

, and there seems to be no definition for MySqlSchema.

I finally managed to get what I want by compiling
	COLUMN_("TIMESTAMP", Time, RECORD_CREATED, 0, 0) ATTRIBUTE("ALTER TABLE @t change column @c @c timestamp not null default current_timestamp;", ";")

, which yields
RECORD_CREATED timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

Now, what about that?

Thanks!

[Updated on: Sun, 01 May 2011 22:02]

Report message to a moderator

Re: Creating a TIMESTAMP column in MySQL [message #32224 is a reply to message #32222] Mon, 02 May 2011 09:03 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
#define SQLDEFAULT(v)   INLINE_ATTRIBUTE("default " #v)

Line is missing from MySqlSchema.h. It seems to be a bug.
Re: Creating a TIMESTAMP column in MySQL [message #32238 is a reply to message #32224] Mon, 02 May 2011 17:53 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Patch included in MySqlSchema.h as suggested, column successfuly created as wanted.

Thank you!
Re: Creating a TIMESTAMP column in MySQL [message #32264 is a reply to message #32238] Wed, 04 May 2011 20:01 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Patch applied. Thank you.
Previous Topic: MySqlSession::GetTransactionLevel() implementation
Next Topic: fetch not reading into struct
Goto Forum:
  


Current Time: Thu Mar 28 21:50:04 CET 2024

Total time taken to generate the page: 0.02236 seconds