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 ($self, $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 $default = $self->_quote_string($default);
45 $$field_ref .= " DEFAULT $default";
51 my ($self, $string) = @_;
58 # -------------------------------------------------------------------
59 # A burnt child loves the fire.
61 # -------------------------------------------------------------------
67 SQL::Translator::Producer - describes how to write a producer
71 Producer modules designed to be used with SQL::Translator need to
72 implement a single function, called B<produce>. B<produce> will be
73 called with the SQL::Translator object from which it is expected to
74 retrieve the SQL::Translator::Schema object which has been populated
75 by the parser. It is expected to return a string.
83 =item create_table($table)
85 =item create_field($field)
87 =item create_view($view)
89 =item create_index($index)
91 =item create_constraint($constraint)
93 =item create_trigger($trigger)
95 =item alter_field($from_field, $to_field)
97 =item add_field($table, $new_field)
99 =item drop_field($table, $old_field)
105 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
106 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
110 perl(1), SQL::Translator, SQL::Translator::Schema.