DBD-Redbase
view release on metacpan or search on metacpan
t/30insertfetch.t view on Meta::CPAN
),
'insert'
)
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" ),
'prepare select'
)
or DbiError( $dbh->err, $dbh->errstr );
Test( $state or $cursor->execute, 'execute select' )
or DbiError( $cursor->err, $cursor->errstr );
my ( $row, $errstr );
Test(
$state
or ( defined( $row = $cursor->fetchrow_arrayref )
&& !( $cursor->errstr ) ),
'fetch select'
)
or DbiError( $cursor->err, $cursor->errstr );
Test(
$state
or ( $row->[ 0 ] == 1
&& $row->[ 1 ] eq 'Alligator Descartes'
&& $row->[ 2 ] == 1111
&& $row->[ 3 ] eq 'Some Text' ),
'compare select'
)
or DbiError( $cursor->err, $cursor->errstr );
Test( $state or $cursor->finish, 'finish select' )
or DbiError( $cursor->err, $cursor->errstr );
Test( $state or undef $cursor || 1, 'undef select' );
#
# ...and delete it........
#
Test( $state or $dbh->do( "DELETE FROM $table WHERE id = 1" ), 'delete' )
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" ),
'prepare select deleted'
)
or DbiError( $dbh->err, $dbh->errstr );
Test( $state or $cursor->execute, 'execute select deleted' )
or DbiError( $cursor->err, $cursor->errstr );
Test(
$state
or (
!defined( $row = $cursor->fetchrow_arrayref )
&& ( !defined( $errstr = $cursor->errstr )
|| $cursor->errstr eq '' )
),
'fetch select deleted'
)
or DbiError( $cursor->err, $cursor->errstr );
Test( $state or $cursor->finish, 'finish select deleted' )
or DbiError( $cursor->err, $cursor->errstr );
Test( $state or undef $cursor || 1, 'undef select deleted' );
#
# Finally drop the test table.
#
Test( $state or $dbh->do( "DROP TABLE $table" ), 'drop' )
or DbiError( $dbh->err, $dbh->errstr );
}
t/40bindparam.t view on Meta::CPAN
)
and $dbh->do( $def )
),
'create',
$def
)
or DbiError( $dbh->err, $dbh->errstr );
Test(
$state
or $cursor =
$dbh->prepare( "INSERT INTO $table" . " VALUES (?, ?)" ),
'prepare'
)
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 ),
'execute insert 1' )
or DbiError( $dbh->err, $dbh->errstr );
# Does the driver remember the automatically detected type?
Test( $state
or $cursor->execute( "3", "Jochen Wiedmann" ),
'execute insert num as string' )
or DbiError( $dbh->err, $dbh->errstr );
$numericVal = 2;
$charVal = "Tim Bunce";
Test( $state
or $cursor->execute( $numericVal, $charVal ),
'execute insert 2' )
or DbiError( $dbh->err, $dbh->errstr );
# Now try the explicit type settings
Test( $state or $cursor->bind_param( 1, " 4", SQL_INTEGER() ), 'bind 1' )
or DbiError( $dbh->err, $dbh->errstr );
Test( $state or $cursor->bind_param( 2, "Andreas Konig" ), 'bind 2' )
or DbiError( $dbh->err, $dbh->errstr );
Test( $state or $cursor->execute, 'execute binds' )
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 $cursor->finish, 'finish' );
Test( $state or undef $cursor || 1, 'undef cursor' );
Test( $state or $dbh->disconnect, 'disconnect' );
Test( $state or undef $dbh || 1, 'undef dbh' );
#
# And now retreive the rows using bind_columns
#
#
# Connect to the database
#
Test(
$state
or $dbh = DBI->connect( $test_dsn, $test_user, $test_password ),
'connect for read'
)
or ServerError();
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 ( ( $ref = $cursor->fetch ) && $id == 2 && $name eq 'Tim Bunce' )
)
or printf( "Query returned id = %s, name = %s, ref = %s, %d\n",
$id, $name, $ref, scalar( @$ref ) );
Test(
$state
or ( ( $ref = $cursor->fetch )
&& $id == 3
&& $name eq 'Jochen Wiedmann' )
)
or printf( "Query returned id = %s, name = %s, ref = %s, %d\n",
$id, $name, $ref, scalar( @$ref ) );
Test(
$state
or
( ( $ref = $cursor->fetch ) && $id == 4 && $name eq 'Andreas Konig' )
)
or printf( "Query returned id = %s, name = %s, ref = %s, %d\n",
$id, $name, $ref, scalar( @$ref ) );
Test(
$state
or ( ( $ref = $cursor->fetch ) && $id == 5 && !defined( $name ) )
)
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 );
}
t/40listfields.t view on Meta::CPAN
#
# 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
&& ( lc $$ref[ 0 ] ) eq $table_def[ 0 ][ 0 ]
&& ( lc $$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 ommitted due to the fact that NULLABLE is not implemented in Hsqldb
Test(
$state
or ( $dbdriver eq 'CSV' )
or ( $dbdriver eq 'ConfFile' )
or ( $ref = $cursor->{ 'NULLABLE' } )
or ( $dbdriver ne 'Hsqldb' )
&& @$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(
$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 " . IsNull( "id" ) )
)
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 $dbdriver eq 'CSV'
or $dbdriver eq 'ConfFile'
)
or DbiError( $dbh->err, $dbh->errstr );
Test(
$state
or ( !defined( $$rv[ 0 ] ) and defined( $$rv[ 1 ] ) )
or $dbdriver eq 'CSV'
or $dbdriver eq 'ConfFile'
)
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
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 ( $numrows == -1 ) )
or ErrMsgF( "Expected 1 rows, got %s.\n", $numrows );
Test( $state or ( $numrows = TrueRows( $cursor ) ) == 1 )
or ErrMsgF( "Expected to fetch 1 rows, got %s.\n", $numrows );
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 ( $numrows == -1 ) )
or ErrMsgF( "Expected 2 rows, got %s.\n", $numrows );
Test( $state or ( $numrows = TrueRows( $cursor ) ) == 2 )
or ErrMsgF( "Expected to fetch 2 rows, got %s.\n", $numrows );
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 ( $numrows == -1 ) )
or ErrMsgF( "Expected 2 rows, got %s.\n", $numrows );
Test( $state or ( $numrows = TrueRows( $cursor ) ) == 2 )
or ErrMsgF( "Expected to fetch 2 rows, got %s.\n", $numrows );
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.279 second using v1.01-cache-2.11-cpan-4d50c553e7e )