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