Re: insert into statement problem

From: Ravi Kongara (Ravi.Kongara_at_Sun.COM)
Date: 07/30/04


Date: Fri, 30 Jul 2004 10:56:11 -0700
To: "Helck, Timothy" <Timothy.Helck@bowker.com>

You can even avoid writing extra four lines of code ( ..foreach loop.. )
with this line.

$statement->execute(@sbval);

This also takes care of numeric fields, if database is smart enough to
convert internally ( Oracle does ).

Ravi

Helck, Timothy wrote:

>You can get single quotes around your values with this line:
>my $temval = "('".join("','",@sbval )."')";
>
>However, Mark's solution is much better, especially if your list of values includes a number.
>
>-----Original Message-----
>From: Nettlingham, Mark [mailto:Mark.Nettlingham@logicacmg.com]
>Sent: Friday, July 30, 2004 5:10 AM
>To: 'kaustubh shinde'; dbi-users@perl.org
>Subject: RE: insert into statement problem
>
>
>In order to get quoting to work, your best bet is to use placeholders, which
>are automatically populated/quoted for you. My solution would be (and I'm no
>expert):
>
>Replace:
>$temval = "(".join(",",@sbval ).")";
>With:
>$temval = "(".join(", ", map("?", @sbval)).")";
>(which creates a string : "?,?,?,?,?,?" replacing the values from @sbval)
>
>And add the following after your prepare statement:
>my $f=1;
>foreach my $value (@sbval) {
> $statement->bind_param($f++, $value);
>}
>
>Happy for people to improve on this, though!
>
>-----Original Message-----
>From: kaustubh shinde [mailto:shindekaustubh@hotmail.com]
>Sent: 30 July 2004 09:35
>To: dbi-users@perl.org
>Subject: insert into statement problem
>
>
>Hi,
>I have been trying to read data from a hash and put it into myaql using
>insert into statement.
>
>foreach $key (keys %submt_feat)
>{
> if($submt_feat{$key}){
> $submt_feat{$key}= $submt_feat{$key};
> push(@sbft,$key);
> push(@sbval,$submt_feat{$key});
> }
>}
>$temfeat = "(".join(",",@sbft).")";
>$temval = "(".join(",",@sbval ).")";
>$ins = "insert into submitter ";
>$statement = $ins.$temfeat." values ".$temval.";";
>$statement = $dbh->prepare($statement);
>$statement->execute();
>
>but it doesnt work because the values need quotes around them since its
>varchar type.
>i am not able to get quotes around them. This is very urgent and I will
>really really appreciate any ideas.
>Thank you,
>Kaustubh
>
>_________________________________________________________________
>Studies, career, romance. Whatever your concerns.
>http://www.astroyogi.com/newMSN/ We have the answers.
>
>This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.
>
>



Relevant Pages

  • Re: how to include special characters in a formula?
    ... > I have tried the suggestion below, but it still doesnt work. ... >> Use double quotes instead of apostrophes. ... >> Pearson Software Consulting, LLC ...
    (microsoft.public.excel.programming)
  • Re: morefunc help
    ... >This is what I am using and it doesnt work ... Is the entire formula really within double quotes? ... Note that as you wrote it above, your formula is either a syntax error at ... 'C:\\', where it'd be garbage after the quoted string "indirect.ext(", or if you ...
    (microsoft.public.excel.worksheet.functions)
  • RE: insert into statement problem
    ... You can get single quotes around your values with this line: ... Subject: insert into statement problem ... but it doesnt work because the values need quotes around them since its ...
    (perl.dbi.users)
  • insert into statement problem
    ... I have been trying to read data from a hash and put it into myaql using ... but it doesnt work because the values need quotes around them since its ... i am not able to get quotes around them. ...
    (perl.dbi.users)