DBD-pNET
view release on metacpan or search on metacpan
t/30insertfetch.t view on Meta::CPAN
#
# ...and delete it........
#
Test($state or $dbh->do("DELETE FROM $table WHERE id = 1"))
or DbiError($dbh->err, $dbh->errstr);
#
# Now, try SELECT'ing the row out. This should fail.
#
Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"
. " WHERE id = 1"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($cursor->err, $cursor->errstr);
my ($row, $errstr);
Test($state or (!defined($row = $cursor->fetchrow_arrayref) &&
(!defined($errstr = $cursor->errstr) ||
$cursor->errstr eq '')))
or DbiError($cursor->err, $cursor->errstr);
Test($state or $cursor->finish, "\$sth->finish failed")
or DbiError($cursor->err, $cursor->errstr);
Test($state or undef $cursor || 1);
#
# Finally drop the test table.
#
Test($state or $dbh->do("DROP TABLE $table"))
or DbiError($dbh->err, $dbh->errstr);
}
t/40bindparam.t view on Meta::CPAN
#
# 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);
Test($state or $cursor = $dbh->prepare("INSERT INTO $table"
. " VALUES (?, ?)"))
or DbiError($dbh->err, $dbh->errstr);
#
# Insert some rows
#
# Automatic type detection
my $numericVal = 1;
my $charVal = "Alligator Descartes";
Test($state or $cursor->execute($numericVal, $charVal))
or DbiError($dbh->err, $dbh->errstr);
# Does the driver remember the automatically detected type?
Test($state or $cursor->execute("2", "Tim Bunce"))
or DbiError($dbh->err, $dbh->errstr);
$numericVal = 3;
$charVal = "Jochen Wiedmann";
Test($state or $cursor->execute($numericVal, $charVal))
or DbiError($dbh->err, $dbh->errstr);
# Now try the explicit type settings
Test($state or $cursor->bind_param(1, " 4", SQL_INTEGER()))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->bind_param(2, "Andreas König"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
# Works undef -> NULL?
Test($state or $cursor->bind_param(1, 5, SQL_INTEGER()))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->bind_param(2, undef))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
Test($state or undef $cursor || 1);
#
# 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 DbiError($dbh->err, $dbh->errstr);
if (!$state && $verbose) {
print "Query returned id = $id, name = $name, ref = $ref, @$ref\n";
}
Test($state or (($ref = $cursor->fetch) && $id == 2 &&
$name eq 'Tim Bunce'))
or DbiError($dbh->err, $dbh->errstr);
if (!$state && $verbose) {
print "Query returned id = $id, name = $name, ref = $ref, @$ref\n";
}
Test($state or (($ref = $cursor->fetch) && $id == 3 &&
$name eq 'Jochen Wiedmann'))
or DbiError($dbh->err, $dbh->errstr);
if (!$state && $verbose) {
print "Query returned id = $id, name = $name, ref = $ref, @$ref\n";
}
Test($state or (($ref = $cursor->fetch) && $id == 4 &&
$name eq 'Andreas König'))
or DbiError($dbh->err, $dbh->errstr);
if (!$state && $verbose) {
print "Query returned id = $id, name = $name, ref = $ref, @$ref\n";
}
Test($state or (($ref = $cursor->fetch) && $id == 5 &&
!defined($name)))
or DbiError($dbh->err, $dbh->errstr);
if (!$state && $verbose) {
print "Query returned id = $id, name = $name, ref = $ref, @$ref\n";
}
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);
}
t/40blobs.t view on Meta::CPAN
#
# Insert a row into the test table.......
#
Test($state or $dbh->do("INSERT INTO $table VALUES(1, "
. $qblob . ")"))
or DbiError($dbh->err, $dbh->errstr);
#
# Now, try SELECT'ing the row out.
#
Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"
. " WHERE id = 1"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
Test($state or (defined($row = $cursor->fetchrow_arrayref)))
or DbiError($cursor->err, $cursor->errstr);
Test($state or (@$row == 2 && $$row[0] == 1 && $$row[1] eq $blob))
or !$verbose or (ShowBlob($blob),
ShowBlob(defined($$row[1]) ? $$row[1] : ""));
Test($state or $cursor->finish)
or DbiError($cursor->err, $cursor->errstr);
Test($state or undef $cursor || 1)
or DbiError($cursor->err, $cursor->errstr);
#
# Finally drop the test table.
#
Test($state or $dbh->do("DROP TABLE $table"))
or DbiError($dbh->err, $dbh->errstr);
}
}
t/40listfields.t view on Meta::CPAN
or DbiError($dbh->err, $dbh->errstr);
#
# Create a new table
#
Test($state or ($def = TableDefinition($table, @table_def),
$dbh->do($def)))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($cursor->err, $cursor->errstr);
my $res;
Test($state or (($res = $cursor->{'NUM_OF_FIELDS'}) == @table_def))
or DbiError($cursor->err, $cursor->errstr);
if (!$state && $verbose) {
printf("Number of fields: %s\n", defined($res) ? $res : "undef");
}
Test($state or ($ref = $cursor->{'NAME'}) && @$ref == @table_def
&& $$ref[0] eq $table_def[0][0]
&& $$ref[1] eq $table_def[1][0])
or DbiError($cursor->err, $cursor->errstr);
if (!$state && $verbose) {
print "Names:\n";
for ($i = 0; $i < @$ref; $i++) {
print " ", $$ref[$i], "\n";
}
}
Test($state or ($ref = $cursor->{'NULLABLE'}) && @$ref == @table_def
&& !($$ref[0] xor ($table_def[0][3] & $COL_NULLABLE))
&& !($$ref[1] xor ($table_def[1][3] & $COL_NULLABLE)))
or DbiError($cursor->err, $cursor->errstr);
if (!$state && $verbose) {
print "Nullable:\n";
for ($i = 0; $i < @$ref; $i++) {
print " ", ($$ref[$i] & $COL_NULLABLE) ? "yes" : "no", "\n";
}
}
Test($state or undef $cursor || 1);
#
# 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'} == 0))
or !$verbose or printf("NUM_OF_FIELDS is %s, not zero.\n",
$cursor->{'NUM_OF_FIELDS'});
Test($state or (undef $cursor) or 1);
}
t/40nulls.t view on Meta::CPAN
#
# Test whether or not a field containing a NULL is returned correctly
# as undef, or something much more bizarre
#
Test($state or $dbh->do("INSERT INTO $table VALUES"
. " ( NULL, 'NULL-valued id' )"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"
. " WHERE id = NULL"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
Test($state or $rv = $cursor->fetchrow_arrayref)
or DbiError($dbh->err, $dbh->errstr);
Test($state or !defined($$rv[0]) && defined($$rv[1]))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->finish)
or DbiError($dbh->err, $dbh->errstr);
Test($state or undef $cursor || 1);
#
# Finally drop the test table.
#
Test($state or $dbh->do("DROP TABLE $table"))
or DbiError($dbh->err, $dbh->errstr);
}
t/40numrows.t view on Meta::CPAN
# This section should exercise the sth->rows
# method by preparing a statement, then finding the
# number of rows within it.
# Prior to execution, this should fail. After execution, the
# number of rows affected by the statement will be returned.
#
Test($state or $dbh->do("INSERT INTO $table"
. " VALUES( 1, 'Alligator Descartes' )"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or ($cursor = $dbh->prepare("SELECT * FROM $table"
. " WHERE id = 1")))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
Test($state or ($numrows = $cursor->rows) == 1)
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->finish)
or DbiError($dbh->err, $dbh->errstr);
Test($state or undef $cursor or 1);
Test($state or $dbh->do("INSERT INTO $table"
. " VALUES( 2, 'Jochen Wiedmann' )"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or ($cursor = $dbh->prepare("SELECT * FROM $table"
. " WHERE id >= 1")))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
Test($state or ($numrows = $cursor->rows) == 2)
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->finish)
or DbiError($dbh->err, $dbh->errstr);
Test($state or undef $cursor or 1);
Test($state or $dbh->do("INSERT INTO $table"
. " VALUES(3, 'Tim Bunce')"))
or DbiError($dbh->err, $dbh->errstr);
Test($state or ($cursor = $dbh->prepare("SELECT * FROM $table"
. " WHERE id >= 2")))
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->execute)
or DbiError($dbh->err, $dbh->errstr);
Test($state or ($numrows = $cursor->rows) == 2)
or DbiError($dbh->err, $dbh->errstr);
Test($state or $cursor->finish)
or DbiError($dbh->err, $dbh->errstr);
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 0.342 second using v1.01-cache-2.11-cpan-4d50c553e7e )