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