DBD-InterBase

 view release on metacpan or  search on metacpan

t/40doparam.t  view on Meta::CPAN


sub ServerError() {
    my $err = $DBI::errstr;  # Hate -w ...
    print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
    "\tEither your server is not up and running or you have no\n",
    "\tpermissions for acessing the DSN $test_dsn.\n",
    "\tThis test requires a running server and write permissions.\n",
    "\tPlease make sure your server is running and you have\n",
    "\tpermissions, then retry.\n");
    exit 10;
}

if (!defined(&SQL_VARCHAR)) {
    eval "sub SQL_VARCHAR { 12 }";
}
if (!defined(&SQL_INTEGER)) {
    eval "sub SQL_INTEGER { 4 }";
}

#
#   Main loop; leave this untouched, put tests after creating
#   the new table.
#
while (Testing()) {
    #
    #   Connect to the database
    Test($state or $dbh = DBI->connect($test_dsn, $test_user,
$test_password, {ChopBlanks => 1}))
    or ServerError();

    #
    #   Find a possible new table name
    #
    Test($state or $table = FindNewTable($dbh))
       or DbiError($dbh->err, $dbh->errstr);

    #
    #   Create a new table; EDIT THIS!
    #
    Test($state or ($def = TableDefinition($table,
                       ["id",   "INTEGER",  4, 0],
                       ["name", "CHAR",    64, $COL_NULLABLE]),
            $dbh->do($def)))
       or DbiError($dbh->err, $dbh->errstr);

    #
    #   Insert some rows
    #

    # Automatic type detection
    my $numericVal = 1;
    my $charVal = "Alligator Descartes";

    Test($state or $dbh->do("INSERT INTO $table"
           . " VALUES (?, ?)", undef, $numericVal, $charVal))
       or DbiError($dbh->err, $dbh->errstr);

    #
    #   And now retreive the rows using bind_columns
    #
    Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"
                       . " ORDER BY id"))
       or DbiError($dbh->err, $dbh->errstr);

    Test($state or $cursor->execute)
       or DbiError($dbh->err, $dbh->errstr);

    Test($state or $cursor->bind_columns(undef, \$id, \$name))
       or DbiError($dbh->err, $dbh->errstr);

    Test($state or ($ref = $cursor->fetch)  &&  $id == 1  &&
     $name eq 'Alligator Descartes')
    or printf("Query returned id = %s, name = %s, ref = %s, %d\n",
          $id, $name, $ref, scalar(@$ref));

#    }

    Test($state or undef $cursor  or  1);


    #
    #   Finally drop the test table.
    #
    Test($state or $dbh->do("DROP TABLE $table"))
       or DbiError($dbh->err, $dbh->errstr);
}



( run in 2.934 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )