Gentoo Archives: gentoo-dev

From: Michael Cummings <mcummings@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] DBD-mysql select failures with MySQL 4.1
Date: Mon, 27 Jun 2005 11:45:40
Message-Id: 200506270740.37609.mcummings@gentoo.org
In Reply to: [gentoo-dev] DBD-mysql select failures with MySQL 4.1 by Anthony Gorecki
1 Take this to gentoo-perl@g.o (I'm just getting back from vacation, real
2 responses delayed until we finish getting everything back in order at the
3 house). First recommendation is of course, don't try to assign something to
4 $_ directly, but maybe that's just my personal take (I'd have used another
5 var, any other var).
6
7 On Sunday 26 June 2005 23:55, Anthony Gorecki wrote:
8 > Hello,
9 >
10 > I've been encountering an unusual string of errors while attempting to
11 > retrieve information from a database using DBD-mysql-2.9007 and
12 > mysql-4.1.12. The database in question is of type InnoDB. Below is an
13 > example:
14 >
15 > #!/usr/bin/perl -w
16 >
17 > use strict;
18 > use DBI;
19 >
20 > my $db_conn = DBI->connect('DBI:mysql:infrastructure', 'system',
21 > 'readonly'); if (!$db_conn) {
22 > error('The program was unable to connect to the database.');
23 > }
24 >
25 > $_ = $db_conn->selectrow_array("
26 > SELECT \@user_id := (
27 > SELECT user_id FROM users WHERE username = 'agorecki' LIMIT 1)
28 > );
29 > ");
30 >
31 > if (!defined($_)) {
32 > $db_conn->disconnect();
33 > error('It appears that the user account has disappeared since login '.
34 > 'time...'
35 > );
36 > }
37 >
38 >
39 > The same query in MySQL will return the session variable, however DBD-mysql
40 > returns undefined. Similarly, when I run:
41 >
42 > SELECT type
43 > FROM svn_access
44 > WHERE 'test' REGEXP REPLACE(path_regex, '\$USERNAME\$', 'agorecki') = 1
45 > AND (user_id = @user_id
46 > OR group_id = ANY (SELECT group_id FROM group_memberships WHERE
47 > user_id = @user_id)
48 > OR (user_id IS NULL AND group_id IS NULL)
49 > )
50 > ORDER BY type DESC LIMIT 1;
51 >
52 >
53 > through selectrow_array (properly encoded for use in a PERL script), I also
54 > receive an undefined result. The above query correctly returns one row when
55 > input into a MySQL console and executed.
56 >
57 > The only thing that actually managed to execute and return a value
58 > successfully was:
59 > $_ = $db_conn->selectrow_array("SELECT 'hello';");
60 >
61 > Any thoughts?
62
63 --
64 -----o()o---------------------------------------------
65 Michael Cummings | #gentoo-dev, #gentoo-perl
66 Gentoo Perl Dev | on irc.freenode.net
67 -----o()o---------------------------------------------