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',
15 default_function => 'getdate()',
16 default_function_def => 'AS getdate()',
19 password => $password,
23 CREATE TABLE sybase_loader_test1 (
24 id INTEGER IDENTITY NOT NULL PRIMARY KEY,
26 computed_dt AS getdate()
29 # Test data types, see http://ispirer.com/wiki/sqlways/sybase/data-types
30 # XXX handle FLOAT(P) at some point
31 # ( http://msdn.microsoft.com/en-us/library/aa258876(SQL.80).aspx )
33 CREATE TABLE sybase_loader_test2 (
34 id INTEGER IDENTITY NOT NULL PRIMARY KEY,
44 a_double_precision DOUBLE PRECISION,
48 a_smalldatetime SMALLDATETIME,
50 a_smallmoney SMALLMONEY,
51 a_timestamp timestamp,
53 a_char_with_precision CHAR(2),
54 an_nchar_with_precision NCHAR(2),
55 a_unichar_with_precision UNICHAR(2),
56 a_varchar_with_precision VARCHAR(2),
57 an_nvarchar_with_precision NVARCHAR(2),
58 a_univarchar_with_precision UNIVARCHAR(2),
60 a_binary_with_precision BINARY(2),
61 a_varbinary_with_precision VARBINARY(2),
62 the_numeric NUMERIC(6,3),
63 the_decimal DECIMAL(6,3)
67 drop => [ qw/ sybase_loader_test1 sybase_loader_test2 / ],
70 my ($schema, $monikers, $classes) = @_;
72 my $rs = $schema->resultset($monikers->{sybase_loader_test1});
73 my $rsrc = $rs->result_source;
75 is $rsrc->column_info('id')->{data_type},
77 'INTEGER IDENTITY data_type is correct';
79 is $rsrc->column_info('id')->{is_auto_increment},
81 'INTEGER IDENTITY is_auto_increment => 1';
83 is $rsrc->column_info('ts')->{data_type},
85 'timestamps have the correct data_type';
87 is $rsrc->column_info('ts')->{inflate_datetime},
89 'timestamps have inflate_datetime => 0';
91 ok ((exists $rsrc->column_info('computed_dt')->{data_type}
92 && (not defined $rsrc->column_info('computed_dt')->{data_type})),
93 'data_type for computed column exists and is undef')
94 or diag "Data type is: ",
95 $rsrc->column_info('computed_dt')->{data_type}
98 my $computed_dt_default =
99 $rsrc->column_info('computed_dt')->{default_value};
101 ok ((ref $computed_dt_default eq 'SCALAR'),
102 'default_value for computed column is a scalar ref')
103 or diag "default_value is: ", $computed_dt_default
106 eval { is $$computed_dt_default,
108 'default_value for computed column is correct' };
110 $rsrc = $schema->resultset($monikers->{sybase_loader_test2})
112 my @type_columns = grep /^a/, $rsrc->columns;
113 my @without_precision = grep !/_with_precision\z/, @type_columns;
114 my @with_precision = grep /_with_precision\z/, @type_columns;
117 apply { s/_with_precision\z// } @with_precision
120 for my $col (@without_precision) {
121 my ($data_type) = $col =~ /^an?_(.*)/;
122 $data_type =~ s/_/ /g;
124 ok((not exists $rsrc->column_info($col)->{size}),
126 (exists $with_precision{$col} ? 'without precision ' : '') .
127 "has no 'size' column_info")
128 or diag "size is ".$rsrc->column_info($col)->{size}."\n";
131 for my $col (@with_precision) {
132 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
133 ($data_type = uc $data_type) =~ s/_/ /g;
134 my $size = $rsrc->column_info($col)->{size};
137 "$data_type with precision has a correct 'size' column_info";
140 is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
141 'size for NUMERIC(precision, scale) is correct';
143 is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
144 'size for DECIMAL(precision, scale) is correct';
150 if( !$dsn || !$user ) {
151 $tester->skip_tests('You need to set the DBICTEST_SYBASE_DSN, _USER, and _PASS environment variables');
154 $tester->run_tests();