7 use DBI::Const::GetInfoType;
10 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
12 #warn "$dsn $user $pass";
14 plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
15 unless ($dsn && $user);
19 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
21 my $dbh = $schema->storage->dbh;
22 my $stats = new DBICTest::Stats();
23 $schema->storage->debugobj($stats);
24 $schema->storage->debug(1);
26 $dbh->do("DROP TABLE IF EXISTS artist;");
28 $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10)) ENGINE=InnoDB;");
30 #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
32 # This is in Core now, but it's here just to test that it doesn't break
33 $schema->class('Artist')->load_components('PK::Auto');
35 # test primary key handling
36 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
37 ok($new->artistid, "Auto-PK worked");
41 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
43 my $it = $schema->resultset('Artist')->search( {},
46 order_by => 'artistid' }
48 is( $it->count, 3, "LIMIT count ok" );
49 is( $it->next->name, "Artist 2", "iterator->next ok" );
52 is( $it->next, undef, "next past end of resultset ok" );
54 my $test_type_info = {
59 'default_value' => undef,
62 'data_type' => 'VARCHAR',
65 'default_value' => undef,
68 'data_type' => 'CHAR',
71 'default_value' => undef,
77 my $arty = $schema->resultset('Artist')->find(1);
79 my $name = $arty->name();
81 $schema->svp_begin('savepoint1');
83 cmp_ok($stats->{'SVP_BEGIN'}, '==', 1, 'Statistics svp_begin tickled');
85 $arty->update({ name => 'Jheephizzy' });
87 $arty->discard_changes();
89 cmp_ok($arty->name(), 'eq', 'Jheephizzy', 'Name changed');
91 $schema->svp_rollback('savepoint1');
93 cmp_ok($stats->{'SVP_ROLLBACK'}, '==', 1, 'Statistics svp_rollback tickled');
95 $arty->discard_changes();
97 cmp_ok($arty->name(), 'eq', $name, 'Name rolled back');
99 $schema->txn_commit();
102 my $mysql_version = $dbh->get_info( $GetInfoType{SQL_DBMS_VER} );
103 skip "Cannot determine MySQL server version", 1 if !$mysql_version;
105 my ($v1, $v2, $v3) = $mysql_version =~ /^(\d+)\.(\d+)(?:\.(\d+))?/;
106 skip "Cannot determine MySQL server version", 1 if !$v1 || !defined($v2);
110 if( ($v1 < 5) || ($v1 == 5 && $v2 == 0 && $v3 <= 3) ) {
111 $test_type_info->{charfield}->{data_type} = 'VARCHAR';
114 my $type_info = $schema->storage->columns_info_for('artist');
115 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
120 $dbh->do("DROP TABLE artist") if $dbh;