[freetds] testing using tsql

David Nichols nicholsman at gmail.com
Thu Jun 21 01:54:39 EDT 2007


> I am trying to find a way to test an MS SQL engine using tsql(1)  
> from a
> Linux box.
> My input file has over 47000 SQL statements in it.
> So I rolled up a perl script to say...
> my $input = IO::File->new ( "inputfile.sql");
> my $output = IO::File->new( "| tsql -H host -P port -U xx -P xxx");
> $output->autoflush(1);
> do
> {
>      $more = $sql = getSql ( $in );
>     sendSql ($out, $sql);
>     # recvResponse(....);
>     sleep(2); # watch some TV, etc
> } while ( $more );
> My problem is with my writes to the pipe above. And tsql prompts and
> bunch of error messages...I might have to insert a function called
> recvResponse() after sendSQL()....and that is where I said, I bet
> someone has already done this....
> has anyone cooked up a utilitiy like this....I need to be able to  
> insert
> sleep between sql requests....that is why I can 'nt use tsql itself
> Or maybe there is a way ...

If you don't absolutely have to use tsql, then if I could suggest  
trying qore to do it; the latest release has a FreeTDS-based driver  
(called "mssql").
Qore features tighter database integration than perl, and, although  
of course it's a much newer language so it doesn't have the amazing  
breadth and depth of perl's libraries and modules, the sort of thing  
you are trying to do is a lot easier in qore than perl (IMHO - note:  
I am the author of qore, so I'm obviously biased).

The code would look like the following in qore:

# load the FreeTDS driver
%requires mssql

# set connection parameters using the mssql driver
# note there must be an entry for this dataserver in the freetds.conf  
file to set the hostname, port and the TDS protocol version
my $db = new Datasource("mssql", "user", "password", "connection_name"):

my $input = new File();

# the following assumes that each line is an SQL statement terminated  
by a newline
while (exists (my $line = trim($input.readLine())))

If you need any help with qore, drop me a line.  Qore info can be  
found here: http://qoretechnologies.com/qore

Otherwise I can't help much with perl - although I might suggest  
trying calling tsql with system() or something like that for each SQL  
command instead of using a pipe; maybe it will be easier to debug?


More information about the FreeTDS mailing list