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

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...

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

Replies are listed 'Best First'.
Re^3: SQL Query error while executing in perl. Is it possible to execute these Scripts??
by NetWallah (Canon) on Dec 06, 2010 at 06:23 UTC
    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". ;-)
        Wrong. Most SQL engines require single quotes for values, and double quotes for otherwise illegal identifiers.

        The "Wrong" bit is debatable Alexander as I believe the node you replied to was attempting to comment on the inclusion of @something in the same SQL which included $tim. I read the node as you could use single quotes around the SQL string to avoid @something being interpreted by Perl as an array but since you also include $tim you need to use double-quotes (around the SQL) and escape the @something.

        However, other than that I agree with most of your points and advice except to point out a slight snag with the quote_identifier. Most databases have some rather nasty rules about quoted and unquoted identifiers like some uppercase unquoted identifiers, some lowercase them and some keep the case. Once you use quoted_identifier in many databases you have to get the case exactly right. Some also require table/column names the same as reserved words to be quoted. All I'm really saying is it is not clear cut whether to use quote_identifier always.

        While I disagree with your evaluation of the information as "wrong", I accept the point that SQL usually requires single-quoted literals, and placeholders are good.

        Until O.P has comments otherwise, I presume the issue is resolved, and we can avoid unnecessary debate and contention. I understand what you meant, and agree with your recommendation. My disagreement with your evaluation is irrelevant and non-productive, but it is there for the record. "Wrong" unfortunately has an accusatory quality, and invokes an emotional response. May I gently suggest that when you express disagreement, to please consider using something less potentially inflammatory , unless , of course, the issue is blatant or egregiously misrepresented.

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