Procedural interface to mysql

Discussion in 'Perl Misc' started by Lars Eighner, Oct 19, 2008.

  1. Lars Eighner

    Lars Eighner Guest

    Is there a procedural interface to mysql?


    --
    Lars Eighner <http://larseighner.com/>
    Q. What did Palin do that Obama could not do?
    A. Got me to vote for Obama.
    Lars Eighner, Oct 19, 2008
    #1
    1. Advertising

  2. On 2008-10-19 03:07, Lars Eighner <> wrote:
    > Is there a procedural interface to mysql?


    What do you mean by "procedural interface"? I assume you know about DBI.
    What would a "procedural interface" give you that DBI doesn't?

    hp
    Peter J. Holzer, Oct 19, 2008
    #2
    1. Advertising

  3. Lars Eighner

    Lars Eighner Guest

    In our last episode,
    <>,
    the lovely and talented Peter J. Holzer
    broadcast on comp.lang.perl.misc:

    > On 2008-10-19 03:07, Lars Eighner <> wrote:
    >> Is there a procedural interface to mysql?


    > What do you mean by "procedural interface"? I assume you know about DBI.


    Yes.

    > What would a "procedural interface" give you that DBI doesn't?


    No objects. So it would be faster, simpler, more intuitive, more easily
    made to do what I want to do instead of what someone thinks I ought to want
    to do.

    --
    Lars Eighner <http://larseighner.com/>
    Q. What did Palin do that Obama could not do?
    A. Got me to vote for Obama.
    Lars Eighner, Oct 19, 2008
    #3
  4. Lars Eighner

    smallpond Guest

    On Oct 19, 9:56 am, Lars Eighner <> wrote:
    > In our last episode,
    > <>,
    > the lovely and talented Peter J. Holzer
    > broadcast on comp.lang.perl.misc:
    >
    > > On 2008-10-19 03:07, Lars Eighner <> wrote:
    > >> Is there a procedural interface to mysql?

    > > What do you mean by "procedural interface"? I assume you know about DBI.

    >
    > Yes.
    >
    > > What would a "procedural interface" give you that DBI doesn't?

    >
    > No objects. So it would be faster, simpler, more intuitive, more easily
    > made to do what I want to do instead of what someone thinks I ought to want
    > to do.
    >
    > --
    > Lars Eighner <http://larseighner.com/>
    > Q. What did Palin do that Obama could not do?
    > A. Got me to vote for Obama.




    A method call in perl is a procedural call where the first
    argument is passed using strange syntax. The call in
    your code:

    $dbh = $dsn->connect($user, $password);

    is a shorthand way of doing:

    $dbh = DBD::mysql::connect($dsn, $user, $password);

    The advantage of OO is that $dsn knows what package it
    is in, so the checking is done for you. Think of it
    that way and it will seem more natural.

    --S
    smallpond, Oct 19, 2008
    #4
  5. Lars Eighner

    Tim Greer Guest

    Lars Eighner wrote:

    >
    >> What would a "procedural interface" give you that DBI doesn't?

    >
    > No objects. So it would be faster, simpler, more intuitive, more
    > easily made to do what I want to do instead of what someone thinks I
    > ought to want to do.
    >


    Honestly, that would be such a negligible amount of overhead, and it's
    pretty intuitive already. If you're worried about speed, you should
    consider converting to C and compiling.
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
    Tim Greer, Oct 19, 2008
    #5
  6. Lars Eighner

    Lars Eighner Guest

    In our last episode, <ZeKKk.8085$>, the lovely and
    talented Tim Greer broadcast on comp.lang.perl.misc:

    > Lars Eighner wrote:


    >>
    >>> What would a "procedural interface" give you that DBI doesn't?

    >>
    >> No objects. So it would be faster, simpler, more intuitive, more
    >> easily made to do what I want to do instead of what someone thinks I
    >> ought to want to do.
    >>


    > Honestly, that would be such a negligible amount of overhead, and it's
    > pretty intuitive already. If you're worried about speed, you should
    > consider converting to C and compiling.


    I'm gathering, then, that I will have to write my own, because all
    database acess in perl is through the OO DBI.

    --
    Lars Eighner <http://larseighner.com/>
    Q. What did Palin do that Obama could not do?
    A. Got me to vote for Obama.
    Lars Eighner, Oct 19, 2008
    #6
  7. Lars Eighner

    Tim Greer Guest

    Lars Eighner wrote:

    > In our last episode, <ZeKKk.8085$>, the lovely
    > and talented Tim Greer broadcast on comp.lang.perl.misc:
    >
    >> Lars Eighner wrote:

    >
    >>>
    >>>> What would a "procedural interface" give you that DBI doesn't?
    >>>
    >>> No objects. So it would be faster, simpler, more intuitive, more
    >>> easily made to do what I want to do instead of what someone thinks I
    >>> ought to want to do.
    >>>

    >
    >> Honestly, that would be such a negligible amount of overhead, and
    >> it's
    >> pretty intuitive already. If you're worried about speed, you should
    >> consider converting to C and compiling.

    >
    > I'm gathering, then, that I will have to write my own, because all
    > database acess in perl is through the OO DBI.
    >


    It wouldn't be difficult to write your own without going the OO route.
    I just really don't think it's going to have any impact on the speed
    (not enough to matter). The current modules that do use OO are very
    mature, stable, and do a great deal of things that are big time savers.
    However, again. if you want to write your own code, by all means, go
    for it.
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
    Tim Greer, Oct 19, 2008
    #7
  8. On 2008-10-19 18:40, Lars Eighner <> wrote:
    > In our last episode, <ZeKKk.8085$>, the lovely and
    > talented Tim Greer broadcast on comp.lang.perl.misc:
    >> Lars Eighner wrote:
    >>>> What would a "procedural interface" give you that DBI doesn't?
    >>>
    >>> No objects. So it would be faster, simpler, more intuitive, more
    >>> easily made to do what I want to do instead of what someone thinks I
    >>> ought to want to do.
    >>>

    >
    >> Honestly, that would be such a negligible amount of overhead, and it's
    >> pretty intuitive already. If you're worried about speed, you should
    >> consider converting to C and compiling.

    >
    > I'm gathering, then, that I will have to write my own, because all
    > database acess in perl is through the OO DBI.


    Back in the perl 4 days, there used to be Oraperl, a procedural (because
    perl didn't do OO yet) interface to Oracle. As an interface it still
    exists, but these days it just uses DBI in the background. So it won't
    be any faster, and it doesn't look simpler to me (well it does, but
    that's because it does a lot less - the functionality that Oraperl
    provides is just as simple in DBI).

    hp
    Peter J. Holzer, Oct 19, 2008
    #8
  9. Lars Eighner

    Todd Wade Guest

    On Oct 19, 2:40 pm, Lars Eighner <> wrote:
    > In our last episode, <ZeKKk.8085$>, the lovely and
    > talented Tim Greer broadcast on comp.lang.perl.misc:
    >
    > > Lars Eighner wrote:

    >
    > >>> What would a "procedural interface" give you that DBI doesn't?

    >
    > >> No objects. So it would be faster, simpler, more intuitive, more
    > >> easily made to do what I want to do instead of what someone thinks I
    > >> ought to want to do.

    >
    > > Honestly, that would be such a negligible amount of overhead, and it's
    > > pretty intuitive already. If you're worried about speed, you should
    > > consider converting to C and compiling.

    >
    > I'm gathering, then, that I will have to write my own, because all
    > database acess in perl is through the OO DBI.


    Perhaps show us sample syntax that is going to be "faster, simpler,
    more intuitive, and [other things the DBI does that you dont think it
    does]?

    Todd W.
    Todd Wade, Oct 19, 2008
    #9
  10. Lars Eighner

    Guest

    "Peter J. Holzer" <> wrote:
    > On 2008-10-19 18:40, Lars Eighner <> wrote:
    > > In our last episode, <ZeKKk.8085$>, the lovely and
    > > talented Tim Greer broadcast on comp.lang.perl.misc:
    > >> Lars Eighner wrote:
    > >>>> What would a "procedural interface" give you that DBI doesn't?
    > >>>
    > >>> No objects. So it would be faster, simpler, more intuitive, more
    > >>> easily made to do what I want to do instead of what someone thinks I
    > >>> ought to want to do.
    > >>>

    > >
    > >> Honestly, that would be such a negligible amount of overhead, and it's
    > >> pretty intuitive already. If you're worried about speed, you should
    > >> consider converting to C and compiling.

    > >
    > > I'm gathering, then, that I will have to write my own, because all
    > > database acess in perl is through the OO DBI.


    You could always figure out what the magic package names are and make the
    calls procedurally:

    $h = get_connection_without_disclosing_password();
    print $h;
    print $h->selectrow_array("select count(*) from foodata");
    print DBI::db::selectrow_array($h,"select count(*) from foodata");
    __END__
    DBI::db=HASH(0x981a80)
    228139983
    228139983

    You could even make your own wrappers to remember the package names for
    you.


    > Back in the perl 4 days, there used to be Oraperl, a procedural (because
    > perl didn't do OO yet) interface to Oracle. As an interface it still
    > exists, but these days it just uses DBI in the background. So it won't
    > be any faster, and it doesn't look simpler to me (well it does, but
    > that's because it does a lot less - the functionality that Oraperl
    > provides is just as simple in DBI).


    Sure, but you don't have an irrational hatred of OO like our friend does.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , Oct 19, 2008
    #10
  11. On 2008-10-19, Lars Eighner <> wrote:
    > In our last episode,
    ><>, the lovely and talented
    >Peter J. Holzer broadcast on comp.lang.perl.misc:

    *SKIP*
    >> What would a "procedural interface" give you that DBI doesn't?

    > No objects. So it would be faster, simpler, more intuitive, more
    > easily made to do what I want to do instead of what someone thinks I
    > ought to want to do.


    Consider this -- Perl's "objects" aren't actually objects in OO sense,
    they are "blessed references". Inheritance, methods, constructors etc
    are no more than side-effect of blessing *anything* into *package* (not
    a class actually).

    As soon as you must keep state, you either bless or push responcibility
    of knowing what that particular data structure is onto user. In your
    case, you must keep state -- you'll end up with hash, I think. And here
    either your user must track what that unblessed hash is or Perl will do
    that for them.

    Next. Don't say that you don't know that these statements are pretty
    same: C<$hashref->method($arg);> vs C<method $hashref, $arg;>. The
    difference is that in second case there's place for lots of burden.

    Next. B<DBI> isn't OO. I see aggregation; I see methods; I don't see
    inheritance. Would you like to point at any class that actually
    inherits from B<DBI> (OK, I didn't verified that, so I can be
    incompetent, as ever)?

    And you must know that B<DBI> isn't pure Perl. I think, that any
    implementation of the same functionality in pure Perl would be slower.
    What functionality would you like to sacrifice for purity? XS on some
    API (libmysqlclient in your case)? What you gain in that case? Speed?
    Of what? How much time you're going to spend till you'll get working
    implementation?

    OK. That can be a challenge. I like challenges, they are good cause to
    make world better. And I really would like to hear your success story.
    But don't complain that you're the only user.

    --
    Torvalds' goal for Linux is very simple: World Domination
    Eric Pozharski, Oct 19, 2008
    #11
  12. Lars Eighner

    John Bokma Guest

    Eric Pozharski <> wrote:

    > Would you like to point at any class that actually
    > inherits from B<DBI>


    *points at a class I've written for a customer*

    Oh, and I found one for you that's on CPAN:
    <http://search.cpan.org/src/TIMB/DBI-1.607/lib/DBI/ProxyServer.pm>


    -> @ISA = qw(RPC::plServer DBI);


    --
    John http://johnbokma.com/ - Hacking & Hiking in Mexico

    Perl help in exchange for a gift:
    http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
    John Bokma, Oct 20, 2008
    #12
  13. >>>>> "LE" == Lars Eighner <> writes:

    LE> <>, the lovely and
    LE> talented Peter J. Holzer broadcast on comp.lang.perl.misc:

    >> What would a "procedural interface" give you that DBI doesn't?


    LE> No objects. So it would be faster, simpler, more intuitive,
    LE> more easily made to do what I want to do instead of what someone
    LE> thinks I ought to want to do.

    "Faster" and "simpler" are highly unlikely to both be accomplished at
    once. It's a function call either way; you have the overhead of
    additional method resolution, but you are spared the morass of PHP-style
    mysql_ functions.

    "More intuitive" and "more easily made to do what I want to do..." are a
    result of your viewpoint rather than anything inherent in object
    orientation.

    Frankly, you could fairly trivially put a wrapper around DBI calls so that

    $sth->prepare (....)

    turned into

    dbi_prepare ($sth, ....)

    but you'd gain nothing except avoiding the visible use of objects, and
    the code behind the wrapper would be exactly the same. Would this be
    faster, simpler, more intuitive, and easier for you to work with, simply
    because you don't *see* that there are objects involved?

    If so, the problem is with you, not with objects.

    Charlton



    --
    Charlton Wilbur
    Charlton Wilbur, Oct 20, 2008
    #13
  14. On 2008-10-20, John Bokma <> wrote:
    > Eric Pozharski <> wrote:
    >> Would you like to point at any class that actually inherits from
    >> B<DBI>

    > *points at a class I've written for a customer* Oh, and I found one
    > for you that's on CPAN:
    ><http://search.cpan.org/src/TIMB/DBI-1.607/lib/DBI/ProxyServer.pm> ->
    >@ISA = qw(RPC::plServer DBI);


    Oh, that hurts. No-one is more lazy than me.

    --
    Torvalds' goal for Linux is very simple: World Domination
    Eric Pozharski, Oct 20, 2008
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. parley
    Replies:
    13
    Views:
    743
    jim corey
    Feb 11, 2004
  2. John Gabriele

    help: good sturdy C procedural program design

    John Gabriele, Apr 24, 2004, in forum: C Programming
    Replies:
    2
    Views:
    486
    John Gabriele
    Apr 24, 2004
  3. Manuel

    OOP vs procedural

    Manuel, Jan 3, 2006, in forum: C++
    Replies:
    16
    Views:
    794
    James
    Jan 8, 2006
  4. Mohitz
    Replies:
    4
    Views:
    454
    Jim Langston
    Jul 12, 2007
  5. tenxian
    Replies:
    10
    Views:
    2,665
    Mark Space
    Apr 25, 2008
Loading...

Share This Page