PHP Classes

Timestamp, Time Stamp, Time-stamp HOW?

Recommend this page to a friend!

      Metabase  >  All threads  >  Timestamp, Time Stamp, Time-stamp HOW?  >  (Un) Subscribe thread alerts  
Subject:Timestamp, Time Stamp, Time-stamp HOW?
Summary:How, in the XML schema, do I do Time Stamps?
Messages:7
Author:Shawn Koppenhoefer
Date:2014-12-29 17:59:53
 

  1. Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Shawn Koppenhoefer Shawn Koppenhoefer - 2014-12-29 17:59:53
Hello again,

I haven't succeeded in understanding how to add a Timestamp type to the database schema.
Have I missed the documentation for that?,.. and if so, where can I go read?


I have tried variations of this:
<field> <name>creation_timestamp</name><type>time stamp</type><default></default></field>

I have tried 'Timestamp', 'Time stamp', 'time stamp', 'timestamp' etc.
But everything I try to install the schema, I get the following message:

Error: Could not parse database schema file: It was not defined a valid field type property

I suppose I could give up, and just use the 'Date' type... but...
Can you help?

p.s. I had no problem with the "users" example in the documentation.
p.s. Here is my full entry where I try to use time stamps. :(

<table>
<name>news</name>
<declaration>
<field> <name>id</name> <autoincrement>1</autoincrement> </field>
<field> <name>creation_timestamp</name><type>time stamp</type><default></default></field>
<field> <name>news_date</name> <type>date</type> </field>
<field> <name>publication_date</name> <type>date</type> </field>
<field> <name>priority</name> <type>integer</type> </field>
<field> <name>author_id</name> <type>integer</type> </field>
<field> <name>title</name> <type>text</type> </field>
<field> <name>article_url</name> <type>text</type> </field>
<field> <name>image_url</name> <type>text</type> </field>
</declaration>
</table>

  2. Re: Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Shawn Koppenhoefer Shawn Koppenhoefer - 2014-12-29 18:13:09 - In reply to message 1 from Shawn Koppenhoefer
ok.. progresss.
By looking into your manager_database.php file I see that I should be using 'timestamp'.
(I had thought it was 'time stamp' because of the space you used in the documentation I was using from

So I tried that, but now I am getting this error message:

Error: Could not parse database schema file: field value is not a valid timestamp value


Here is my new schema piece:

<table>
<name>news</name>
<declaration>
<field> <name>id</name> <autoincrement>1</autoincrement> </field>

<field> <name>creation_timestamp</name><type>timestamp</type><default></default></field>

<field> <name>edit_timestamp</name><type>time stamp</type><default></default></field>
<field> <name>news_date</name> <type>date</type> </field>
<field> <name>publication_date</name> <type>date</type> </field>
<field> <name>priority</name> <type>integer</type> </field>
<field> <name>author_id</name> <type>integer</type> </field>
<field> <name>title</name> <type>text</type> </field>
<field> <name>article_url</name> <type>text</type> </field>
<field> <name>image_url</name> <type>text</type> </field>

</declaration>
</table>

  3. Re: Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-12-29 18:33:41 - In reply to message 2 from Shawn Koppenhoefer
Yes, that's because an empty string is not a valid timestamp for the default value. If you want the default to be NULL, just do not define the default. Otherwise, you need to specify a value in the ISO format YYYY-MM-DD HH:MM:SS .

  4. Re: Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Shawn Koppenhoefer Shawn Koppenhoefer - 2014-12-29 18:43:47 - In reply to message 3 from Manuel Lemos
fabulous!..

Is there a way to default to the current date time of the created record rather than null?

  5. Re: Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-12-29 19:22:13 - In reply to message 4 from Shawn Koppenhoefer
You can insert a variable to define the default values like this:

$variables=array(
"today"=>MetabaseNow(),
);
$manager=new metabase_manager_class;
$success=$manager->UpdateDatabase("schema.xml", "schema.xml.before", $arguments, $variables);

Then your field definition appears like this:

<field>
<name>creation_timestamp</name>
<type>timestamp</type>
<default><variable>today</variable></default>
</field>

  6. Re: Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Shawn Koppenhoefer Shawn Koppenhoefer - 2014-12-30 09:31:20 - In reply to message 5 from Manuel Lemos
Thanks!

but Arghhh. It didn’t work out as I expected.
The resulting mysql definition ended up with DEFAULT for my fields set to a *specific* datetime value (2014-12-30 10:22:45)(the datetime of the instant I reran the my updatedatabase.php script with that $manager->UpdateDatabase call. :(

But of course, I in mysql I can set the default to “CURRENT_TIMESTAMP” and that works fine, so this is not a problem (but would be nice to be able to set in the schema :)

  7. Re: Timestamp, Time Stamp, Time-stamp HOW?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2014-12-30 19:57:59 - In reply to message 6 from Shawn Koppenhoefer
Oh, sorry, I thought you wanted to set it to when the table is created.

Metabase does not support anything like CURRENT_TIMESTAMP because that is very MySQL specific.

Setting the value to the current time when you insert the record is not such a big deal in terms of code.

Metastorage is another project that works on top of Metabase. It generates classes for storing and retrieving database table records as objects.

It supports another XML format for defining the classes of objects to be mapped to database tables. Each field is defined as class variable.

Variables may have autocreate or autoupdate properties that you can set to make the generated classes set the variables to the current date and time of creation or updating of the fields.

You may find more about Metastorage here:

meta-language.net/metastorage.html

 
For more information send a message to info at phpclasses dot org.