mwill007 has asked for the wisdom of the Perl Monks concerning the following question:
I have to update database manually alot, so I wrote an app that reads the first line of a csv file and creates the headers/tables for an insert or update statement. The next lines are the data in the file.
I build the statement like so
if ($checksite eq $none) { $insertsqlstatement = 'INSERT INTO database.database('; $x=0; foreach (@dbcolumn) { $insertsqlstatement = $insertsqlstatement . "@dbcolumn[$x]"; # if ($x != $numelements ) { $insertsqlstatement = $insertsqlstatement . ","; } # else { $insertsqlstatement = $insertsqlstatement . ') VALUES ('; } # $x=$x+1; } # $x=0; foreach (@dbcolumn) { $insertsqlstatement = $insertsqlstatement . '\'' . "@splitarray[$ +x]" . '\''; $splitstatement = $splitstatement . '$' .@dbcolumn[$x] ; # if ($x != $numelements) { $insertsqlstatement = $insertsqlstatement . ','; $splitstatement = $splitstatement . ','; } # else { $insertsqlstatement = $insertsqlstatement .')'; } $x=$x+1; } }
when I print the value of $insertsqlstatement is equal to INSERT INTO database.database(site_id, site_store_type, project, site_city, site_state, site_country, project_begin ) VALUES ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8/2016 ')
I can copy it an it runs just fine in sql
Buy when i write from my sql statement it will not write sqlexec($insertsqlstatement);
But if i manualy set the value of $insertsqlstatement = "INSERT INTO database.database(site_id, site_store_type, project, site_city, site_state, site_country, project_begin ) VALUES ('9999','SC OSR','Prebuild','Penfield','NY','US','8/8/2016 ')";
The sqlexec($insertsqlstatement); executes and updates the database
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: building sql statement
by haukex (Archbishop) on Jul 25, 2016 at 19:02 UTC | |
by Your Mother (Archbishop) on Jul 25, 2016 at 19:19 UTC | |
by mwill007 (Initiate) on Jul 25, 2016 at 19:37 UTC | |
|
Re: building sql statement
by GotToBTru (Prior) on Jul 25, 2016 at 18:40 UTC | |
|
Re: building sql statement
by KeighleHawk (Scribe) on Jul 25, 2016 at 19:07 UTC |