DBD-InterBase
view release on metacpan or search on metacpan
t/40alltypes.t view on Meta::CPAN
#
# Test($state or $table = FindNewTable($dbh))
# or DbiError($dbh->err, $dbh->errstr);
#
# Create a new table
#
my ($def, $table, $stmt);
$state or do {
$table = find_new_table($dbh);
$def =<<"DEF";
CREATE TABLE $table (
INTEGER_ INTEGER,
SMALLINT_ SMALLINT,
CHAR13_ CHAR(13),
CHAR20_ CHAR(20),
VARCHAR13_ VARCHAR(13),
DECIMAL_ DECIMAL,
FLOAT_ FLOAT,
DOUBLE_ DOUBLE PRECISION,
A_TIMESTAMP TIMESTAMP,
A_DATE DATE,
A_TIME TIME,
NUMERIC_AS_SMALLINT NUMERIC(4,3),
NUMERIC_AS_SMALLINT2 NUMERIC(4,3),
NUMERIC_AS_INTEGER NUMERIC(9,3),
NUMERIC_AS_INTEGER2 NUMERIC(9,3),
A_SIXTYFOUR NUMERIC(18,3)
)
DEF
};
Test($state or ($dbh->do($def)))
or DbiError($dbh->err, $dbh->errstr);
$state or do {
$stmt =<<"END_OF_QUERY";
INSERT INTO $table
(
INTEGER_,
SMALLINT_,
CHAR13_,
CHAR20_,
VARCHAR13_,
DECIMAL_,
FLOAT_,
DOUBLE_,
A_TIMESTAMP,
A_DATE,
A_TIME,
NUMERIC_AS_SMALLINT,
NUMERIC_AS_SMALLINT2,
NUMERIC_AS_INTEGER,
NUMERIC_AS_INTEGER2,
A_SIXTYFOUR
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
END_OF_QUERY
};
Test($state or $cursor = $dbh->prepare($stmt))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute(
30000,
1000,
'Edwin',
'Edwin Pratomo',
'A string',
5000,
1.2,
1.44,
$timestamp,
'TOMORROW',
'NOW',
32.71,
-32.71,
123456.7895,
-123456.7895,
86753090000.8675309)
) or DbiError($cursor->err, $cursor->errstr);
Test($state or $cursor = $dbh->prepare("SELECT * FROM $table", {
ib_timestampformat => '%Y-%m-%d %H:%M',
ib_dateformat => '%m-%d-%Y',
ib_timeformat => '%H:%M',
})) or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($cursor->err, $cursor->errstr);
Test($state or ($res = $cursor->fetchall_arrayref))
or DbiError($cursor->err, $cursor->errstr);
if (!$state) {
my ($types, $names, $fields) = @{$cursor}{TYPE, NAME, NUM_OF_FIELDS};
for (my $i = 0; $i < $fields; $i++) {
Test($state or ( $is_match[$i]->($res) ))
or DbiError(undef,
"wrong SELECT result for field $names->[$i]: $res->[0]->[$i]");
}
} else {
for (1..$num_of_fields) { Test($state) }
}
#
# Drop the test table
#
Test($state or ($cursor = $dbh->prepare("DROP TABLE $table")))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($cursor->err, $cursor->errstr);
# NUM_OF_FIELDS should be zero (Non-Select)
Test($state or (!$cursor->{'NUM_OF_FIELDS'}))
or !$verbose or printf("NUM_OF_FIELDS is %s, not zero.\n",
$cursor->{'NUM_OF_FIELDS'});
Test($state or (undef $cursor) or 1);
}
( run in 0.824 second using v1.01-cache-2.11-cpan-39bf76dae61 )