You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Scott Chapman <sc...@mischko.com> on 2002/02/05 22:14:48 UTC

Recordset: How to make function convert data as it's selected.

Can Recordset be set up to do this?

I have a data file with timestamps stored as seconds since epoch.  I think 
!Filter might make it possible to convert the data to MM/DD/YYYY format.  
I'm not sure if it can be done or how to do it.

The !Filter looks like it will take regular expressions.  Can I use it or some 
other method with Recordset to process the results of the query on the fly?

TIA!
Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Recordset: How to make function convert data as it's selected.

Posted by Gerald Richter <ri...@ecos.de>.
> How to make function convert data as it's selected.
> Can Recordset be set up to do this?
>

Yes

> I have a data file with timestamps stored as seconds since epoch.  I think
> !Filter might make it possible to convert the data to MM/DD/YYYY format.
> I'm not sure if it can be done or how to do it.
>

!Filter is the correct thing to use:

$db = DBIx::Database -> new  ({ .... }) ;
$db -> TableAttr ('*', '!Filter',


        9   =>          [ \&date2sql,  \&sql2date ],
        11   =>          [ \&date2sql,  \&sql2date ],
    }) ;

date2sql and sql2date are two functions that take make the actual
conversion, maybe by using Date::Calc or whatever ou like. date2sql get the
ascii date as first parameter and schould return it as int so it can be
written into the database and sql2date does the thing the other way round.
By specify ing 9 and 11 this will be done for all date and datetime fields,
you can also give a field name instead. The * tells Recordset that it is for
all tables, instead you can give a table name here. You can also pass the
!Filter parameter when you setup your recordset object, but I prefer to set
it up once and forget about it for the rest of the programm

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


> The !Filter looks like it will take regular expressions.  Can I use it or
some
> other method with Recordset to process the results of the query on the
fly?
>
> TIA!
> Scott
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org