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)
  • PostgreSQL and Customer Database
    ... I've been working on both SQL and Perl for a while now, ... get them all onto an SQL database, and be able to keep track of sales, as ... the database available to customers and potential customers, ...
    (perl.beginners)
  • Ways of ensuring integers in the database are seen as numbers in perl?
    ... I'd like my database returned integers to look like integers to Perl but they currently don't until I add 0 to them. ... The reason for this is that adding 0 to a Perl scalar seems to persuade Perl the scalar is an integer. ... $num as returned from database: ...
    (perl.dbi.users)
  • Re: How to access MS Access from Perl?
    ... if you were to later migrate to MS SQL Server or Oracle ... minimize your load on the database server's compiled procedure cache. ... On the other hand, if startup time for your perl script is an issue, and ... slightly preferable to the bulkier DBI + DBD::ODBC. ...
    (comp.lang.perl)
  • Re: LAMP - Program Design with Perl
    ... > information and queries the MySQL database. ... > Maybe there are Perl modules to faciliate this kind of task? ... so I think it worthwhile to second Anno's suggestion on this method (eg. ... Aside from the hint about dispatch tables, ...
    (comp.lang.perl.misc)