Re: Problem with DBI and placeholders

2021-04-15 Thread mailing lists via beginners
 I may not have expressed myself well, I have to migrate tables between two databases that contain millions of rows and I only need specific columns. Now it works using placeholders only for the values but is very slow for inserts even with AutoCommit disabled. Getting data from $src_db is f

Re: Problem with DBI and placeholders

2021-04-09 Thread Lawrence Statton
On 4/9/21 7:11 AM, mailing lists via beginners wrote: thanks Andrew I need to insert millions of rows so I need to have a good performance using placeholders You can not use placeholders for the table name. If you have millions of *tables*, there is something very, very, very wrong with

Re: Problem with DBI and placeholders

2021-04-09 Thread mailing lists via beginners
I use mysql so I don't see what may be failing :-( On Friday, April 9, 2021, 3:41:23 PM GMT+2, Andrew Solomon wrote: The problem is that this: $sth = $dbh->prepare("SELECT * FROM ?"); $sth->execute("test") && say "OK"; translates to  SELECT * FROM "test"; rather than  SELECT * FROM te

Re: Problem with DBI and placeholders

2021-04-09 Thread mailing lists via beginners
thanks, but that only works when you don't use parameters for the placeholders just try to do an insert like this: $sth = $dbh->prepare("INSERT INTO ? (?) VALUES (?)"); foreach  {    $sth->execute("test","data1","data2") && say "OK 2";}; now you need to pass the parameters and they will f

Re: Problem with DBI and placeholders

2021-04-09 Thread Andrew Solomon
The problem is that this: $sth = $dbh->prepare("SELECT * FROM ?"); $sth->execute("test") && say "OK"; translates to SELECT * FROM "test"; rather than SELECT * FROM test; This isn't a problem for Postgres but MySQL doesn't accept quoted table names. On Fri, Apr 9, 2021 at 1:25 PM mailing li

Re: Problem with DBI and placeholders

2021-04-09 Thread mailing lists via beginners
I'm using: CentOS Linux release 7.9.2009 (Core) perl 5.16.3 perl-DBD-MySQL-4.023 perl-DBI-1.627 On Friday, April 9, 2021, 2:19:13 PM GMT+2, mailing lists via beginners wrote: without using the variable $table it also fails with the same error $sth = $dbh->prepare("SELECT * FROM ?");

Re: Problem with DBI and placeholders

2021-04-09 Thread mailing lists via beginners
without using the variable $table it also fails with the same error $sth = $dbh->prepare("SELECT * FROM ?");$sth->execute("test") && say "OK"; On Friday, April 9, 2021, 2:12:01 PM GMT+2, mailing lists via beginners wrote: thanks Andrew I need to insert millions of rows so I need

Re: Problem with DBI and placeholders

2021-04-09 Thread mailing lists via beginners
thanks Andrew I need to insert millions of rows so I need to have a good performance using placeholders On Friday, April 9, 2021, 1:57:25 PM GMT+2, Andrew Solomon wrote: The ? is for quoting field values rather than entering table or field names. "SELECT * FROM $table" is probably

Re: Problem with DBI and placeholders

2021-04-09 Thread Andrew Solomon
The ? is for quoting field values rather than entering table or field names. "SELECT * FROM $table" is probably what you want. On Fri, Apr 9, 2021 at 12:49 PM mailing lists via beginners < beginners@perl.org> wrote: > Hello, > > I am having a problem with a very simple task and I don't see where

Problem with DBI and placeholders

2021-04-09 Thread mailing lists via beginners
Hello, I am having a problem with a very simple task and I don't see where the fault is. The first query works with problem but the second one fails with this error:  ./test.pl OK 1 DBD::mysql::st execute failed: You have an error in your SQL syntax; check the manual that corresponds to your M