in reply to Re^2: CREATE TABLE DDL from DBI Statement
in thread CREATE TABLE DDL from DBI Statement
You definitely need something like SQL::Translator. It will read the table structure of your database and save it in an internal representation: that is wat the SQL::Translator::Parser::name_your_database_here does. Next you call SQL::Translator::Producer::name_your_other_database_here on this internal object and it will make you the SQL to build the structure to do so. Changing databases is as easy as replacing the type of the database in 'to'.
Good thing is that there are parsers and producers for DB2!
SQL::Translator is a big module but it pays to have a look at it.
The full program could be as easy as:
use strict; use SQL::Translator; my $translator = SQL::Translator->new( add_drop_table => 1, no_comments => 0, show_warnings => 1, quote_table_names => 1, quote_field_names => 1, from => 'DBI', parser_args => { dsn => 'dbi:DB2:Your_Database;host=Your_Host', db_user => 'user', db_password => 'password', }, to => 'SQLite', ); my $output = $translator->translate or die $translator->error; print $output;
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: CREATE TABLE DDL from DBI Statement
by whereiskurt (Friar) on Jul 22, 2008 at 13:08 UTC | |
|
Re^4: CREATE TABLE DDL from DBI Statement
by whereiskurt (Friar) on Jul 22, 2008 at 21:09 UTC |