In this tutorial I'll show you how to modify dbtoy's output, using custom stylesheets.
As of release 0.6, dbtoy lets you insert a fragment of your choice in its xml files, between the header
and the root tag. This feature can be used to add a reference to an xsl stylesheet to all the files, another use
could be the insertion of a disclaimer or a comment.
To add a stylesheet to dbtoy files, just add the '-x' option to your command line arguments, e.g.:
[user@testlinux]$ dbtoy -u user -p my_pwd -d mysql -x'<?xml-stylesheet type="text/xsl" href="file:///path/to/file.xsl"?>' /mnt/dbtoy
In this second example, I'll show you how to generate SQL code from dbtoy xml files. Data files will be transformed in a sequence of insert statements, and types will become ddl scripts.
Here is the script:
-- DDL script. Generated from dbtoy output.
create table user (
int(11) id PRIMARY KEY,
varchar(64) login ,
varchar(64) password ,
enum('yes','no') enabled ,
);
-- Table data insert script. Generated from dbtoy output
insert into user values(
'1',
'domenico',
'domepw1',
'yes',
);
insert into user values(
'2',
'andrea',
'ris1pl',
'yes',
);
insert into user values(
'3',
'luca',
'def_12p',
'yes',
);
insert into user values(
'4',
'maek',
'rino76',
'yes',
);
insert into user values(
'5',
'pino_dd',
'para0m9',
'yes',
);
insert into user values(
'6',
'enzo',
'enzo2',
'no',
);
...