Showing 4 changed files with 102 additions and 43 deletions
+9 -1
lib/DBIx/Custom.pm
... ...
@@ -299,13 +299,21 @@ sub each_column {
299 299
 
300 300
     my $re = $self->exclude_table;
301 301
     
302
+    my %tables;
303
+    
302 304
     # Iterate all tables
303 305
     my $sth_tables = $self->dbh->table_info;
304 306
     while (my $table_info = $sth_tables->fetchrow_hashref) {
305
-        
306 307
         # Table
307 308
         my $table = $table_info->{TABLE_NAME};
308 309
         next if defined $re && $table =~ /$re/;
310
+        $tables{$table}++;
311
+    }
312
+
313
+    # Iterate all tables
314
+    my @tables = sort keys %tables;
315
+    for (my $i = 0; $i < @tables; $i++) {
316
+        my $table = $tables[$i];
309 317
         
310 318
         # Iterate all columns
311 319
         my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
+44
t/common-sqlserver.t
... ...
@@ -0,0 +1,44 @@
1
+use strict;
2
+use warnings;
3
+
4
+use FindBin;
5
+$ENV{DBIX_CUSTOM_TEST_RUN} = 1
6
+  if -f "$FindBin::Bin/run/common-postgresql.run";
7
+$ENV{DBIX_CUSTOM_SKIP_MESSAGE} = 'postgresql private test';
8
+
9
+use DBIx::Custom;
10
+{
11
+    package DBIx::Custom;
12
+    no warnings 'redefine';
13
+
14
+    my $date_typename = 'date';
15
+    my $datetime_typename = 'datetime';
16
+
17
+    sub date_typename { lc $date_typename }
18
+    sub datetime_typename { lc $datetime_typename }
19
+
20
+    my $date_datatype = 91;
21
+    my $datetime_datatype = 11;
22
+
23
+    sub date_datatype { lc $date_datatype }
24
+    sub datetime_datatype { lc $datetime_datatype }
25
+    
26
+    my $dsn = "dbi:ODBC:driver={SQL Server};Server={localhost\\SQLEXPRESS};"
27
+      . "Trusted_Connection=No;AutoTranslate=No;Database=dbix_custom;";
28
+    has dsn => $dsn;
29
+    has user  => 'dbix_custom';
30
+    has password => 'dbix_custom';
31
+    
32
+    sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255));' }
33
+    sub create_table1_2 {'create table table1 (key1 varchar(255), key2 varchar(255), '
34
+     . 'key3 varchar(255), key4 varchar(255), key5 varchar(255));' }
35
+    sub create_table1_type { "create table table1 (key1 $date_typename, key2 $datetime_typename);" }
36
+    sub create_table1_highperformance { "create table table1 (ab varchar(255), bc varchar(255), "
37
+      . "ik varchar(255), hi varchar(255), ui varchar(255), pq varchar(255), dc varchar(255));" }
38
+    sub create_table2 { 'create table table2 (key1 varchar(255), key3 varchar(255));' }
39
+    sub create_table2_2 { "create table table2 (key1 varchar(255), key2 varchar(255), key3 varchar(255))" }
40
+    sub create_table3 { "create table table3 (key1 varchar(255), key2 varchar(255), key3 varchar(255))" }
41
+    sub create_table_reserved { 'create table "table" ("select" varchar(255), "update" varchar(255))' }
42
+}
43
+
44
+require "$FindBin::Bin/common.t";
+2 -42
t/common.t
... ...
@@ -155,10 +155,8 @@ my $create_table_reserved = $dbi->create_table_reserved;
155 155
 my $q = substr($dbi->quote, 0, 1);
156 156
 my $p = substr($dbi->quote, 1, 1) || $q;
157 157
 my $date_typename = $dbi->date_typename;
158
-my $time_typename = $dbi->time_typename;
159 158
 my $datetime_typename = $dbi->datetime_typename;
160 159
 my $date_datatype = $dbi->date_datatype;
161
-my $time_datatype = $dbi->time_datatype;
162 160
 my $datetime_datatype = $dbi->datetime_datatype;
163 161
 
164 162
 # Variable
... ...
@@ -193,6 +191,7 @@ my $insert_param;
193 191
 my $join;
194 192
 my $binary;
195 193
 
194
+
196 195
 # Drop table
197 196
 eval { $dbi->execute('drop table table1') };
198 197
 
... ...
@@ -200,6 +199,7 @@ test 'type_rule into';
200 199
 $dbi = DBIx::Custom->connect;
201 200
 eval { $dbi->execute('drop table table1') };
202 201
 $dbi->execute($create_table1_type);
