Showing 5 changed files with 63 additions and 98 deletions
+2
Changes
... ...
@@ -2,6 +2,8 @@
2 2
     - you can set any string as separator
3 3
     - fixed memory leak and connection increasing bug, and query_buider method return new object.
4 4
     - added EXPERIMENTAL exclude_table attribute
5
+    - added EXPERIMENTAL show_typename method
6
+    - added EXPERIMENTAL show_datatype method
5 7
 0.1711
6 8
     - renamed EXPERIMENTAL available_type_name to available_typename
7 9
     - renamed EXPERIMENTAL available_data_type to available_datatype
+58 -13
lib/DBIx/Custom.pm
... ...
@@ -73,16 +73,6 @@ sub available_datatype {
73 73
     return $data_types;
74 74
 }
75 75
 
76
-sub show_datatype {
77
-    my ($self, $table) = @_;
78
-    
79
-    
80
-}
81
-
82
-sub show_typename {
83
-    
84
-}
85
-
86 76
 sub available_typename {
87 77
     my $self = shift;
88 78
     
... ...
@@ -320,9 +310,6 @@ sub each_column {
320 310
     }
321 311
 }
322 312
 
323
-
324
-
325
-
326 313
 sub each_table {
327 314
     my ($self, $cb) = @_;
328 315
     
... ...
@@ -949,6 +936,39 @@ sub setup_model {
949 936
     return $self;
950 937
 }
951 938
 
939
+sub show_datatype {
940
+    my ($self, $table) = @_;
941
+    croak "Table name must be specified" unless defined $table;
942
+    print "$table\n";
943
+    
944
+    my $result = $self->select(table => $table, where => "'0' <> '0'");
945
+    my $sth = $result->sth;
946
+
947
+    my $columns = $sth->{NAME};
948
+    my $data_types = $sth->{TYPE};
949
+    
950
+    for (my $i = 0; $i < @$columns; $i++) {
951
+        my $column = $columns->[$i];
952
+        my $data_type = $data_types->[$i];
953
+        print "$column: $data_type\n";
954
+    }
955
+}
956
+
957
+sub show_typename {
958
+    my ($self, $t) = @_;
959
+    croak "Table name must be specified" unless defined $t;
960
+    print "$t\n";
961
+    
962
+    $self->each_column(sub {
963
+        my ($self, $table, $column, $infos) = @_;
964
+        return unless $table eq $t;
965
+        my $typename = $infos->{TYPE_NAME};
966
+        print "$column: $typename\n";
967
+    });
968
+    
969
+    return $self;
970
+}
971
+
952 972
 sub type_rule {
953 973
     my $self = shift;
954 974
     
... ...
@@ -3124,6 +3144,30 @@ C<columns> of model object is automatically set, parsing database information.
3124 3144
 If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3125 3145
 executed SQL and bind values are printed to STDERR.
3126 3146
 
3147
+=head2 C<show_datatype EXPERIMENTAL>
3148
+
3149
+    $dbi->show_datatype($table);
3150
+
3151
+Show data type of the columns of specified table.
3152
+
3153
+    book
3154
+    title: 5
3155
+    issue_date: 91
3156
+
3157
+This data type is used in C<type_rule>'s C<from1> and C<from2>.
3158
+
3159
+=head2 C<show_typename EXPERIMENTAL>
3160
+
3161
+    $dbi->show_typename($table);
3162
+
3163
+Show type name of the columns of specified table.
3164
+
3165
+    book
3166
+    title: varchar
3167
+    issue_date: date
3168
+
3169
+This type name is used in C<type_rule>'s C<into1> and C<into2>.
3170
+
3127 3171
 =head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3128 3172
 
3129 3173
 DEBUG output encoding. Default to UTF-8.
... ...
@@ -3150,6 +3194,7 @@ L<DBIx::Custom>
3150 3194
     default_bind_filter # will be removed at 2017/1/1
3151 3195
     default_fetch_filter # will be removed at 2017/1/1
3152 3196
     insert_param_tag # will be removed at 2017/1/1
3197
+    register_tag # will be removed at 2017/1/1
3153 3198
     register_tag_processor # will be removed at 2017/1/1
3154 3199
     update_param_tag # will be removed at 2017/1/1
3155 3200
     
+2 -1
t/common-postgresql.t
... ...
@@ -30,7 +30,7 @@ use DBIx::Custom;
30 30
     has dsn => "dbi:Pg:dbname=dbix_custom";
31 31
     has user  => 'dbix_custom';
32 32
     has password => 'dbix_custom';
33
-    has system_table => sub {
33
+    has exclude_table => sub {
34 34
 
35 35
         return qr/^(
36 36
             pg_|column_|role_|view_|sql_
... ...
@@ -45,6 +45,7 @@ use DBIx::Custom;
45 45
             |domains
46 46
             |element_types
47 47
             |enabled_roles
48
+            |information_schema
48 49
             |information_schema_catalog_name
49 50
             |key_column_usage
50 51
             |parameters
+1 -13
t/common.t
... ...
@@ -195,23 +195,11 @@ my $binary;
195 195
 # Drop table
196 196
 eval { $dbi->execute('drop table table1') };
197 197
 
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211 198
 test 'type_rule into';
212 199
 $dbi = DBIx::Custom->connect;
213 200
 eval { $dbi->execute('drop table table1') };
214 201
 $dbi->execute($create_table1_type);
202
+$DB::single = 1;
215 203
 $dbi->type_rule(
216 204
     into1 => {
217 205
         $date_typename => sub { '2010-' . $_[0] }
-71
t/sqlite.t
... ...
@@ -179,78 +179,7 @@ my $binary;
179 179
 $dbi = DBIx::Custom->connect;
180 180
 
181 181
 ### a little complex test
182
-test 'type_rule into';
183
-$dbi = DBIx::Custom->connect;
184
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
185
-$dbi->type_rule(
186
-    into1 => {
187
-        date => sub { uc $_[0] }
188
-    }
189
-);
190
-$dbi->insert({key1 => 'a'}, table => 'table1');
191
-$result = $dbi->select(table => 'table1');
192
-is($result->one->{key1}, 'A');
193 182
 
194
-$dbi = DBIx::Custom->connect;
195
-$dbi->execute("create table table1 (key1 date, key2 datetime)");
196
-$dbi->type_rule(
197
-    into1 => [
198
-         [qw/date datetime/] => sub { uc $_[0] }
199
-    ]
200
-);
201
-$dbi->insert({key1 => 'a', key2 => 'b'}, table => 'table1');
202
-$result = $dbi->select(table => 'table1');
203
-$row = $result->one;
204
-is($row->{key1}, 'A');
205
-is($row->{key2}, 'B');
206
-
207
-$dbi = DBIx::Custom->connect;
208
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
209
-$dbi->insert({key1 => 'a', key2 => 'B'}, table => 'table1');
210
-$dbi->type_rule(
211
-    into1 => [
212
-        [qw/date datetime/] => sub { uc $_[0] }
213
-    ]
214
-);
215
-$result = $dbi->execute(
216
-    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
217
-    param => {key1 => 'a', 'table1.key2' => 'b'}
218
-);
219
-$row = $result->one;
220
-is($row->{key1}, 'a');
221
-is($row->{key2}, 'B');
222
-
223
-$dbi = DBIx::Custom->connect;
224
-$dbi->execute("create table table1 (key1 Date, key2 datetime)");
225
-$dbi->insert({key1 => 'A', key2 => 'B'}, table => 'table1');
226
-$dbi->type_rule(
227
-    into1 => [
228
-        [qw/date datetime/] => sub { uc $_[0] }
229
-    ]
230
-);
231
-$result = $dbi->execute(
232
-    "select * from table1 where key1 = :key1 and key2 = :table1.key2;",
233
-    param => {key1 => 'a', 'table1.key2' => 'b'},
234
-    table => 'table1'
235
-);
236
-$row = $result->one;
237
-is($row->{key1}, 'A');
238
-is($row->{key2}, 'B');
239
-
240
-$dbi = DBIx::Custom->connect;
241
-$dbi->execute("create table table1 (key1 date, key2 datetime)");
242
-$dbi->register_filter(twice => sub { $_[0] * 2 });
243
-$dbi->type_rule(
244
-    from1 => {
245
-        date => 'twice',
246
-    },
247
-    into1 => {
248
-        date => 'twice',
249
-    }
250
-);
251
-$dbi->insert({key1 => 2}, table => 'table1');
252
-$result = $dbi->select(table => 'table1');
253
-is($result->fetch->[0], 8);
254 183
 
255 184
 test 'type_rule and filter order';
256 185
 $dbi = DBIx::Custom->connect;