AW: how to allow variable number of argumets in mysql insert quer y

AW: how to allow variable number of argumets in mysql insert quer y

am 18.12.2007 20:03:03 von Gisbert.Selke

> -----Ursprüngliche Nachricht-----
> Von: Baron Schwartz [mailto:baron@xaprb.com]
> Gesendet: Dienstag, 18. Dezember 2007 19:36
> You could also use this idiom:
>=20
> $dbh->do($sql, \%attrs, @args)
>=20
> For example,
>=20
> $dbh->do("select foo from bar where bar in(" . join(',', map { '?' }
> @args) . ")",
> {}, @args);
Right, Baron, that's much better (safer) than my second solution! =
TMTOWTDI.
The problem is (in both approaches) that the statement should be an =
INSERT
rather than a SELECT. Unless the columns are specified excplitly, the =
number
of parameters in the VALUES(...) part must match the number of columns =
in
the table, unless I'm mistaken about SQL syntax. You may, of course, =
insert
NULLs (aka undefs in the Perl world), but you have to do so explicitly.

\Gisbert

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=3Dgcdmp-msql-mysql-modules @m.gmane.org

Re: AW: how to allow variable number of argumets in mysql insertquer y

am 18.12.2007 20:53:11 von Fungazid

Thanks you a lot men,

I think that do() is slower then prepare() + execute() (if you need to cal=
l
execute multiple times). This is the first problem I have with your
solutions.=20
Secondly, the tables Iâ€=99m using have 100-400 columns! so the idea of
concatenating a string of 300 values and to input this directly into a
function can be a problem.
What I need is a way to translate a string into a perl code during run-time
(if there is a way).


--=20
View this message in context: http://www.nabble.com/AW%3A-how-to-allow-vari=
able-number-of-argumets-in-mysql-insert-quer-y-tp14403577p14 404440.html
Sent from the MySQL - Perl mailing list archive at Nabble.com.


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=3Dgcdmp-msql-mysql-modules @m.gmane.org

Re: AW: how to allow variable number of argumets in mysql insert quer y

am 18.12.2007 21:34:57 von Baron Schwartz

On Dec 18, 2007 2:53 PM, fungazid wrote:
>
> Thanks you a lot men,
>
> I think that do() is slower then prepare() + execute() (if you need to call
> execute multiple times). This is the first problem I have with your
> solutions.
> Secondly, the tables I'm using have 100-400 columns! so the idea of
> concatenating a string of 300 values and to input this directly into a
> function can be a problem.
> What I need is a way to translate a string into a perl code during run-time
> (if there is a way).

There definitely is, but it sounds like you need to read Higher-Order
Perl before you get into trouble :-)

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: AW: how to allow variable number of argumets in mysql insertquer y

am 18.12.2007 22:35:10 von Fungazid

My man,

Maybe you are partly right,
anyway I sloved my problem !!!!!!!!!!!!!!!!!
It is working fine
The solution is simple:

______________________________
for(my $i=1; $i< $size; $i++)
{
$str=$str.',$args['.$i.']';
}
my $str2='$q->execute('.$str.') or die "Couldn\'t execute statement: " .
$q->errstr';
eval $str2 or die "error!!!\n";
_______________________________


Thank you good people


Baron Schwartz-2 wrote:
>
> On Dec 18, 2007 2:53 PM, fungazid wrote:
>>
>> Thanks you a lot men,
>>
>> I think that do() is slower then prepare() + execute() (if you need to
>> call
>> execute multiple times). This is the first problem I have with your
>> solutions.
>> Secondly, the tables I'm using have 100-400 columns! so the idea of
>> concatenating a string of 300 values and to input this directly into a
>> function can be a problem.
>> What I need is a way to translate a string into a perl code during
>> run-time
>> (if there is a way).
>
> There definitely is, but it sounds like you need to read Higher-Order
> Perl before you get into trouble :-)
>
> --
> MySQL Perl Mailing List
> For list archives: http://lists.mysql.com/perl
> To unsubscribe: http://lists.mysql.com/perl?unsub=lists@nabble.com
>
>
>

--
View this message in context: http://www.nabble.com/AW%3A-how-to-allow-variable-number-of- argumets-in-mysql-insert-quer-y-tp14403577p14406265.html
Sent from the MySQL - Perl mailing list archive at Nabble.com.


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org