Commit | Line | Data |
fe67d343 |
1 | use strict; |
2 | use lib qw(t/lib); |
3 | use dbixcsl_common_tests; |
804c115d |
4 | use Test::More; |
2d1dc6de |
5 | use Test::Exception; |
6ecee584 |
6 | use List::MoreUtils 'apply'; |
f9f65ded |
7 | |
fe67d343 |
8 | my $dsn = $ENV{DBICTEST_SYBASE_DSN} || ''; |
9 | my $user = $ENV{DBICTEST_SYBASE_USER} || ''; |
10 | my $password = $ENV{DBICTEST_SYBASE_PASS} || ''; |
11 | |
12 | my $tester = dbixcsl_common_tests->new( |
7cb9244f |
13 | vendor => 'sybase', |
fe67d343 |
14 | auto_inc_pk => 'INTEGER IDENTITY NOT NULL PRIMARY KEY', |
41968729 |
15 | default_function => 'getdate()', |
16 | default_function_def => 'AS getdate()', |
fe67d343 |
17 | dsn => $dsn, |
18 | user => $user, |
19 | password => $password, |
804c115d |
20 | extra => { |
21 | create => [ |
22 | q{ |
23 | CREATE TABLE sybase_loader_test1 ( |
24 | id INTEGER IDENTITY NOT NULL PRIMARY KEY, |
de82711a |
25 | ts timestamp, |
de82711a |
26 | computed_dt AS getdate() |
804c115d |
27 | ) |
28 | }, |
6ecee584 |
29 | # Test data types, see http://ispirer.com/wiki/sqlways/sybase/data-types |
30 | # XXX handle FLOAT(P) at some point |
ca7feebf |
31 | # ( http://msdn.microsoft.com/en-us/library/aa258876(SQL.80).aspx ) |
6ecee584 |
32 | q{ |
33 | CREATE TABLE sybase_loader_test2 ( |
34 | id INTEGER IDENTITY NOT NULL PRIMARY KEY, |
35 | a_text TEXT, |
36 | a_unitext UNITEXT, |
37 | an_image IMAGE, |
38 | a_bigint BIGINT, |
39 | an_int INT, |
40 | an_integer INTEGER, |
41 | a_smallint SMALLINT, |
42 | a_tinyint TINYINT, |
43 | a_real REAL, |
44 | a_double_precision DOUBLE PRECISION, |
45 | a_date DATE, |
46 | a_time TIME, |
47 | a_datetime DATETIME, |
48 | a_smalldatetime SMALLDATETIME, |
49 | a_money MONEY, |
50 | a_smallmoney SMALLMONEY, |
51 | a_timestamp timestamp, |
52 | a_bit BIT, |
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), |
59 | a_float FLOAT, |
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) |
64 | ) |
65 | }, |
804c115d |
66 | ], |
6ecee584 |
67 | drop => [ qw/ sybase_loader_test1 sybase_loader_test2 / ], |
41968729 |
68 | count => 36, |
804c115d |
69 | run => sub { |
70 | my ($schema, $monikers, $classes) = @_; |
71 | |
72 | my $rs = $schema->resultset($monikers->{sybase_loader_test1}); |
de82711a |
73 | my $rsrc = $rs->result_source; |
74 | |
75 | is $rsrc->column_info('id')->{data_type}, |
2fb9a4b3 |
76 | 'int', |
de82711a |
77 | 'INTEGER IDENTITY data_type is correct'; |
78 | |
79 | is $rsrc->column_info('id')->{is_auto_increment}, |
80 | 1, |
81 | 'INTEGER IDENTITY is_auto_increment => 1'; |
804c115d |
82 | |
2fb9a4b3 |
83 | is $rsrc->column_info('ts')->{data_type}, |
84 | 'timestamp', |
85 | 'timestamps have the correct data_type'; |
de82711a |
86 | |
41968729 |
87 | is $rsrc->column_info('ts')->{inflate_datetime}, |
88 | 0, |
89 | 'timestamps have inflate_datetime => 0'; |
de82711a |
90 | |
db4d62ad |
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} |
96 | ; |
2d1dc6de |
97 | |
2fb9a4b3 |
98 | my $computed_dt_default = |
99 | $rsrc->column_info('computed_dt')->{default_value}; |
2d1dc6de |
100 | |
2fb9a4b3 |
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 |
104 | ; |
2d1dc6de |
105 | |
2fb9a4b3 |
106 | eval { is $$computed_dt_default, |
107 | 'getdate()', |
108 | 'default_value for computed column is correct' }; |
6ecee584 |
109 | |
110 | $rsrc = $schema->resultset($monikers->{sybase_loader_test2}) |
111 | ->result_source; |
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; |
115 | my %with_precision; |
116 | @with_precision{ |
117 | apply { s/_with_precision\z// } @with_precision |
118 | } = (); |
119 | |
120 | for my $col (@without_precision) { |
121 | my ($data_type) = $col =~ /^an?_(.*)/; |
122 | $data_type =~ s/_/ /g; |
123 | |
124 | ok((not exists $rsrc->column_info($col)->{size}), |
125 | "$data_type " . |
126 | (exists $with_precision{$col} ? 'without precision ' : '') . |
127 | "has no 'size' column_info") |
128 | or diag "size is ".$rsrc->column_info($col)->{size}."\n"; |
129 | } |
130 | |
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}; |
135 | |
136 | is $size, 2, |
137 | "$data_type with precision has a correct 'size' column_info"; |
138 | } |
139 | |
140 | is_deeply $rsrc->column_info('the_numeric')->{size}, [6,3], |
141 | 'size for NUMERIC(precision, scale) is correct'; |
142 | |
143 | is_deeply $rsrc->column_info('the_decimal')->{size}, [6,3], |
144 | 'size for DECIMAL(precision, scale) is correct'; |
145 | |
804c115d |
146 | }, |
147 | }, |
fe67d343 |
148 | ); |
149 | |
150 | if( !$dsn || !$user ) { |
151 | $tester->skip_tests('You need to set the DBICTEST_SYBASE_DSN, _USER, and _PASS environment variables'); |
152 | } |
153 | else { |
154 | $tester->run_tests(); |
155 | } |