Skip to content

Commit

Permalink
Merge 010b5b1 into d5103d9
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Aug 26, 2015
2 parents d5103d9 + 010b5b1 commit 507c7e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following people have contributed to the SQLFairy project:
- Stephen Bennett <stephen@freenode.net>
- Stephen Clouse <stephenclouse@gmail.com>
- SymKat <symkat@symkat.com>
- Tina Müller <tinita@cpan.org>
- Tina Müller <cpan2@tinita.de>
- Vincent Bachelier <geistteufel@yahoo.fr>
- Wallace Reis <wreis@cpan.org>
- William Wolf <throughnothing@gmail.com>
Expand Down
44 changes: 24 additions & 20 deletions lib/SQL/Translator/Producer/Sybase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ sub produce {
my $add_drop_table = $translator->add_drop_table;
my $schema = $translator->schema;

my $output;
$output .= header_comment unless ($no_comments);
my @output;
push @output, header_comment unless ($no_comments);

my @foreign_keys;

for my $table ( $schema->get_tables ) {
my $table_name = $table->name or next;
Expand Down Expand Up @@ -163,6 +165,8 @@ sub produce {
my $commalist = join( ', ', map { qq['$_'] } @$list );
my $seq_name;

my $identity = '';

if ( $data_type eq 'enum' ) {
my $check_name = mk_name(
$table_name.'_'.$field_name, 'chk' ,undef, 1
Expand All @@ -174,10 +178,10 @@ sub produce {
elsif ( $data_type eq 'set' ) {
$data_type .= 'character varying';
}
elsif ( $field->is_auto_increment ) {
$field_def .= ' IDENTITY';
}
else {
if ( $field->is_auto_increment ) {
$identity = 'IDENTITY';
}
if ( defined $translate{ $data_type } ) {
$data_type = $translate{ $data_type };
}
Expand Down Expand Up @@ -209,6 +213,7 @@ sub produce {

$field_def .= " $data_type";
$field_def .= "($size)" if $size;
$field_def .= " $identity" if $identity;

#
# Default value
Expand Down Expand Up @@ -257,8 +262,8 @@ sub produce {
}
elsif ( $type eq FOREIGN_KEY ) {
$name ||= mk_name( $table_name, 'fk', undef,1 );
push @constraint_defs,
"CONSTRAINT $name FOREIGN KEY".
push @foreign_keys,
"ALTER TABLE $table ADD CONSTRAINT $name FOREIGN KEY".
' (' . join( ', ', @fields ) . ') REFERENCES '.
$constraint->reference_table.
' (' . join( ', ', @rfields ) . ')';
Expand All @@ -281,25 +286,23 @@ sub produce {
push @index_defs,
'CREATE INDEX ' . $index->name .
" ON $table_name (".
join( ', ', $index->fields ) . ");";
join( ', ', $index->fields ) . ")";
}

my $create_statement;
$create_statement = qq[DROP TABLE $table_name_ur;\n]
if $add_drop_table;
$create_statement .= qq[CREATE TABLE $table_name_ur (\n].
my $drop_statement = $add_drop_table
? qq[DROP TABLE $table_name_ur] : '';
my $create_statement = qq[CREATE TABLE $table_name_ur (\n].
join( ",\n",
map { " $_" } @field_defs, @constraint_defs
).
"\n);"
"\n)"
;

$output .= join( "\n\n",
@comments,
$create_statement = join("\n\n", @comments) . "\n\n" . $create_statement;
push @output,
$create_statement,
@index_defs,
''
);
;
}

foreach my $view ( $schema->get_views ) {
Expand All @@ -311,7 +314,7 @@ sub produce {
# text of view is already a 'create view' statement so no need
# to do anything fancy.

$output .= join("\n\n",
push @output, join("\n\n",
@comments,
$view->sql(),
);
Expand All @@ -330,11 +333,12 @@ sub produce {
# think about doing fancy stuff with granting permissions and
# so on.

$output .= join("\n\n",
push @output, join("\n\n",
@comments,
$procedure->sql(),
);
}
push @output, @foreign_keys;

if ( $WARN ) {
if ( %truncated ) {
Expand All @@ -349,7 +353,7 @@ sub produce {
}
}

return $output;
return wantarray ? @output : join ";\n\n", @output;
}

sub mk_name {
Expand Down

0 comments on commit 507c7e7

Please sign in to comment.