For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > August 2005 > DBI prepare and fetch









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DBI prepare and fetch
soup_or_power@yahoo.com

2005-08-30, 6:58 pm

Hi
What does DBI's prepare do? Will it flag any errors? Also what does
fetch do. I tried "perldoc DBI" but couldn't find the answers there.

Thanks for your help

A. Sinan Unur

2005-08-30, 6:58 pm

soup_or_power@yahoo.com wrote in news:1125434381.413058.242940@g14g2000cwa.googlegroups.com:

> Hi
> What does DBI's prepare do? Will it flag any errors?


<URL:http://search.cpan.org/~timb/DBI-1.48/DBI.pm#prepare>

> Also what does fetch do.


<URL:http://search.cpan.org/~timb/DBI-1...._Handle_Methods>

Read about the fetch_* methods.

> I tried "perldoc DBI" but couldn't find the answers there.


You'll have to explain exactly what information is missing from
the docs above for us to be able to help you.

Sinan

--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/c...guidelines.html
Keith Keller

2005-08-30, 6:58 pm

On 2005-08-30, soup_or_power@yahoo.com <soup_or_power@yahoo.com> wrote:
> What does DBI's prepare do? Will it flag any errors? Also what does
> fetch do. I tried "perldoc DBI" but couldn't find the answers there.


What part of perldoc DBI was unclear to you? prepare prepares the
statement, passing it to the RDBMS if it supports prepared statements.
fetch is an alias for fetchrow_arrayref (this is also in perldoc DBI,
but it's not absolutely clear where to find it; look for
fetchrow_arrayref and you'll see the place).

--keith

--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information

xhoster@gmail.com

2005-08-30, 6:58 pm

soup_or_power@yahoo.com wrote:
> Hi
> What does DBI's prepare do?


At a high level? It prepares your statement. At a low level?
Whatever DBD makes it do.

> Will it flag any errors?


That depends. In Oracle, it will flag some errors. In Mysql,
I don't think it will even do that.

> Also what does
> fetch do. I tried "perldoc DBI" but couldn't find the answers there.


Fetch is an alias for fetchrow_arrayref. As I just discovered, this fact
is surprisingly very poorly documented in DBI.

"fetchrow_arrayref"
$ary_ref = $sth->fetchrow_arrayref;
$ary_ref = $sth->fetch; # alias

That appears to be it. There should be an entry that says:
"fetch"
An alias for fetchrow_arrayref.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
soup_or_power@yahoo.com

2005-08-31, 6:57 pm

Many thanks for your replies. I think the reason for prepare is the
statement handle on return so it can be passed adcross with subroutine
calls. Passing a statement handle is less memory intensive than passing
the SQL around. Please correct me if I am wrong.

xhoster@gmail.com

2005-08-31, 6:57 pm

soup_or_power@yahoo.com wrote:
> Many thanks for your replies. I think the reason for prepare is the
> statement handle on return so it can be passed adcross with subroutine
> calls. Passing a statement handle is less memory intensive than passing
> the SQL around. Please correct me if I am wrong.


You are wrong. A statement handle is a fundamental part of the DBI
abtraction, regardless of whether this makes passing them to subroutines
more memory efficient or not. How do you call execute one a statement
handle which does not exist? How do you bind parameters to a statemnet
handle which does not exist? How do you bind columns to a statement handle
that does not exist? How do you avoid excessive soft parses (in Oracle,
and I presume other databases) without statement handles? How do you fetch
rows one at a time without statement handles? (Well, I guess you could
make a result_set handle instead of a statement handle for that last one.)


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com