Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

There's heaps of database abstraction modules in Perl but it seems that while abstraction always means "You don't have to deal with messy C interfaces", and sometimes "You can write SQL in Perl", it hardly ever means "we'll take care of data type idiosyncrasies for you". I need something like that.

My problem (briefly mentioned in my announcement of Ashafix) is this: I've used a couple of DBMS layers but all programs have been tied to one particular DBMS. Now I want to write one that runs unchanged on at least PostgreSQL and MySQL and my first problem is the handling of booleans. Pg uses an own type that returns 't' or 'f' while MySQL by convention uses TINYINT that is set to zero or non-zero. Currently I'm using DBIx::Simple and I'd prefer to keep it fairly slim. My ideas so far:

  • Define an ENUM in MySQL to emulate the Pg behavior. Doesn't work because other software is using the database too and would get very confused.
  • Use DBIx::Class, write my own InflateColumn::Bool and a primitive Bool class that uses a tied hash or something to give the usual zero-or-nonzero-scalar behavior when used in boolean context.
    Disadvantage: that's about as fat as it gets.
  • Subclass DBIx::Simple, feed it a simple column=>type mapping for each table I'll use and make all retrieval methods use a hash()/hashes() method internally so I can do the mapping myself.
    Disadvantage: smells inefficient (although it's probably still much faster than DBIx::Class), may be reinventing the wheel.

Have I by any chance overlooked something on CPAN that would let me do this in a simpler way?


In reply to Database abstraction including data types by mbethke

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (9)
    As of 2014-12-29 14:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (189 votes), past polls