CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
reading multiple sql queries from a file.

 



007bindu
New User

Aug 19, 2008, 1:42 AM

Post #1 of 2 (3451 views)
reading multiple sql queries from a file. Can't Post

Hi

i have a .txt file which contains a set of sql queries, in the below format.

ex: 1: Select BenchmarkVersion from PABenchmarkView WHERE StageType='Received' AND BenchmarkID IN('testcase1-benchmark1');
2: Select BenchmarkID From PABenchmarkView WHERE StageType='Received'AND BenchmarkID IN('MultiBM-1', 'MultiBM-2')AND McAfeeSupplied='False';
3: Select * from PAAuditBenchmarkResultScore where BenchmarkResultAutoID = (Select BenchmarkResultAutoID from PAAuditBenchmarkResult where BenchmarkId = 'waiver_bench54');
4: Select Title from PACpeDictionary where DisplayInUI=1;

I want to read and store the query to a temp variable. So that i can execute each query from a common sql function.

My SQL funtion is :

package SQLquery;
use DBI;
#use Cwd;

$user="";
$password="";

$DSN="MQIS";

connect_SQLDataBase_WinAuth();
Func1();

sub connect_SQLDataBase_WinAuth
{
$dbh = DBI->connect("dbi:ODBC:$DSN", $user, $password);
}


sub Func1()
{
#### read all the sql queries from the text file to temp variable and start executing it for each array value
$query=("Select Title from PACpeDictionary where DisplayInUI=1; \n");
$sth = $dbh->prepare($query);
$sth->execute;
my $queryoutput;
while (($queryoutput)=$sth->fetchrow_array())
{
print ("\n $queryoutput \n");
}
}

Thanks in Advance

Bindu

9900205942


sycoogtit
User

Sep 6, 2008, 9:36 PM

Post #2 of 2 (3155 views)
Re: [007bindu] reading multiple sql queries from a file. [In reply to] Can't Post

I'm not sure what the question is here. You want Func1 to be something like this?


Code
open(FILE, "sql_queries.txt"); 
while(<FILE>) {
chomp;
$query = $_;
$sth = $dbh->prepare($query);
...
}
close(FILE);


Edit:
I just realized this is in the regex forum. Am I way off on what you're looking for, or should this be in a different forum?

--
http://bunsooter.com


(This post was edited by sycoogtit on Sep 6, 2008, 9:39 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives