in reply to SQL Query error while executing in perl. Is it possible to execute these Scripts??

Expanding on what Corion said : "@" sigils signify arrays, and double quoted (") strings are interpolated.

One way to resolve the issue would be to use single quotes (') when setting $sql. Another way is to escape (\) the "@"s.

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

  • Comment on Re: SQL Query error while executing in perl. Is it possible to execute these Scripts??

Replies are listed 'Best First'.
Re^2: SQL Query error while executing in perl. Is it possible to execute these Scripts??
by Sachin_dada (Initiate) on Dec 03, 2010 at 01:54 UTC

    Thanks for ur reply.. I'm not clear with what Corion said.. But as u said, the ineterpolated strings could be the problem... May be i'll try to execute with Single quotes.. But could u please tell, whether i can use the Perl variable in the SQL Scripts, as to extract the values from DB.. Like i used in above SQL Query...

      YES - indeed - that is what makes using perl with Databases so powerful.

      Your line needs to change to:

      my $sql = "DECLARE \@log varchar(5) SET \@log=$tim Update dbo.tltime s +et logtime = \@log";
      Notice that the "@" signs need to be escaped - because "@log" is intended for the SQL server, not perl. perl needs to be told to ignore the @, which you do by expressing it as "\@".

      On the other hand, you wan to tell SQL the value contained in the perl "$tim" variable, so you require perl's interpolation for THAT variable, so , use double-quotes.

           Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

        you wan to tell SQL the value contained in the perl "$tim" variable, so you require perl's interpolation for THAT variable, so , use double-quotes.

        Wrong. Most SQL engines require single quotes for values, and double quotes for otherwise illegal identifiers.

        But don't use single-quotes, either. Use placeholders and only placeholders for any value passed to the database. Forget that quote exists at all. That method should be restricted to DBDs.

        Use quote_identifier when you need to pass variable identifiers (most times, names of database objects like tables, views, columns, triggers, sequences, procedures) to the database.

        Update: Sorry, I wrote nonsense.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)