202
+$DB::single = 1;
203 203
 $dbi->type_rule(
204 204
     into1 => {
205 205
         $date_typename => sub { '2010-' . $_[0] }
... ...
@@ -1143,9 +1143,6 @@ is_deeply($rows, [{key1 => 1, key2 => 2}], "table and columns and where key");
1143 1143
 $rows = $dbi->select(table => 'table1', column => ['key1'], where => {key1 => 3})->all;
1144 1144
 is_deeply($rows, [{key1 => 3}], "table and columns and where key");
1145 1145
 
1146
-$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->all;
1147
-is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
1148
-
1149 1146
 $dbi->register_filter(decrement => sub { $_[0] - 1 });
1150 1147
 $rows = $dbi->select(table => 'table1', where => {key1 => 2}, filter => {key1 => 'decrement'})
1151 1148
             ->all;
... ...
@@ -1553,43 +1550,6 @@ is_deeply($infos,
1553 1550
     ]
1554 1551
 );
1555 1552
 
1556
-test 'limit';
1557
-$dbi = DBIx::Custom->connect;
1558
-eval { $dbi->execute('drop table table1') };
1559
-$dbi->execute($create_table1);
1560
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1561
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
1562
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
1563
-$dbi->register_tag(
1564
-    limit => sub {
1565
-        my ($count, $offset) = @_;
1566
-        
1567
-        my $s = '';
1568
-        $s .= "limit $count";
1569
-        $s .= " offset $offset" if defined $offset;
1570
-        
1571
-        return [$s, []];
1572
-    }
1573
-);
1574
-$rows = $dbi->select(
1575
-  table => 'table1',
1576
-  where => {key1 => 1},
1577
-  append => "order by key2 {limit 1 0}"
1578
-)->all;
1579
-is_deeply($rows, [{key1 => 1, key2 => 2}]);
1580
-$rows = $dbi->select(
1581
-  table => 'table1',
1582
-  where => {key1 => 1},
1583
-  append => "order by key2 {limit 2 1}"
1584
-)->all;
1585
-is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
1586
-$rows = $dbi->select(
1587
-  table => 'table1',
1588
-  where => {key1 => 1},
1589
-  append => "order by key2 {limit 1}"
1590
-)->all;
1591
-is_deeply($rows, [{key1 => 1, key2 => 2}]);
1592
-
1593 1553
 test 'connect super';
1594 1554
 $dbi = DBIx::Custom->connect;
1595 1555
 eval { $dbi->execute('drop table table1') };
+47
t/sqlite.t
... ...
@@ -172,6 +172,16 @@ is($result->fetch_first->[0], 'A');
172 172
 $result = $dbi->select(table => 'table1');
173 173
 is($result->one->{key1}, 'A');
174 174
 
175
+test 'select limit';
176
+eval { $dbi->execute('drop table table1') };
177
+$dbi->execute($create_table1);
178
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
179
+$dbi->insert(table => 'table1', param => {key1 => 3, key2 => 4});
180
+$rows = $dbi->select(table => 'table1', append => "order by key1 desc limit 1")->all;
181
+is_deeply($rows, [{key1 => 3, key2 => 4}], "append statement");
182
+
183
+
184
+
175 185
 # DEPRECATED! test
176 186
 test 'filter __ expression';
177 187
 $dbi = DBIx::Custom->connect;
... ...
@@ -216,3 +226,40 @@ $dbi->update(table => 'table', where => {'table.select' => 1}, param => {update
216 226
 $result = $dbi->execute("select * from ${q}table$p");
217 227
 $rows   = $result->all;
218 228
 is_deeply($rows, [{select => 2, update => 6}], "reserved word");
229
+
230
+test 'limit tag';
231
+$dbi = DBIx::Custom->connect;
232
+eval { $dbi->execute('drop table table1') };
233
+$dbi->execute($create_table1);
234
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
235
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 4});
236
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 6});
237
+$dbi->register_tag(
238
+    limit => sub {
239
+        my ($count, $offset) = @_;
240
+        
241
+        my $s = '';
242
+        $s .= "limit $count";
243
+        $s .= " offset $offset" if defined $offset;
244
+        
245
+        return [$s, []];
246
+    }
247
+);
248
+$rows = $dbi->select(
249
+  table => 'table1',
250
+  where => {key1 => 1},
251
+  append => "order by key2 {limit 1 0}"
252
+)->all;
253
+is_deeply($rows, [{key1 => 1, key2 => 2}]);
254
+$rows = $dbi->select(
255
+  table => 'table1',
256
+  where => {key1 => 1},
257
+  append => "order by key2 {limit 2 1}"
258
+)->all;
259
+is_deeply($rows, [{key1 => 1, key2 => 4},{key1 => 1, key2 => 6}]);
260
+$rows = $dbi->select(
261
+  table => 'table1',
262
+  where => {key1 => 1},
263
+  append => "order by key2 {limit 1}"
264
+)->all;
265
+is_deeply($rows, [{key1 => 1, key2 => 2}]);