Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

SQL Server 2003 output to Tk/Perl window

by Red_Dragon (Beadle)
on Dec 11, 2006 at 21:40 UTC ( [id://589166]=perlquestion: print w/replies, xml ) Need Help??

Red_Dragon has asked for the wisdom of the Perl Monks concerning the following question:

Wise and Noble Monks,

I am trying to get some idea on how to capture the results of an SQL query and display them in a scrollable WIN32 window. I am new to this method and need some examples to get me started, if any are available? Thank you for any assistance you can provide.

R_D

  • Comment on SQL Server 2003 output to Tk/Perl window

Replies are listed 'Best First'.
Re: SQL Server 2003 output to Tk/Perl window
by liverpole (Monsignor) on Dec 11, 2006 at 22:14 UTC
    Hi Red_Dragon,

    There are a couple of ways.  One is simply to take the results and write them to the widget (I'm assuming you have either a Text or a ROText object).  For example:

    use strict; use warnings; use Tk; my $sql = ""; my $mw = new MainWindow; my $top = $mw->Frame()->pack(-expand => 1, -fill => "both"); my $f1 = $top->Frame()->pack(-expand => 1, -fill => "x"); my $f2 = $top->Frame()->pack(-expand => 1, -fill => "both"); $f1->Label(-text => "SQL Statement")->pack(-side => "left"); $f1->Entry(-textvar => \$sql, -width => 64)->pack(-side => "left"); $f1->Button(-text => "SQL", -command => \&submit)->pack(-side => "righ +t"); my $output = $mw->Text()->pack(-expand => 1, -fill => "both"); MainLoop(); sub submit { # Here, insert the code for submitting the query using $sql... my $results = ... $output->insert("end", $results); $output->see("end"); $mw->update();

    The above code does everything except submitting the query in $sql to the SQL database (you'll need to fill that in where it says my $results = ...).

    Another way is to investigate the tied interface to a Tk::Text widget.  You can read about that either in your local ActiveState documentation, or at ActiveState's website (http://www.activestate.com), in the section about the Text widget; specifically the section titled Tied Interface, which says:

    TIED INTERFACE The Perl/Tk Text widget also has built-in TIEHANDLE methods for print and printf statements. This means you can print to file handles tied to a Text widget, and the tied methods automatically insert the print statement's arguments into the Text widget. For example: #!/usr/local/bin/perl -w use POSIX 'acos'; use Tk; use strict; my $mw = MainWindow->new; my $text = $mw->Text(qw/-width 40 -height 10/)->pack; tie *STDOUT, ref $text, $text; print "Hello Text World!\n"; printf "pi ~= %1.5f", acos(-1.0); MainLoop;

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://589166]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-23 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found