Re: insert into statement problem
From: Ravi Kongara (Ravi.Kongara_at_Sun.COM)
Date: 07/30/04
- Previous message: gary sekinger: "Re: fork and keeping connection DBD::Oracle ?"
- In reply to: Timothy Helck: "RE: insert into statement problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
>
>
- Previous message: gary sekinger: "Re: fork and keeping connection DBD::Oracle ?"
- In reply to: Timothy Helck: "RE: insert into statement problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|