3 use dbixcsl_common_tests;
6 use List::MoreUtils 'apply';
8 my $dsn = $ENV{DBICTEST_SYBASE_DSN} || '';
9 my $user = $ENV{DBICTEST_SYBASE_USER} || '';
10 my $password = $ENV{DBICTEST_SYBASE_PASS} || '';
12 my $tester = dbixcsl_common_tests->new(
14 auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY',
17 password => $password,
21 CREATE TABLE sybase_loader_test1 (
22 id INTEGER IDENTITY NOT NULL PRIMARY KEY,
24 charfield VARCHAR(10) DEFAULT 'foo',
25 computed_dt AS getdate()
28 # Test data types, see http://ispirer.com/wiki/sqlways/sybase/data-types
29 # XXX handle FLOAT(P) at some point
31 CREATE TABLE sybase_loader_test2 (
32 id INTEGER IDENTITY NOT NULL PRIMARY KEY,
42 a_double_precision DOUBLE PRECISION,
46 a_smalldatetime SMALLDATETIME,
48 a_smallmoney SMALLMONEY,
49 a_timestamp timestamp,
51 a_char_with_precision CHAR(2),
52 an_nchar_with_precision NCHAR(2),
53 a_unichar_with_precision UNICHAR(2),
54 a_varchar_with_precision VARCHAR(2),
55 an_nvarchar_with_precision NVARCHAR(2),
56 a_univarchar_with_precision UNIVARCHAR(2),
58 a_binary_with_precision BINARY(2),
59 a_varbinary_with_precision VARBINARY(2),
60 the_numeric NUMERIC(6,3),
61 the_decimal DECIMAL(6,3)
65 drop => [ qw/ sybase_loader_test1 sybase_loader_test2 / ],
68 my ($schema, $monikers, $classes) = @_;
70 my $rs = $schema->resultset($monikers->{sybase_loader_test1});
71 my $rsrc = $rs->result_source;
73 is $rsrc->column_info('id')->{data_type},
75 'INTEGER IDENTITY data_type is correct';
77 is $rsrc->column_info('id')->{is_auto_increment},
79 'INTEGER IDENTITY is_auto_increment => 1';
81 is $rsrc->column_info('ts')->{data_type},
83 'timestamps have the correct data_type';
85 is $rsrc->column_info('charfield')->{data_type},
87 'VARCHAR has correct data_type';
89 is $rsrc->column_info('charfield')->{default_value},
91 'constant DEFAULT is correct';
93 is $rsrc->column_info('charfield')->{size},
95 'VARCHAR(10) has correct size';
97 ok ((exists $rsrc->column_info('computed_dt')->{data_type}
98 && (not defined $rsrc->column_info('computed_dt')->{data_type})),
99 'data_type for computed column exists and is undef')
100 or diag "Data type is: ",
101 $rsrc->column_info('computed_dt')->{data_type}
104 my $computed_dt_default =
105 $rsrc->column_info('computed_dt')->{default_value};
107 ok ((ref $computed_dt_default eq 'SCALAR'),
108 'default_value for computed column is a scalar ref')
109 or diag "default_value is: ", $computed_dt_default
112 eval { is $$computed_dt_default,
114 'default_value for computed column is correct' };
116 $rsrc = $schema->resultset($monikers->{sybase_loader_test2})
118 my @type_columns = grep /^a/, $rsrc->columns;
119 my @without_precision = grep !/_with_precision\z/, @type_columns;
120 my @with_precision = grep /_with_precision\z/, @type_columns;
123 apply { s/_with_precision\z// } @with_precision
126 for my $col (@without_precision) {
127 my ($data_type) = $col =~ /^an?_(.*)/;
128 $data_type =~ s/_/ /g;
130 ok((not exists $rsrc->column_info($col)->{size}),
132 (exists $with_precision{$col} ? 'without precision ' : '') .
133 "has no 'size' column_info")
134 or diag "size is ".$rsrc->column_info($col)->{size}."\n";
137 for my $col (@with_precision) {
138 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
139 ($data_type = uc $data_type) =~ s/_/ /g;
140 my $size = $rsrc->column_info($col)->{size};
143 "$data_type with precision has a correct 'size' column_info";
146 is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
147 'size for NUMERIC(precision, scale) is correct';
149 is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
150 'size for DECIMAL(precision, scale) is correct';
156 if( !$dsn || !$user ) {
157 $tester->skip_tests('You need to set the DBICTEST_SYBASE_DSN, _USER, and _PASS environment variables');
160 $tester->run_tests();