Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > multiple SQL line query via Perl

Reply
Thread Tools

multiple SQL line query via Perl

 
 
JohnnyQ
Guest
Posts: n/a
 
      10-03-2003
Hello:

I posted this in the comp.lang.perl, but I saw a thread that said it
was abandoned. Sorry if this is a multiple post.

This is a question about formulating Sybase SQL queries in Perl.

I can certainly do single command lines in perl using:

$dbh = DBI->connect("dbi:Sybase:server=$dbHost", $dbUser, $dbPass);

if (!defined $dbh) { death ("Could not connect to database\n."); }
else { print LOGFILE "Connected to database.\n"; }

$query = "use ${dbDatabase}";
$sth = $dbh->prepare(${query});
$sth->execute;

$query = "set rowcount 100000";
$sth = $dbh->prepare(${query});
$sth->execute;

However, as fas as I can tell Sybase needs to have variables in the
executable block that they are used. So, I can't do something like:

$query = " declare @rowct int";
$sth = $dbh->prepare(${query});
$sth->execute;

$query = "select @rowct =1";
$sth = $dbh->prepare(${query});
$sth->execute;

Nor can I combine statements to do something like:

$query = "declare @rowct int\n select @rowct =1";
$sth = $dbh->prepare(${query});
$sth->execute;

So, my problem is that I have to find a way to group the following SQL
statements together and have them execute at once:

declare @rowct int
select @rowct = 1
while (@rowct > 0)
begin
delete Foo where creationDate < dateadd(day, -5, getdate())
select @rowct = @@rowcount
end

Thanks,

John
 
Reply With Quote
 
 
 
 
Greg Bacon
Guest
Posts: n/a
 
      10-04-2003
In article <(E-Mail Removed) >,
JohnnyQ <(E-Mail Removed)> wrote:

: [...]
: So, my problem is that I have to find a way to group the following SQL
: statements together and have them execute at once:
:
: declare @rowct int
: select @rowct = 1
: while (@rowct > 0)
: begin
: delete Foo where creationDate < dateadd(day, -5, getdate())
: select @rowct = @@rowcount
: end

What about the following?

$dbh->do(q{
declare @rowct int
select @rowct = 1
while (@rowct > 0)
begin
delete Foo where creationDate < dateadd(day, -5, getdate())
select @rowct = @@rowcount
end
});

Greg
--
Kelso: I'm not shallow, Fez. I just judge chicks by their looks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Long running SQL query via ActiveRecord blocking the entire Ruby process? estebanjang@gmail.com Ruby 5 11-06-2007 11:28 PM
Build dynamic sql query for JSTL <sql:query> Anonymous Java 0 10-13-2005 10:01 PM
SQL Query via python Jeff Elkins Python 6 05-24-2005 12:16 PM
Re: SQL Query via python Steve Holden Python 1 05-23-2005 03:14 PM
SQL FOR XML Query results to Text via ASP.NET Rob ASP .Net 1 01-07-2004 03:42 PM



Advertisments