Function notation with mysql

L

Lars Eighner

I'd like to work in perl, but it appears the Mysql module has been eaten by
DBI so it will no longer recognize funtion notation. Is there any
procedural-type library for interfacing with Mysql?
 
J

Jim Cochrane

Why? Are you fraid your head will explode if you type "->" too many times?

sherm--

Maybe he has a repetitive motion syndrome, but only in finger number 4
(counting the thumb as finger # 1) of his right hand. :)

--
 
L

Lars Eighner

In our last episode,
the lovely and talented Sherm Pendley
broadcast on comp.lang.perl.misc:
Why? Are you fraid your head will explode if you type "->" too many times?

No, I am afraid of broken stuff that I cannot fix. Hey, like GUIs, objects
are fine if you want to do exactly what developers think you should want to
do exactly the way they think everyone should want to do them.
 
X

xhoster

Lars Eighner said:
In our last episode,
the lovely and talented Sherm Pendley
broadcast on comp.lang.perl.misc:



No, I am afraid of broken stuff that I cannot fix. Hey, like GUIs,
objects are fine if you want to do exactly what developers think you
should want to do exactly the way they think everyone should want to do
them.

You could always invoke the code thingies in subroutine form rather than
method form if that makes you happy, but I suspect you are just delight in
being unhappy.

Xho
 
L

Lars Eighner

I suppose this is true, but if you're simply generating queries, there
is only a small handful of methods you'll need to use (e.g., connect,
prepare, execute, fetch, do). Much of the rest of DBI is syntactic
sugar and convenience methods, which you can safely not use.

Well, I have rethought this, and decided that I can probably write the
functions I need using backtick calls to the mysql client. I did something
rather rash and actually read man mysql, discovering that if I don't call it
interactively, I don't have to try to parse the ASCII tables.
 
J

J. Gleixner

Lars Eighner wrote:
[...]
Well, I have rethought this, and decided that I can probably write the
functions I need using backtick calls to the mysql client. I did something
rather rash and actually read man mysql, discovering that if I don't call it
interactively, I don't have to try to parse the ASCII tables.

Yuck. Nothing is stopping you from going against the advice others
are giving, but there's no need to tell anyone that's what you're
doing. :)

DBI is pretty nice and there are a lot of tutorials and documentation
available to make using it, pretty painless.
 
L

Lars Eighner

That sounds really gruesome.

Perhaps, but I have been experimenting since I wrote the above, and I am
delighted. This makes so many things possible that I gave up on because I
couldn't fight my way through DBI. I rue the many hours I wasted at that.
The following pseudocode
@stuff=`mysql -e '$query'`;
foreach my $line (@stuff)
{
# process each returned line
}
is the moral equivalent of
$dbh=DBI::connect($dsn);
$sth=$dbh->prepare($query);
$sth->execute;
while ($row=$sth->fetch)
{
# process each row; $row is an arrayref
}

See what I mean? The direct version is simple, clean, easy to understand
and to edit. The objects are black boxes at the bottom of an opaque swamp:
there is no telling what they are doing or how.
except you avoid the shell, you avoid a connection per query, you can do
nice stuff with prepare and execute so that you can iterate a query over
a list (and also let execute automatically quote arguments appropriately
before submitting the query), and @$row is already parsed. If your
script is basically a one-off, backticks are fine, but anything larger
and backticks will become masochistic in a hurry.

Here's how I learned my lesson about objects:

I installed CGI::Kwiki. I thought it might be possible to customize it for a
project, although it was a horrible mess with javascript and all out of the
box. It said that it could be customized simply by writing replacement
modules and placing them in a local directory. Sounded good so far.

Well, the first thing I wanted to change was the DOCTYPE. I wanted to
change XHTML doctype to HTML. I grepped the distributed modules on XHTML,
locating all the doctype declarations in the distribution (all three
happened to be in template module). I rewrote the template module, put it
in the local lib and thought I was off to the races.

But no. Docs still came out as type XHTML. So I thought, well, maybe they
are rolling a doctype declaration out of parts. So I grepped on parts of
the XHTML doctype declaration, to see if I missed where the doctype really
was being generated. Nope. The doctype was not coming from anywhere in the
CGI::Kwiki distribution. Evidently it was coming from somewhere up the
dependencies. Where? After many hours I still do not know.
Somewhere, someone decided that I should want to use XHTML and that I was
not going to have a choice about it. And that is what OOP is all about:
preventing people from doing what they want to do.

When it become impossible to do anything in perl without objects, I'm
going back sed in Bourne scripts.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,674
Latest member
scazeho

Latest Threads

Top