|
Posted by Hemant Shah on September 20, 2006, 2:10 pm
Please log in for more thread options
I forgot to mentions that the example shows 3 columns, but the actual table
contains 50 coulmns.
While stranded on information super highway Hemant Shah wrote:
>
> Folks,
>
> I am having problem with my perl script that uses DBD::DB2 and inserts
> data into a table. I am trying to write a generic script that will
> read table name, column name and data from a file and dynamically
> build sql insert statement and insert data into the table.
>
> The input file looks like:
>
> tablename:col1,col2,col3
> data1,data2,data3
> data1,data2,data3
> data1,data2,data3
> .
> .
> .
> .
>
>
> The problem I have is that if I dynamically build the insert statement
> then the data does not get inserted into the database and I do not get
> any error. I intentionally wrong column name for one of the columns and
> I do do not get any errors. If I hard code the insert statement and I get
> error.
>
>
> Here is how I build my statement:
>
>
> # Build insert statement.
> $InsStmt = "INSERT INTO $ (";
> my $ColumnsArraySize = @ColumnsArray;
> for (my $i = 0; $i < $ColumnsArraySize; $i++)
>
> {
> if ($i == ($ColumnsArraySize -1))
> {
> $InsStmt .= $ColumnsArray[$i] . ")\n";
> }
> else
> {
> $InsStmt .= $ColumnsArray[$i] . ", ";
> }
> }
> $InsStmt .= "VALUES (";
> for (my $i = 0; $i < $ColumnsArraySize; $i++)
>
> {
> if ($i == ($ColumnsArraySize -1))
> {
> $InsStmt .= "?);\n";
> }
> else
> {
> $InsStmt .= "?, ";
> }
> }
>
> print "$InsStmt\n";
>
>
>
> Output:
> INSERT INTO DWH_PLIN (ACCESS_KEY, QUE_KEY, PLAN_CODE_TYPE)
> VALUES (?, ?, ?);
>
>
>
> If I hard code the statement as follows:
>
> $InsStmt = "INSERT INTO DWH_PLIN (ACCESS_KEY, QUE_KEY, PLAN_CODE_TYPE)
> VALUES (?, ?, ?);"
>
> Then I get error that I should get.
>
> What could cause this problem?
> How do I solve it?
>
> --
> Hemant Shah /"\ ASCII ribbon campaign
> E-mail: NoJunkMailshah@xnet.com \ / ---------------------
> X against HTML mail
> TO REPLY, REMOVE NoJunkMail / \ and postings
> FROM MY E-MAIL ADDRESS.
> -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
> I haven't lost my mind, Above opinions are mine only.
> it's backed up on tape somewhere. Others can have their own.
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
|