Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Database abstraction including data types ( $dbh->{pg_bool_tf} )

by erix (Parson)
on May 20, 2012 at 19:49 UTC ( #971515=note: print w/replies, xml ) Need Help??

in reply to Database abstraction including data types

Hardly a complete answer, but handy for the particular true/false problem that you mention is, for the postgres side: $dbh->{pg_bool_tf}, which lets you choose between t/f or 1/0:

$ perl -Mstrict -MDBI -E 'my$dbh=DBI->connect("dbi:Pg:"); $dbh->{pg_bool_tf} = 0; # true false is now 1/0 print $dbh->selectall_arrayref("select 1=1")->[0]->[0], "\n"; $dbh->{pg_bool_tf} = 1; # true false is now t/f print $dbh->selectall_arrayref("select 1=1")->[0]->[0], "\n"; # ' output: 1 t

(See DBD::Pg $dbh attributes.)

  • Comment on Re: Database abstraction including data types ( $dbh->{pg_bool_tf} )
  • Download Code

Replies are listed 'Best First'.
Re^2: Database abstraction including data types
by Anonymous Monk on May 20, 2012 at 21:00 UTC

    Aternatively do it all in the database:

    SELECT CASE WHEN column_name THEN 1 ELSE 0 END AS column_name FROM table ...
      By the way, that whole app looks like a good candidate for SQLite which could simplify the configuration and management a bit.

        I'm not sure how many people actually use SQLite for their Postfix installation. Postfix supports it but Postfixadmin doesn't so I suppose there has been little demand. It would probably work with mostly the same SQL as MySQL except for the DDL. But given that I'd have to support the "big ones" too as that's what most people use, I don't quite see how it would simplify things?

Re^2: Database abstraction including data types
by mbethke (Hermit) on May 22, 2012 at 05:12 UTC

    Now that's cool, hadn't even thought that it could have been abstracted on such a low level. That may just be enough for this particular application unless I run into other incompatibilities, which looks unlikely. Thank you!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971515]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2018-06-24 04:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.