[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] :Sybase success, build errors



> diff -ruN exec.t.original exec.t

Hmm... The patch was longer than the file. 

If you prefer, here's the full contents of the modified file.

j



#!perl
#
# $Id: exec.t,v 1.8 2005/06/27 18:04:18 mpeppler Exp $

use lib 'blib/lib';
use lib 'blib/arch';

use lib 't';
use _test;

use strict;

#use Test::More qw(no_plan);
use Test::More tests => 41;


BEGIN { use_ok('DBI', ':sql_types');
        use_ok('DBD::Sybase');}


use vars qw($Pwd $Uid $Srv $Db);

my $using_freetds = ($ENV{SYBASE} =~ /freetds/i) ? 1 : 0;

#DBI->trace(3);

($Uid, $Pwd, $Srv, $Db) = _test::get_info();

#DBI->trace(3);
my $dbh = DBI->connect("dbi:Sybase:server=$Srv;database=$Db", $Uid, $Pwd, {PrintError=>1});
#exit;
ok(defined($dbh), 'Connect');

$SIG{__WARN__} = sub { print @_; };
my $sth = $dbh->prepare("exec sp_helpindex \@objname = 'sysusers'");   # Placeholders not supported in freetds
ok(defined($sth), 'Prepare sp_helpindex');

my $rc;
$rc = $sth->execute();
ok(defined($rc), "exec sysusers");

get_all_results($sth);

#$dbh->do("use tempdb");
$dbh->do("set arithabort off");
$dbh->do("if object_id('dbitest') != NULL drop proc dbitest");
$rc = $dbh->do(q{
create proc dbitest @one varchar(20), @two int, @three numeric(5,2), @four smalldatetime, @five float output
as
    select @one, @two, @three, @four
    select * from master..sysprocesses

    return @two
});

ok(defined($rc), "$rc (create proc)");

$sth = $dbh->prepare("exec dbitest \@one = ?, \@two = ?, \@three = ?, \@four = ?, \@five = ? output");
#$rc = $sth->execute("one", 2, 3.2, "jan 1 2001", 5.4);
ok(defined($sth), "prepare dbitest");
ok($sth->bind_param(1, "one"),               "bind_param 1");
ok($sth->bind_param(2, 2, SQL_INTEGER),      "bind_param 2");
ok($sth->bind_param(3, 3.2, SQL_DECIMAL),    "bind_param 3");
ok($sth->bind_param(4, "jan 1 2001"),        "bind_param 4");
ok($sth->bind_param(5, 5.4, SQL_FLOAT),      "bind_param 5");
SKIP: {
  skip "freetds seg faults here", 1 if $using_freetds;
  ok($rc = $sth->execute(), "execute dbitest 1");
}

SKIP: {
  skip "freetds doesn't support placeholders", 2 if $using_freetds;
  #DBI->trace(4);
  get_all_results($sth);
  ok($rc = $sth->execute("one", 25, 333.2, "jan 1 2001", 5.4),  "exec dbitest 2");
  get_all_results($sth);
  ok($rc = $sth->execute(undef, 25, 3.2234, "jan 3 2001", 5.4), "exec dbitest 3");
}

SKIP: {
  skip "freetds doesn't support \$sth->func?", 2 if $using_freetds;
  ok(my @out = $sth->func('syb_output_params'),                 '$sth->func');
  is($out[0], 5.4,                                              "out param 1");
}


#print "@out\n";
#do {
#    local $^W = 0;
#    while(my $d = $sth->fetch) {
#	print "@$d\n";
#    }
#} while($sth->{syb_more_results});

# test various failure modes:

$sth->{syb_do_proc_status} = 1;
$dbh->{syb_flush_finish} = 0;

SKIP: {
  skip "freetds doesn't support placeholders", 6 if $using_freetds;
  ok($rc = $sth->execute(undef, 0, 3.2234, "jan 3 2001", 5.4),   "execute fail mode 1");
  get_all_results($sth);
  #DBI->trace(3);
  ok($rc = $sth->execute("raise", 1, 3.2234, "jan 3 2001", 5.4), "execute fail mode 2");
  get_all_results($sth);
  ok($rc = $sth->execute(undef, 0, 3.2234, "jan 3 2001", 5.4),   "execute fail mode 3");
  #DBI->trace(0);
  get_all_results($sth);

  $dbh->{syb_flush_finish} = 1;
  ok($rc = $sth->execute(undef, 0, 3.2234, "jan 3 2001", 5.4),   "execute fail mode 4");
  get_all_results($sth);
  #DBI->trace(3);
  ok($rc = $sth->execute(undef, 1, 3.2234, "jan 3 2001", 5.4),   "execute fail mode 5");
  get_all_results($sth);
  #DBI->trace(0);
  ok($rc = $sth->execute(undef, 0, 3.2234, "jan 3 2001", 5.4),   "execute fail mode 6");
  get_all_results($sth);
}


ok($dbh->do("drop proc dbitest"),                                  "drop proc dbitest 1");
ok($dbh->do("if object_id('dbitest') != NULL drop proc dbitest"),  "drop proc dbitest 2");
$rc = $dbh->do(q{
create proc dbitest @one varchar(20), @two int, @three numeric(5,2), @four smalldatetime --, @five float = null output
as
    select @one, @two, @three, @four

});

ok(defined($rc), "$rc (create proc)");

SKIP: {
  skip "freetds doesn't support bind_param nor placeholders", 7 if $using_freetds;
  ok($sth = $dbh->prepare("exec dbitest ?, ?, ?, ?"),      "prepare");
  ok($sth->bind_param(1, 'String 1', SQL_VARCHAR),         "bind_param 1");
  ok($sth->bind_param(2, 1, SQL_INTEGER),                  "bind_param 2");
  ok($sth->bind_param(3, 3.25, SQL_DECIMAL),               "bind_param 3");
  ok($sth->bind_param(4, '2005-06-27', SQL_DATETIME),      "bind param 4");

  for (0 .. 1) {
    $sth->execute('String 1', 1, 3.25, '2005-06-27');
    while(my $row = $sth->fetch) {
      ok($row->[2] == 3.25, "Implicit finish handling");
    }
  }
}

SKIP: {
  skip "freetds doesn't support bind_param nor placeholders", 7 if $using_freetds;
  $dbh->{syb_do_proc_status} = 1;
  ok($sth = $dbh->prepare("exec dbitest ?, ?, ?, ?"),  "prepare");
  ok($sth->bind_param(1, 'String 1', SQL_VARCHAR),     "bind_param 1");
  ok($sth->bind_param(2, 1, SQL_INTEGER),              "bind_param 2");
  ok($sth->bind_param(3, 3.25, SQL_DECIMAL),           "bind_param 3");
  ok($sth->bind_param(4, '2005-06-27', SQL_DATETIME),  "bind_param 4");

  for (0 .. 1) {
    $sth->execute('String 1', 1, 3.25, '2005-06-27');
    while(my $row = $sth->fetch) {
      ok($row->[2] == 3.25, "Implicit finish handling");
    }
  }
}

ok($dbh->do("drop proc dbitest"),     "drop proc dbitest");

sub get_all_results {
    my $sth = shift;

    do {
	while(my $d = $sth->fetch) {
	    #print "@$d\n";
	    ;
	}
    } while($sth->{syb_more_results});
}