DBI prepare and fetch

S

soup_or_power

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
 
K

Keith Keller

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
 
X

xhoster

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
 
S

soup_or_power

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.
 
X

xhoster

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
 

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
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top