John Siracusa writes:
 > On 8/14/07, George Hartzell <[EMAIL PROTECTED]> wrote:
 > > The default value of "now" does work when used in the RDBO perl
 > > module.  The problem is that since I'm using RDBO::Loader, the only
 > > way to get that value in there is to use it in the SQL, where it
 > > doesn't do what is intended.
 > 
 > Remember that the Loader also provides hooks to modify the metadata
 > pulled from the database, both before and after class initialization.
 > In this case, you could add a pre_init_hook that walks over all the
 > columns and replaces any default "current_datetime" values on datetime
 > columns with "now".
 > 
 > http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Loader.pm#pre_init_hook

I'll hold that in reserve, it seems like it's worth getting the
Rose::DB code to work with what SQLite uses (kinky as it may be).

 > > Can you give me a hint on setting up the inlining?  It looks like I'll
 > > need to change
 > > Rose::DB::Object::Metadata::Column::Timestamp::should_inline_value so
 > > that it checks (off the top of my head)
 > >
 > >   ($_[1]->driver eq 'sqlite' && $_[2] =~ /current_datetime/i)
 > >
 > > or something close to that.  I'll have to figure out how to work it
 > > into the existing ternary test.
 > 
 > You shouldn't need to modify should_inline_value().  Instead, add
 > "current_datetime" as a valid "keyword" for SQLite date/time columns.
 > To do this, alter the validate_*_keyword() method(s) in
 > Rose::DB::SQLite.  This fix will be in the next release, but I haven't
 > don't it yet.  If you do it first, feel free to post a patch :)

With a stock installation, using a default value of current_timestamp
in my sql causes an insert from perl to fail with

  Invalid default datetime: 'current_timestamp' at .....

So, I made the following change to Rose/DB/SQLite.pm (apeing the style
in Pg.pm)

--- /usr/local/lib/perl5/site_perl/5.8.8/Rose/DB/SQLite.pm.orig 2007-08-15 
13:11:11.000000000 -0700
+++ /usr/local/lib/perl5/site_perl/5.8.8/Rose/DB/SQLite.pm      2007-08-15 
13:08:22.000000000 -0700
@@ -56,7 +56,8 @@
 sub validate_datetime_keyword
 {
   no warnings;
-  !ref $_[1] && $_[1] =~ /^\w+\(.*\)$/ ;
+  !ref $_[1] && $_[1] =~ /^(?:current_timestamp|\w+\(.*\))$/ ;
+  #!ref $_[1] && $_[1] =~ /^\w+\(.*\)$/ ;
 }
 
and now the insert "succeeds", but the value that gets inserted is the
literal string "current_timestamp" (w/out the double-quotation-marks).

I commented on this ealier in the thread and you thought that the
value needed to be inlined, which is where I got started with that idea.

[I know that I'm being sloppy about timestamps and datetimes and such,
and need to remember what the portable sql thingy to use is.  I
*think* that's ortagonal to the problem I'm seeing...]

Suggestions?

g.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to