package SQL::Translator::Producer::MySQL;
# -------------------------------------------------------------------
-# $Id: MySQL.pm,v 1.54 2007-11-10 03:36:43 mwz444 Exp $
-# -------------------------------------------------------------------
-# Copyright (C) 2002-4 SQLFairy Authors
+# Copyright (C) 2002-2009 SQLFairy Authors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
use strict;
use warnings;
use vars qw[ $VERSION $DEBUG %used_names ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.54 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
$DEBUG = 0 unless defined $DEBUG;
# Maximum length for most identifiers is 64, according to:
'long integer' => 'integer',
'text' => 'text',
'datetime' => 'datetime',
+
+ #
+ # PostgreSQL types
+ #
+ bytea => 'BLOB',
);
my $qt = $options->{quote_table_names} || '';
my $qf = $options->{quote_field_names} || '';
- my $table_name = $table->name;
+ my $table_name = quote_table_name($table->name, $qt);
debug("PKG: Looking at table '$table_name'\n");
#
#
my $create = '';
my $drop;
- $create .= "--\n-- Table: $qt$table_name$qt\n--\n" unless $options->{no_comments};
- $drop = qq[DROP TABLE IF EXISTS $qt$table_name$qt] if $options->{add_drop_table};
- $create .= "CREATE TABLE $qt$table_name$qt (\n";
+ $create .= "--\n-- Table: $table_name\n--\n" unless $options->{no_comments};
+ $drop = qq[DROP TABLE IF EXISTS $table_name] if $options->{add_drop_table};
+ $create .= "CREATE TABLE $table_name (\n";
#
# Fields
return $drop ? ($drop,$create) : $create;
}
+sub quote_table_name {
+ my ($table_name, $qt) = @_;
+
+ $table_name =~ s/\./$qt.$qt/g;
+
+ return "$qt$table_name$qt";
+}
+
sub generate_table_options
{
my ($table, $options) = @_;
[
'NULL' => \'NULL',
],
- [
- 'CURRENT_TIMESTAMP'
- ],
);
}