abstraction on "create table" statement
am 06.09.2006 14:59:34 von plegallHi dbi-users list,
I'm coding a tool which should eventually be able to connect to as many
DBMS as Perl DBI let do. I have a generic graphical interface where I
set a list of columns and their types. I would like to give this list
of columns and to get back a "create table" SQL statement.
In the following example, I would like to find a CPAN module with the
get_create_table function.
my $columns = [
{
name => 'shop_code',
key => 1,
type => 'integer',
len => undef,
null => 0,
default => '',
comment => 'Code of the shop',
},
{
name => 'ean',
key => 1,
type => 'string',
len => undef,
null => 0,
default => '',
comment => 'European Article Number',
},
{
name => 'sales',
key => 0,
type => 'integer',
len => undef,
null => 1,
default => undef,
comment => 'how much was sold',
},
{
name => 'quantity',
key => 0,
type => 'integer',
len => undef,
null => 1,
default => undef,
comment => 'how many were sold',
},
];
my $query = get_create_table(
table => 'article',
dbtype => 'mysql', # Oracle, PostgreSQL, DB2...
columns => $columns,
);
# $query should contain something like this
#
# CREATE TABLE `article` (
# `shop_code` int(11) NOT NULL COMMENT 'Code of the shop',
# `ean` varchar(255) NOT NULL COMMENT 'European Article Number',
# `sales` int(11) default NULL COMMENT 'how much was sold',
# `quantity` int(11) default NULL COMMENT 'how many were sold',
# PRIMARY KEY (`shop_code`,`ean`)
# )
Do you have an idea which CPAN modules can do that? I've seen Alzabo
should be able to do it, any other suggestion?
--
Pierrick LE GALL
R&D engineer at Talend, Open data solution
http://talend.com