carpediem has asked for the wisdom of the Perl Monks concerning the following question:

Greetings-

I'm hoping that someone else has run into this issue before. The trouble I am having is that I am getting the following error for my Update statement:

#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"UPDATE my_table SET MY_COLUMN = '' WHERE MY_OTHER_COLUMN = 'my_value'"' at line 1 at mysql_connect.pl line 24.

I have verified that the same statement executes successfully using the MySQL CLI, so I'm not sure what syntax Perl is finding objectionable...


My setup is as follows:

* I am running Perl(ActivePerl-5.10.0.1003-MSWin32-x86-285500) and the MySQL(5.0.51b) DB on Windows XP

* I am using the http://search.cpan.org/dist/Net-MySQL-0.09 module

And now the code (you will note the Select statement that comes prior to the Update statement, which is not throwing any errors):

my $mysql = Net::MySQL->new( hostname => 'localhost', database => 'my_DB', user => 'root', password => 'my_password' ); $mysql->query(q{"SELECT * FROM my_table WHERE MY_OTHER_COLUMN LIKE 'my +_value'"}); $mysql->query(q{"UPDATE my_table SET MY_COLUMN = '' WHERE MY_OTHER_COL +UMN = 'my_value'"}); die $mysql->get_error_message if $mysql->is_error;
Thanks for any help you can provide, and please let me know if I have forgotten to include anything relevant.

Replies are listed 'Best First'.
Re: MySQL "Update" statement is failing with syntax error
by JavaFan (Canon) on Aug 27, 2008 at 20:56 UTC
    You are quoting your strings twice. You use both q{} and "". So the command that's being send is
    "UPDATE my_table SET MY_COLUMN = '' WHERE MY_OTHER_COLMN = 'my_val +ue'"
    including your quotes.

    I'm a bit amazed it doesn't complain about the SELECT, where you make the same error.

      It's easy: AFAICS he didn't check the result of SELECT...

      Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re: MySQL "Update" statement is failing with syntax error
by apl (Monsignor) on Aug 28, 2008 at 12:05 UTC
    When in trouble or in doubt,
    Print your parameters out.