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
30 # ( http://msdn.microsoft.com/en-us/library/aa258876(SQL.80).aspx )
32 CREATE TABLE sybase_loader_test2 (
33 id INTEGER IDENTITY NOT NULL PRIMARY KEY,
43 a_double_precision DOUBLE PRECISION,
47 a_smalldatetime SMALLDATETIME,
49 a_smallmoney SMALLMONEY,
50 a_timestamp timestamp,
52 a_char_with_precision CHAR(2),
53 an_nchar_with_precision NCHAR(2),
54 a_unichar_with_precision UNICHAR(2),
55 a_varchar_with_precision VARCHAR(2),
56 an_nvarchar_with_precision NVARCHAR(2),
57 a_univarchar_with_precision UNIVARCHAR(2),
59 a_binary_with_precision BINARY(2),
60 a_varbinary_with_precision VARBINARY(2),
61 the_numeric NUMERIC(6,3),
62 the_decimal DECIMAL(6,3)
66 drop => [ qw/ sybase_loader_test1 sybase_loader_test2 / ],
69 my ($schema, $monikers, $classes) = @_;
71 my $rs = $schema->resultset($monikers->{sybase_loader_test1});
72 my $rsrc = $rs->result_source;
74 is $rsrc->column_info('id')->{data_type},
76 'INTEGER IDENTITY data_type is correct';
78 is $rsrc->column_info('id')->{is_auto_increment},
80 'INTEGER IDENTITY is_auto_increment => 1';
82 is $rsrc->column_info('ts')->{data_type},
84 'timestamps have the correct data_type';
86 is $rsrc->column_info('charfield')->{data_type},
88 'VARCHAR has correct data_type';
90 is $rsrc->column_info('charfield')->{default_value},
92 'constant DEFAULT is correct';
94 is $rsrc->column_info('charfield')->{size},
96 'VARCHAR(10) has correct size';
98 ok ((exists $rsrc->column_info('computed_dt')->{data_type}
99 && (not defined $rsrc->column_info('computed_dt')->{data_type})),
100 'data_type for computed column exists and is undef')
101 or diag "Data type is: ",
102 $rsrc->column_info('computed_dt')->{data_type}
105 my $computed_dt_default =
106 $rsrc->column_info('computed_dt')->{default_value};
108 ok ((ref $computed_dt_default eq 'SCALAR'),
109 'default_value for computed column is a scalar ref')
110 or diag "default_value is: ", $computed_dt_default
113 eval { is $$computed_dt_default,
115 'default_value for computed column is correct' };
117 $rsrc = $schema->resultset($monikers->{sybase_loader_test2})
119 my @type_columns = grep /^a/, $rsrc->columns;
120 my @without_precision = grep !/_with_precision\z/, @type_columns;
121 my @with_precision = grep /_with_precision\z/, @type_columns;
124 apply { s/_with_precision\z// } @with_precision
127 for my $col (@without_precision) {
128 my ($data_type) = $col =~ /^an?_(.*)/;
129 $data_type =~ s/_/ /g;
131 ok((not exists $rsrc->column_info($col)->{size}),
133 (exists $with_precision{$col} ? 'without precision ' : '') .
134 "has no 'size' column_info")
135 or diag "size is ".$rsrc->column_info($col)->{size}."\n";
138 for my $col (@with_precision) {
139 my ($data_type) = $col =~ /^an?_(.*)_with_precision\z/;
140 ($data_type = uc $data_type) =~ s/_/ /g;
141 my $size = $rsrc->column_info($col)->{size};
144 "$data_type with precision has a correct 'size' column_info";
147 is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3],
148 'size for NUMERIC(precision, scale) is correct';
150 is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3],
151 'size for DECIMAL(precision, scale) is correct';
157 if( !$dsn || !$user ) {
158 $tester->skip_tests('You need to set the DBICTEST_SYBASE_DSN, _USER, and _PASS environment variables');
161 $tester->run_tests();