7 use DBI::Const::GetInfoType;
9 my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
11 #warn "$dsn $user $pass";
13 plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
14 unless ($dsn && $user);
18 my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
20 my $dbh = $schema->storage->dbh;
22 $dbh->do("DROP TABLE IF EXISTS artist;");
24 $dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), rank INTEGER NOT NULL DEFAULT '13', charfield CHAR(10));");
26 #'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
28 # This is in Core now, but it's here just to test that it doesn't break
29 $schema->class('Artist')->load_components('PK::Auto');
31 # test primary key handling
32 my $new = $schema->resultset('Artist')->create({ name => 'foo' });
33 ok($new->artistid, "Auto-PK worked");
37 $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
39 my $it = $schema->resultset('Artist')->search( {},
42 order_by => 'artistid' }
44 is( $it->count, 3, "LIMIT count ok" );
45 is( $it->next->name, "Artist 2", "iterator->next ok" );
48 is( $it->next, undef, "next past end of resultset ok" );
50 my $test_type_info = {
55 'default_value' => undef,
58 'data_type' => 'VARCHAR',
61 'default_value' => undef,
67 'default_value' => 13,
70 'data_type' => 'CHAR',
73 'default_value' => undef,
78 my $mysql_version = $dbh->get_info( $GetInfoType{SQL_DBMS_VER} );
79 skip "Cannot determine MySQL server version", 1 if !$mysql_version;
81 my ($v1, $v2, $v3) = $mysql_version =~ /^(\d+)\.(\d+)(?:\.(\d+))?/;
82 skip "Cannot determine MySQL server version", 1 if !$v1 || !defined($v2);
86 if( ($v1 < 5) || ($v1 == 5 && $v2 == 0 && $v3 <= 3) ) {
87 $test_type_info->{charfield}->{data_type} = 'VARCHAR';
90 my $type_info = $schema->storage->columns_info_for('artist');
91 is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
94 ## Can we properly deal with the null search problem?
96 ## Only way is to do a SET SQL_AUTO_IS_NULL = 0; on connect
97 ## But I'm not sure if we should do this or not (Ash, 2008/06/03)
101 ok my $artist1_rs = $schema->resultset('Artist')->search({artistid=>6666})
102 => 'Created an artist resultset of 6666';
104 is $artist1_rs->count, 0
105 => 'Got no returned rows';
107 ok my $artist2_rs = $schema->resultset('Artist')->search({artistid=>undef})
108 => 'Created an artist resultset of undef';
111 local $TODO = "need to fix the row count =1 when select * from table where pk IS NULL problem";
112 is $artist2_rs->count, 0
116 my $artist = $artist2_rs->single;
125 #$dbh->do("DROP TABLE artist") if $dbh;