1 package SQL::Translator::Producer;
11 # Do not rely on this if you are not bundled with SQL::Translator.
13 ## $exceptions contains an arrayref of paired values
14 ## Each pair contains a pattern match or string, and a value to be used as
15 ## the default if matched.
16 ## They are special per Producer, and provide support for the old 'now()'
17 ## default value exceptions
18 sub _apply_default_value {
19 my (undef, $field, $field_ref, $exceptions) = @_;
20 my $default = $field->default_value;
21 return if !defined $default;
23 if ($exceptions and ! ref $default) {
24 for (my $i = 0; $i < @$exceptions; $i += 2) {
25 my ($pat, $val) = @$exceptions[ $i, $i + 1 ];
26 if (ref $pat and $default =~ $pat) {
29 } elsif (lc $default eq lc $pat) {
36 my $type = lc $field->data_type;
37 my $is_numeric_datatype = ($type =~ /^(?:(?:big|medium|small|tiny)?int(?:eger)?|decimal|double|float|num(?:ber|eric)?|real)$/);
40 $$field_ref .= " DEFAULT $$default";
41 } elsif ($is_numeric_datatype && Scalar::Util::looks_like_number ($default) ) {
42 # we need to check the data itself in addition to the datatype, for basic safety
43 $$field_ref .= " DEFAULT $default";
45 $$field_ref .= " DEFAULT '$default'";
52 # -------------------------------------------------------------------
53 # A burnt child loves the fire.
55 # -------------------------------------------------------------------
61 SQL::Translator::Producer - describes how to write a producer
65 Producer modules designed to be used with SQL::Translator need to
66 implement a single function, called B<produce>. B<produce> will be
67 called with the SQL::Translator object from which it is expected to
68 retrieve the SQL::Translator::Schema object which has been populated
69 by the parser. It is expected to return a string.
77 =item create_table($table)
79 =item create_field($field)
81 =item create_view($view)
83 =item create_index($index)
85 =item create_constraint($constraint)
87 =item create_trigger($trigger)
89 =item alter_field($from_field, $to_field)
91 =item add_field($table, $new_field)
93 =item drop_field($table, $old_field)
99 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
100 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
104 perl(1), SQL::Translator, SQL::Translator::Schema.