| FabForce-DBDesigner4 documentation | Contained in the FabForce-DBDesigner4 distribution. |
FabForce::DBDesigner4::SQL::Mysql
version 0.306
my $create_stmt = FabForce::DBDesigner4::SQL::Mysql->create_table( $fabforce_table_object );
As each database system has its own syntax, it is important to provide functions for each system.
FabForce::DBDesigner4::SQL::Mysql - create sql with mysql specific syntax
my $create_stmt = FabForce::DBDesigner4::SQL::Mysql->create_table( $fabforce_table_object );
Things it does:
create a "drop table" statement for the given tablename
$class->drop_table( $fabforce_table_object );
returns
DROP TABLE IF EXISTS `tablename`
Renee Baecker, <module@renee-baecker.de>
Copyright (C) 2005 - 2009 by Renee Baecker
This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Renee Baecker <module@renee-baecker.de>
This software is Copyright (c) 2010 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0
| FabForce-DBDesigner4 documentation | Contained in the FabForce-DBDesigner4 distribution. |
package FabForce::DBDesigner4::SQL::Mysql; use strict; use warnings; our $VERSION = '0.02'; sub create_table { my ($class,$table,$options) = @_; my @columns = $table->columns(); my $tablename = $table->name(); my $cols_string = join(",\n ",@columns); $cols_string =~ s!\s+\z!!; $cols_string =~ s!AUTOINCREMENT!AUTO_INCREMENT!g; my $options_string = ""; if ( $options and ref $options ) { my @options; if( $options->{engine} ) { push @options, 'ENGINE=' . $options->{engine}; } if( $options->{charset} ) { push @options, 'DEFAULT CHARSET=' . $options->{charset}; } $options_string = join ' ', @options; } my $stmt = "CREATE TABLE `$tablename` (\n $cols_string,\n "; $stmt .= "PRIMARY KEY(" . join( ",", $table->key ) . "),\n " if scalar( $table->key ) > 0; $stmt =~ s!,\n\s\s\z!\n!; $stmt .= ")$options_string;\n\n"; } sub drop_table { my ($class,$table,$options) = @_; my $name = $table->name; my $stmt = qq~DROP TABLE IF EXISTS `$name`;\n\n~; $stmt; } 1;
__END__