RE: Possible Problem with bind_param



Here's a guess, as I'm not familiar with your particular Database and DBD.

It looks like the DBD is treating your value as in integer. Perhaps the DBD looks at the first part of the string, and thinks, "here's a number, so I'll pass an integer type to the database engine".

Suggestion: try adding a type attribute to the the bind_param call, forcing the value to treated as a CHAR type.

-----Original Message-----
From: David Wu [mailto:davidw@xxxxxxxxxxxxxx]
Sent: Friday, November 10, 2006 4:34 PM
To: dbi-users@xxxxxxxx
Subject: Possible Problem with bind_param


Hi all,

I came across some funny behavior in Perl with the DBI package, and I
don't know how to explain it or why it is happening. I've tried
googling it, but haven't found anything yet. Here is the scenario:

I have some code that automatically tries to update a user's email
address if it has changed when they come through using an
integration. However, it seems that although there was no error with
the database, the update does not go through. Here is the code for
reference:

my $sql = "UPDATE m_user SET email = ?, first_name = ?,
last_name = ? WHERE id = ?;";
my $sth = $dbh->prepare($sql);
$sth->bind_param(1, $get_vars->{new_email});
$sth->bind_param(2, $get_vars->{userfirstname});
$sth->bind_param(3, $get_vars->{userlastname});
$sth->bind_param(4, $api_user_id);
$sth->execute;
$sth->finish;

So, as an example, say somehow the value of the previous email
address for this one user was "341". I print out the value of
"$get_vars->{new_email}" before and after the SQL statement, and the
value is what I expect it to be, something like
"341_43392s@xxxxxxxxxxxxx". There are no errors and I hit the "$dbh-
commit" line. But if I run the query to retrieve the email of that
same user, the email hasn't changed. Also, Rich helped me to tail
the database logs so that I could see the query as it was being
executed, and I saw that it has truncated the value for the email,
looking something like this: "UPDATE m_user SET email = 341,
first_name = ...".

So this leads me to believe that there is something in the Perl that
is causing the value to be truncated, something to do with bind_param
or something like that. I think it doesn't like the underscore
character, or something. What I don't understand is that other
values have been working, like "_12312451_1_36644s@xxxxxxxxx" or
"lkj92mf0v2lkjd0f2_39443s@xxxxxxxxxxxx", but the moodle ones doesn't
work. However, I haven't been able to find any explanation or fix.

I've also tried reforming the query like "UPDATE m_user set email =
'" . $get->vars->{new_email} ."', first_name = '" . $get->vars->
{userfirstname} . "', last_name = '" . $get_vars->{userlastname} . '"
WHERE id = " . $api_user_id . "';";, but it wouldn't execute correctly.

I can correctly update the email directly in the database and in a
perl command line script that uses the same format of the code as
what I included above, but it won't work within the application.

I was wondering if anyone else ever encountered anything like this or
new of a solution? I'm using Perl 5.8.7 and DBI 1.52 and PostgreSQL
8.1.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.3.5 (Debian
1:3.3.5-13) as the database.

Thanks,

Dave
davidw@xxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Count of number of rows returned in delete / update sql in Perl DBI ?
    ... I also referred to the CPAN page before posting this query. ... It's already working for me with Oracle 10g on Perl 5.8.4 on RHEL. ... Amit Saxena wrote: ... I suggest that you simply test to make sure that it works on your database. ...
    (perl.beginners)
  • Possible Problem with bind_param
    ... I came across some funny behavior in Perl with the DBI package, and I don't know how to explain it or why it is happening. ... However, it seems that although there was no error with the database, the update does not go through. ... But if I run the query to retrieve the email of that same user, ... So this leads me to believe that there is something in the Perl that is causing the value to be truncated, something to do with bind_param or something like that. ...
    (perl.dbi.users)
  • Re: design strategy on handling large DB
    ... considered a mid-size database by most people). ... E> mysql, it uses up all the 2GB memory... ... But in perl, I don't know whether I can put the DB flat ... E> file into some data structures in advance, so users can query the DB ...
    (comp.lang.perl.misc)
  • CLOB Oracle 9i select issue
    ... I am having the darnedest problem with selecting clobs from our Oracle ... Database connection seems to be established for quickclob.pl: ... ORA-06512: at line 8 (DBD: oexec error) at ...
    (perl.dbi.users)
  • Re: Bug in DBD::Pg 1.32 with bytea columns
    ... the DBI or DBD know which method to use for a column? ... In theory, the DBD could, when it is asking the database to parse ... Sam Vilain, sam /\T vilain |>T net, PGP key ID: ... (include my PGP key ID in personal replies to avoid spam filtering) ...
    (perl.dbi.users)