Skip Menu |

This queue is for tickets about the Rose-DB-Object CPAN distribution.

Report information
The Basics
Id: 37224
Status: resolved
Priority: 0/
Queue: Rose-DB-Object

People
Owner: Nobody in particular
Requestors: riccardo [...] toutsimplementnous.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 0.7713



Subject: timestamp - sqlite problem
Hi, I cannot give a default value to a timestamp in a sqlite db using Rose::DB::Object. I have the following table: CREATE TABLE temperatures ( sample_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, temperature_value DECIMAL, ); the following object interface: __PACKAGE__->meta->setup ( table => 'temperatures', columns => [ sample_time => { type => 'timestamp', not_null => 1, default => 'CURRENT_TIMESTAMP' }, temperature_value => { type => 'decimal'}, ], primary_key_columns => [ 'sample_time' ], ); and this code: my $pTemperature = temperature->new(temperature_value => -273.15); $pTemperature->save(); but when I SELECT sample_time FROM temperatures, the value of the field is the string 'CURRENT_TIMESTAMP'. I've also tried with "default => 'now()'" and with "default => ''" without success.
From: riccardo [...] toutsimplementnous.org
Hi, I've found this in Rose::DB::Object::Tutorial, but I'm not sure to understand. The only thing I understand is that maybe it is not a bug. But, then, how to insert a timestamp using a default value? "In the case of "creation date" columns like this, it's usually better to let the database provide the value as close as possible to the very moment the row is created. On the other hand, this will mean that any newly created Product object will have a "strange" value for that column (the string "now()") until/unless it is loaded from the database. It's a trade-off."
This was a bug. It is fixed now in SVN. The fix will go out in the next release. When it does, you will still need to set allow_inline_column_values to true in your classes. You can do this in your setup() call: __PACKAGE__->meta->setup ( table => ... columns => ... allow_inline_column_values > 1, ); or by overriding this method in a custom metadata class, then setting your common base class to use it: package My::DB::Object::Metadata; use base 'Rose::DB::Object::Metadata; ... sub allow_inline_column_values { 1 } # always true ... package My::DB::Object; use base 'Rose::DB::Object'; ... use My::DB::Object::Metadata; sub meta_class { 'My::DB::Object::Metadata' } ... package Temperature; use base 'My::DB::Object'; ...
Subject: Re: [rt.cpan.org #37224] timestamp - sqlite problem
Date: Mon, 30 Jun 2008 14:31:12 +0200
To: bug-Rose-DB-Object [...] rt.cpan.org
From: Riccardo Casazza <riccardo [...] toutsimplementnous.org>
Thanks! On Mon, 2008-06-30 at 08:21 -0400, John Siracusa via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=37224 > > > This was a bug. It is fixed now in SVN. The fix will go out in the next release. When it does, > you will still need to set allow_inline_column_values to true in your classes. You can do this > in your setup() call: > > __PACKAGE__->meta->setup > ( > table => ... > columns => ... > allow_inline_column_values > 1, > ); > > or by overriding this method in a custom metadata class, then setting your common base > class to use it: > > package My::DB::Object::Metadata; > use base 'Rose::DB::Object::Metadata; > ... > sub allow_inline_column_values { 1 } # always true > ... > > package My::DB::Object; > use base 'Rose::DB::Object'; > ... > use My::DB::Object::Metadata; > sub meta_class { 'My::DB::Object::Metadata' } > ... > > package Temperature; > use base 'My::DB::Object'; > ...