shemp has asked for the wisdom of the Perl Monks concerning the following question:
And i create a query to write to this table, such as:CREATE TABLE blah ( A INT, B INT NOT NULL DEFAULT 0 )
Then i have an array of hashrefs, each containing 1 row of values to insert, such asmy $query = "INSERT INTO blah SET A = ?, B = ? "; my $query_handle = $db_handle->prepare($query);
Now i have a loop to go through and insert all of these rows. When i wasnt using bind params, if a column doesnt have a value, i just dont mention it in the query, and the DB takes care of inserting a default value. But when using bind params, i cant figure out a way to get the DB to insert the default value, without creating a separate query for each combination of fields to insert.my @to_insert = ( { 'A' => 1, 'B' => 1 }, { 'B' => 2 }, { 'A' => 3 }, );
For this trivial example, there are only 3 queries, but in general, if there are n columns, there are (2^n - 1) possible column combinations, and i dont want to have to create each one.
I dont even know if this is possible, but any insight would be great.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI bind params & column defaults
by Plankton (Vicar) on Oct 27, 2003 at 18:13 UTC | |
|
Re: DBI bind params & column defaults
by dragonchild (Archbishop) on Oct 27, 2003 at 18:18 UTC | |
|
Re: DBI bind params & column defaults
by liz (Monsignor) on Oct 27, 2003 at 18:14 UTC | |
by shemp (Deacon) on Oct 27, 2003 at 18:26 UTC | |
by liz (Monsignor) on Oct 27, 2003 at 18:39 UTC | |
by cchampion (Curate) on Oct 27, 2003 at 19:23 UTC | |
by liz (Monsignor) on Oct 27, 2003 at 19:48 UTC | |
|
Re: DBI bind params & column defaults
by shemp (Deacon) on Oct 27, 2003 at 18:29 UTC | |
|
Re: DBI bind params & column defaults
by shemp (Deacon) on Oct 27, 2003 at 23:23 UTC | |
|
Re: DBI bind params & column defaults
by injunjoel (Priest) on Oct 28, 2003 at 00:24 UTC |