Parse-Dia-SQL-0.27/0000755000175000017500000000000012261537153011723 5ustar affaffParse-Dia-SQL-0.27/AUTHORS0000644000175000017500000000152012254051017012761 0ustar affaff Contributing Authors to-date: Tim Ellis -- Main program, general direction -- mailto: ttiimmeelleessss at tigris dot org Martin Gebert, Edward Epstein -- MySQL InnoDB support and Constraint enforcement Andrew S. Halper -- Ingres Support Greg Copeland -- Bug fixes & patches Christopher Bowland -- Windows-without-Cygwin fixes Peter Lamb -- UML mode and automatic generation of PK, FK and join tables Martin Bögelund -- SAS DB Support (mainly fixing SQL comment style) Neal Stephenson -- Macro expasion support (small objects defined once for many tables) Paul Suda -- Auto-increment MySQL support Mike Ginou -- Debian friendliness and drop index support Norbert Volf -- Comments for PostgreSQL support Patryk Sciborek -- Datatype equivalence generic algorithm Andreas Faafeng -- CPAN rewrite, test suite. Peter Langton -- SQLite3, HTML support. Parse-Dia-SQL-0.27/Changes0000644000175000017500000001271012261536511013214 0ustar affaffRevision history for Perl module Parse::Dia::SQL. 0.27 Fri Jan 3 14:37:55 CET 2014 - RT #91654 Spelling mistake. Thanks to gregor herrmann and perl debian team. 0.26 Tue Dec 17 22:07:00 CET 2013 - RT #66031 dia changed naming from aggregate_a/b to assoc_type. - added support for bigserial & smallserial under postgresql. (Thanks to Felix Ostmann) 0.25 Wed Mar 20 09:29:29 CET 2013 - Fixed bug in "nullable" implementation introducted in 0.24. 0.24 Mon Mar 18 08:22:54 CET 2013 - Added previously unsupported "nullable" feature for non-primary key columns when using Database shape (added in 0.15). 0.23 Tue Aug 28 08:28:19 CEST 2012 - RT #79218 Spelling patch from debian downstream (Thanks to Gregor Herrmann). 0.22 Tue Aug 7 09:00:00 CEST 2012 - RT #78818 syntax error fixed (thanks to openback). - Makefile.PL - added BUILD_REQUIRES => { 'CPAN::Meta' => 0, }, to ensure META.yml is created during build. - Changed META_MERGE => repository to github.com 0.21 Tue Jul 24 09:40:21 CEST 2012 - Added 'html' output options (thanks to Peter Langton). Check generated html with XML::DOM::Parser and HTML::Lint. - RT #77115 - Added SQLite3fk emitter that supports foreign key (thanks to Peter Langton). 0.20 Mon Jan 30 14:19:46 CET 2012 - Added `backticks` to constraint creation, drop table, drop index for MySQL-InnoDB. 0.19 Tue Jan 24 13:19:12 CET 2012 - Added `backticks` support for MySQL-InnoDB (tables only). 0.18 Wed Jan 11 15:45:42 CET 2012 - Added support for table options (see t/data/table_output_options.dia) 0.17 Wed Feb 16 11:02:44 CET 2011 - RT #58189: Enable log level in command line arguments. (reported by ELACOUR@cpan.org) - RT #62131 (reported by Felix Ostmann): - Associations incorrectly named in many-to-many relationships. - Add --uml support. - RT #57842 postgres: serial -> int not working (reported by shemgp). 0.16 Fri May 21 07:20:43 CEST 2010 - RT #57182 Encoding for insert statements in UML components (reported by Gaudenz Steinlin). - Final preparations for debian release. 0.15 Thu Apr 15 22:32:41 CEST 2010 - RT #56357 - Detect Dia database shapes and added experimental parsing (excluding associations) (reported by John-Paul Drawneek). - Added LICENSE to conform with debian standards. 0.14 Fri Feb 5 20:13:09 CET 2010 - RT #53782 - Add typemap support (reported by Jani Päijänen). 0.13 Sun Dec 20 13:01:41 CET 2009 - RT #52755 - Add support for Postgres unique constraints using the smallpackage stereotype (reported by shemgp). - RT #50906 - Added PostgreSQL synonyms int2, int4, int8 to integer, smallint and bigint respectively (reported by Edy Incoletti. - Added ignore_type_mismatch option which allows foreign keys to have a different + type than the primary key it references 0.12 Thu Nov 12 10:51:28 CET 2009 - RT #51433 - Multipicity (sic) not handled correctly (reported by Edy Incoletti and Jeff Chimene) - Ensure all indices are created before foreign key constraints (all db platforms, reported by Jeff Chimene) 0.11 Sun Jul 12 21:25:38 CEST 2009 - Bug #47593 Default type for PSQL 'serial' should be 'integer' not 'int' (thanks to Mart van de Wege). - Added support for Dia 0.97 source files. Added verions checks for each XML element containing it. First reported in bug #47040: Associations are not generated in Dia 0.97 0.10 Sat May 16 21:03:57 CEST 2009 - Use recent (6.50) EU::MM in build to get LICENCE MIN_PERL_VERSION, META_MERGE correctly set. 0.09 Sat May 16 15:29:28 CEST 2009 - SQLite3: Fixed a bug in the update constraint trigger - SQLite3: Added 'on delete cascade' support - Added support for index options, which are modelled as a comment on the operation (index). - Fixed bug: Missing associations should bot prevent index creation. 0.08 Tue Apr 14 14:12:00 CEST 2009 - Bugfix in Utils.pm (sqlite -> sqlite3). - Updated Makefile.PL with META_MERGE and LICENSE. - Added MANIFEST.SKIP - Removed TODO in boilerplate test. 0.07 Wed Apr 1 09:47:50 CEST 2009 - Added experimental support for SQLite v.3 (thanks to Peter Langton). 0.06 Mon Mar 30 09:59:53 CEST 2009 - Fixed bug 'missing role name on PK end' (thanks to Peter Langton). - Fixed foreign key bug for Sybase (case sensitivity issue). - Removed 'experimental' tag on MySQL MyISAM and InnoDB. - Use Text::Table for comment formatting. 0.05 Mon Mar 16 08:58:33 CET 2009 - Restrict length of foreign keys in drop statements (see 0.04) 0.04 Fri Mar 13 13:13:13 CET 2009 - Made foreign keys 18 chars or less on DB2 (overridable) regardless of name length in dia file. (sub _create_constraint_name) - InnoDB: Added drop foreign keys support. - Reduced number of columns in log output to screen. 0.03 Mon Mar 2 09:57:23 CET 2009 - Added table_postfix_options (e.g. 'ENGINE=InnoDB') - Made documentation more consistent. - Removed private subroutines from main documentation. - Made sure parsing is finished before outputting, and updated tests accordingly. 0.02 Fri Feb 27 10:29:36 CET 2009 - Fixed package name error. - Added generate_small_package_sql() to Output.pm - Fixed comma-comment bug. - Added CLI client. 0.01 Mon Feb 23 08:18:14 CET 2009 - original version Parse-Dia-SQL-0.27/LICENSE0000644000175000017500000004305112254051017012723 0ustar affaff GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. Parse-Dia-SQL-0.27/Makefile.PL0000644000175000017500000000347012254051017013671 0ustar affaff # $Id: Makefile.PL,v 1.5 2010/04/15 20:41:00 aff Exp $ use strict; use warnings; require 5.006; use ExtUtils::MakeMaker; my %args = ( NAME => 'Parse::Dia::SQL', AUTHOR => 'Andreas Faafeng ', VERSION_FROM => 'lib/Parse/Dia/SQL.pm', ABSTRACT_FROM => 'lib/Parse/Dia/SQL.pm', EXE_FILES => ['bin/parsediasql'], PL_FILES => {}, LICENSE => 'gpl', META_MERGE => { resources => { repository => 'https://github.com/aff/Parse-Dia-SQL', }, keywords => [ qw [Parse Dia SQL DDL RDBMS DB2 Informix Ingres InnoDB MyISAM MySQL Oracle Postgres SQLite3 Sas Sybase] ], }, BUILD_REQUIRES => { 'CPAN::Meta' => 0, }, PREREQ_PM => { 'Data::Dumper' => 0, 'Digest::MD5' => 0, 'Fatal' => 0, 'File::Spec::Functions' => 0, 'File::Temp' => 0, 'File::Find' => 0, 'HTML::Lint' => 0, 'Getopt::Long' => 0, 'IO::Uncompress::Gunzip' => 0, 'Log::Log4perl' => 0, 'POSIX' => 0, 'Test::Exception' => 0, 'Test::More' => 0, 'Text::Table' => 0, 'XML::DOM' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Parse-Dia-SQL-*' }, ); # Use args according to installed version of ExtUtils::MM my %filter = ( MIN_PERL_VERSION => '6.48', LICENSE => '6.48', META_MERGE => '6.46', AUTHOR => '6.07', ABSTRACT_FROM => '6.07', ); delete $args {$_} for grep {defined $filter {$_} && $ExtUtils::MakeMaker::VERSION lt $filter {$_}} keys %args; WriteMakefile %args; __END__ Parse-Dia-SQL-0.27/TODO0000644000175000017500000000253012254051017012403 0ustar affaff - Implement support for Dia's new Database shape. - Warn if there are typemaps for databases in the model that are not used to generate output. - Add general support for synonyms (replace hack in Parse::Dia::SQL::Utils::get_base_type). - Support index options on individual indices. - Add test for missing FK (formerly fkNamesFromAttList) - Add support for loading statements from external files. - Warn on identical (or near-identical) statements in smallpackages. - Warn attempts to create index on non-existent columns - Add option tablespace to create statements. - Add $VERSION to all modules. - Make sure pre and post statement end up at the right place. - Add options to parsediasql (identical to those of tedia2sql) - For all classes: - verify create table,view,index,constraint syntax - verify drop table,view,index,constraint syntax - Parse::Dia::SQL::Output::MySQL - sub _get_create_table_sql must handle AUTO_INCREMENT - Download DDL's from http://tedia2sql.tigris.org/ and ensure Parse::Dia::SQL produces roughly the same code. - Test with larger dia files. - Optimize with Devel::DProf, and consider a faster XML parser. - Be consistent in subroutine names (e.g. Output.pm) E.g. get__<(create|drop)>_sql - Apply stricter Perl::Critic (current level 'stern', consider 'harsh'). - Update pod in all modules. Parse-Dia-SQL-0.27/META.yml0000664000175000017500000000230412261537153013175 0ustar affaff--- #YAML:1.0 name: Parse-Dia-SQL version: 0.27 abstract: Convert Dia class diagrams into SQL. author: - Andreas Faafeng license: gpl distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: CPAN::Meta: 0 requires: Data::Dumper: 0 Digest::MD5: 0 Fatal: 0 File::Find: 0 File::Spec::Functions: 0 File::Temp: 0 Getopt::Long: 0 HTML::Lint: 0 IO::Uncompress::Gunzip: 0 Log::Log4perl: 0 POSIX: 0 Test::Exception: 0 Test::More: 0 Text::Table: 0 XML::DOM: 0 resources: repository: https://github.com/aff/Parse-Dia-SQL no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.57_05 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 keywords: - Parse - Dia - SQL - DDL - RDBMS - DB2 - Informix - Ingres - InnoDB - MyISAM - MySQL - Oracle - Postgres - SQLite3 - Sas - Sybase Parse-Dia-SQL-0.27/MANIFEST.SKIP0000644000175000017500000000111212254051017013604 0ustar affaff# Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.tmp$ \.bak$ \.new$ \.sql$ \.patch$ \.log$ \.log\.[0-9]+$ ^\. # Avoid Devel::Cover files. \bcover_db\b # Skip debian directory \bdebian\b MYMETA.json MYMETA.yml Parse-Dia-SQL-0.27/lib/0000755000175000017500000000000012261537153012471 5ustar affaffParse-Dia-SQL-0.27/lib/Parse/0000755000175000017500000000000012261537153013543 5ustar affaffParse-Dia-SQL-0.27/lib/Parse/Dia/0000755000175000017500000000000012261537153014240 5ustar affaffParse-Dia-SQL-0.27/lib/Parse/Dia/SQL/0000755000175000017500000000000012261537153014677 5ustar affaffParse-Dia-SQL-0.27/lib/Parse/Dia/SQL/Output/0000755000175000017500000000000012261537153016177 5ustar affaffParse-Dia-SQL-0.27/lib/Parse/Dia/SQL/Output/Sas.pm0000644000175000017500000000136112254051017017254 0ustar affaffpackage Parse::Dia::SQL::Output::Sas; # $Id: Sas.pm,v 1.3 2009/03/02 13:41:39 aff Exp $ =pod =head1 NAME Parse::Dia::SQL::Output::Sas - Create SQL for Sas. =head1 SEE ALSO Parse::Dia::SQL::Output =cut use warnings; use strict; use Data::Dumper; use File::Spec::Functions qw(catfile); use lib q{lib}; use base q{Parse::Dia::SQL::Output}; # extends require Parse::Dia::SQL::Logger; require Parse::Dia::SQL::Const; =head2 new The constructor. Arguments: =cut sub new { my ( $class, %param ) = @_; my $self = {}; # Set defaults for sas $param{db} = q{sas}; $param{object_name_max_length} = $param{object_name_max_length} || 32; $self = $class->SUPER::new(%param); bless( $self, $class ); return $self; } 1; __END__ Parse-Dia-SQL-0.27/lib/Parse/Dia/SQL/Output/SQLite3.pm0000644000175000017500000003356212261536061017767 0ustar affaffpackage Parse::Dia::SQL::Output::SQLite3; # $Id: SQLite3.pm,v 1.5 2009/05/14 09:42:47 aff Exp $ =pod =head1 NAME Parse::Dia::SQL::Output::SQLite3 - Create SQL for SQLite version 3. =head1 SYNOPSIS use Parse::Dia::SQL; my $dia = Parse::Dia::SQL->new(file => 'foo.dia', db => 'sqlite3'); print $dia->get_sql(); =head1 DESCRIPTION This sub-class creates SQL for the SQLite database version 3. =cut use warnings; use strict; use Data::Dumper; use File::Spec::Functions qw(catfile); use lib q{lib}; use base q{Parse::Dia::SQL::Output}; # extends require Parse::Dia::SQL::Logger; require Parse::Dia::SQL::Const; =head2 new The constructor. Object names in SQLite have no inherent limit. 60 has been arbitrarily chosen. =cut sub new { my ( $class, %param ) = @_; my $self = {}; # Set defaults for sqlite $param{db} = q{sqlite3}; $param{object_name_max_length} = $param{object_name_max_length} || 60; $self = $class->SUPER::new( %param ); bless( $self, $class ); return $self; } =head2 _get_create_table_sql Generate create table statement for a single table using SQLite syntax: Includes class comments before the table definition. Includes autoupdate triggers based on the class comment. =head3 autoupdate triggers If the class comment includes a line like: /> Then an 'after update' trigger is generated for this table which executes the statement I for the updated row. Examples of use include tracking record modification dates (C<>) or deriving a value from another field (C<>) =cut sub _get_create_table_sql { my ( $self, $table ) = @_; my $sqlstr = ''; my $temp; my $comment; my $tablename; my $trigger = ''; my $update; my $primary_keys = ''; # include the comments before the table creation $comment = $table->{comment}; if ( !defined( $comment ) ) { $comment = ''; } $tablename = $table->{name}; $sqlstr .= $self->{newline}; if ( $comment ne "" ) { $temp = "-- $comment"; $temp =~ s/\n/\n-- /g; $temp =~ s/^-- $//mgi; if ( $temp ne "" ) { if ( $temp !~ /\n$/m ) { $temp .= $self->{newline}; } $sqlstr .= $temp; } } # Call the base class to generate the main create table statements $sqlstr .= $self->SUPER::_get_create_table_sql( $table ); # Generate update triggers if required if ( $comment =~ //mi ) { $update = $3; # what we will set it to $trigger = $2; # the trigger suffix to use (optional) $trigger = $tablename . "_autoupdate" . $trigger; # Check that the column exists foreach $temp ( @{ $table->{attList} } ) { # build the two primary key elements if ( $$temp[3] == 2 ) { if ( $primary_keys ) { $primary_keys .= " and "; } $primary_keys .= $$temp[0] . "=OLD." . $$temp[0]; } } $sqlstr .= "drop trigger if exists $trigger" . $self->{end_of_statement} . $self->{newline}; $sqlstr .= "create trigger $trigger after update on $tablename begin update $tablename set $update where $primary_keys;end" . $self->{end_of_statement} . $self->{newline}; $sqlstr .= $self->{newline}; } return $sqlstr; } =head2 get_schema_drop Generate drop table statments for all tables using SQLite syntax: drop table {foo} if exists =cut sub get_schema_drop { my $self = shift; my $sqlstr = ''; return unless $self->_check_classes(); CLASS: foreach my $object ( @{ $self->{classes} } ) { next CLASS if ( $object->{type} ne q{table} ); # Sanity checks on internal state if (!defined( $object ) || ref( $object ) ne q{HASH} || !exists( $object->{name} ) ) { $self->{log} ->error( q{Error in table input - cannot create drop table sql!} ); next; } $sqlstr .= qq{drop table if exists } . $object->{name} . $self->{end_of_statement} . $self->{newline}; } return $sqlstr; } =head2 get_view_drop Generate drop view statments for all tables using SQLite syntax: drop view {foo} if exists =cut # Create drop view for all views sub get_view_drop { my $self = shift; my $sqlstr = ''; return unless $self->_check_classes(); CLASS: foreach my $object ( @{ $self->{classes} } ) { next CLASS if ( $object->{type} ne q{view} ); # Sanity checks on internal state if (!defined( $object ) || ref( $object ) ne q{HASH} || !exists( $object->{name} ) ) { $self->{log} ->error( q{Error in table input - cannot create drop table sql!} ); next; } $sqlstr .= qq{drop view if exists } . $object->{name} . $self->{end_of_statement} . $self->{newline}; } return $sqlstr; } =head2 _get_fk_drop Drop foreign key enforcement triggers using SQLite syntax: drop trigger {foo} if exists The automatically generated foreign key enforcement triggers are: See L<"_get_create_association_sql"> for more details. =over =item I_bi_tr =item I_bu_tr =item I_buparent_tr =item I_bdparent_tr =back =cut # Drop all foreign keys sub _get_fk_drop { my $self = shift; my $sqlstr = ''; my $temp; return unless $self->_check_associations(); # drop fk foreach my $association ( @{ $self->{associations} } ) { my ( $table_name, $constraint_name, undef, undef, undef, undef ) = @{$association}; $temp = $constraint_name . "_bi_tr"; $sqlstr .= qq{drop trigger if exists $temp} . $self->{end_of_statement} . $self->{newline}; $temp = $constraint_name . "_bu_tr"; $sqlstr .= qq{drop trigger if exists $temp} . $self->{end_of_statement} . $self->{newline}; $temp = $constraint_name . "_buparent_tr"; $sqlstr .= qq{drop trigger if exists $temp} . $self->{end_of_statement} . $self->{newline}; $temp = $constraint_name . "_bdparent_tr"; $sqlstr .= qq{drop trigger if exists $temp} . $self->{end_of_statement} . $self->{newline}; $sqlstr .= $self->{newline}; } return $sqlstr; } =head2 _get_drop_index_sql drop index statement using SQLite syntax: drop index {foo} if exists =cut sub _get_drop_index_sql { my ( $self, $tablename, $indexname ) = @_; return qq{drop index if exists $indexname} . $self->{end_of_statement} . $self->{newline}; } =head2 get_permissions_create SQLite doesn't support permissions, so suppress this output. =cut sub get_permissions_create { return ''; } =head2 get_permissions_drop SQLite doesn't support permissions, so suppress this output. =cut sub get_permissions_drop { return ''; } =head2 _get_create_association_sql Create the foreign key enforcement triggers using SQLite syntax: create trigger {fkname}[_bi_tr|_bu_tr|_bdparent_tr|_buparent_tr] Because SQLite doesn't natively enforce foreign key constraints (see L), we use triggers to emulate this behaviour. The trigger names are the default contraint name (something like I_fk_I) with suffixes described below. =over =item I<{constraint_name}> is the name of the association, either specified or generated. =item I<{child_table}> is the name of the dependent or child table. =item I<{child_fkcolumn}> is the field in the dependent table that hold the foreign key. =item I<{parent_table}> is the name of the parent table. =item I<{parent_key}> is the key field of the parent table. =back =head3 Before insert - Dependent Table I_bi_tr Before insert on the child table require that the parent key exists. create trigger {constraint_name}_bi_tr before insert on {child_table} for each row begin select raise(abort, 'insert on table {child_table} violates foreign key constraint {constraint_name}') where new.{child_fkcolumn} is not null and (select {parent_key} from {parent_table} where {parent_key}=new.{child_fkcolumn}) is null; end; =head3 Before update - Dependent Table I_bu_tr Before update on the child table require that the parent key exists. create trigger {constraint_name}_bu_tr before update on {table_name} for each row begin select raise(abort, 'update on table {child_table} violates foreign key constraint {constraint_name}') where new.{child_fkcolumn} is not null and (select {parent_key} from {parent_table} where {parent_key}=new.{child_fkcolumn}) is null; end; =head3 Before update - Parent Table I_buparent_tr Before update on the primary key of the parent table ensure that there are no dependent child records. Note that cascading updates B. create trigger {constraint_name}_buparent_tr before update on {parent_table} for each row when new.{parent_key} <> old.{parent_key} begin select raise(abort, 'update on table {parent_table} violates foreign key constraint {constraint_name} on {child_table}') where (select {child_fkcolumn} from {child_table} where {child_fkcolumn}=old.{parent_key}) is not null; end; =head3 Before delete - Parent Table I_bdparent_tr The default behaviour can be modified through the contraint (in the multiplicity field) of the association. =head4 Default (On Delete Restrict) Before delete on the parent table ensure that there are no dependent child records. create trigger {constraint_name}_bdparent_tr before delete on {parent_table} for each row begin select raise(abort, 'delete on table {parent_table} violates foreign key constraint {constraint_name} on {child_table}') where (select {child_fkcolumn} from {child_table} where {child_fkcolumn}=old.{parent_key}) is not null; end; =head4 On Delete Cascade Before delete on the parent table delete all dependent child records. create trigger {constraint_name}_bdparent_tr before delete on {parent_table} for each row begin delete from {child_table} where {child_table}.{child_fkcolumn}=old.{parent_key}; end; =head4 On Delete Set Null Before delete on the parent table set the foreign key field(s) in all dependent child records to NULL. create trigger {constraint_name}_bdparent_tr before delete on {parent_table} for each row begin update {child_table} set {child_table}.{child_fkcolumn}=null where {child_table}.{child_fkcolumn}=old.{parent_key}; end; =cut # Create sql for given association. sub _get_create_association_sql { my ( $self, $association ) = @_; my $sqlstr = ''; my $temp; # Sanity checks on input if ( ref( $association ) ne 'ARRAY' ) { $self->{log} ->error( q{Error in association input - cannot create association sql!} ); return; } # FK constraints are implemented as triggers in SQLite my ( $table_name, $constraint_name, $key_column, $ref_table, $ref_column, $constraint_action ) = @{$association}; # Shorten constraint name, if necessary (DB2 only) $constraint_name = $self->_create_constraint_name( $constraint_name ); $temp = $constraint_name . "_bi_tr"; $sqlstr .= qq{create trigger $temp before insert on $table_name for each row begin select raise(abort, 'insert on table $table_name violates foreign key constraint $constraint_name') where new.$key_column is not null and (select $ref_column from $ref_table where $ref_column=new.$key_column) is null;end} . $self->{end_of_statement} . $self->{newline}; $temp = $constraint_name . "_bu_tr"; $sqlstr .= qq{create trigger $temp before update on $table_name for each row begin select raise(abort, 'update on table $table_name violates foreign key constraint $constraint_name') where new.$key_column is not null and (select $ref_column from $ref_table where $ref_column=new.$key_column) is null;end} . $self->{end_of_statement} . $self->{newline}; # note that the before delete triggers are on the parent ($ref_table) $temp = $constraint_name . "_bdparent_tr"; if ( $constraint_action =~ /on delete cascade/i ) { $sqlstr .= qq{create trigger $temp before delete on $ref_table for each row begin delete from $table_name where $table_name.$key_column=old.$ref_column;end} . $self->{end_of_statement} . $self->{newline}; } elsif ( $constraint_action =~ /on delete set null/i ) { $sqlstr .= qq{create trigger $temp before delete on $ref_table for each row begin update $table_name set $key_column=null where $table_name.$key_column=old.$ref_column;end} . $self->{end_of_statement} . $self->{newline}; } else # default on delete restrict { $sqlstr .= qq{create trigger $temp before delete on $ref_table for each row begin select raise(abort, 'delete on table $ref_table violates foreign key constraint $constraint_name on $table_name') where (select $key_column from $table_name where $key_column=old.$ref_column) is not null;end} . $self->{end_of_statement} . $self->{newline}; } # Cascade updates doesn't work, so we always restrict $temp = $constraint_name . "_buparent_tr"; $sqlstr .= qq{create trigger $temp before update on $ref_table for each row when new.$ref_column <> old.$ref_column begin select raise(abort, 'update on table $ref_table violates foreign key constraint $constraint_name on $table_name') where (select $key_column from $table_name where $key_column=old.$ref_column) is not null;end} . $self->{end_of_statement} . $self->{newline}; $sqlstr .= $self->{newline}; return $sqlstr; } 1; =head1 TODO Things that might get added in future versions: =head3 Mandatory constraints The current foreign key triggers allow NULL in the child table. This might use a keyword in the multiplicity field (perhaps 'required') or could check the 'not null' state of the child fkcolumn. =head3 Views Views haven't been tested. They might already work, but who knows... =head3 Other stuff Bugs etc =cut __END__ Parse-Dia-SQL-0.27/lib/Parse/Dia/SQL/Output/Ingres.pm0000644000175000017500000000222712254051017017757 0ustar affaffpackage Parse::Dia::SQL::Output::Ingres; # $Id: Ingres.pm,v 1.2 2009/03/02 13:41:39 aff Exp $ =pod =head1 NAME Parse::Dia::SQL::Output::Ingres - Create SQL for Ingres. =head1 SEE ALSO Parse::Dia::SQL::Output =cut use warnings; use strict; use Data::Dumper; use File::Spec::Functions qw(catfile); use lib q{lib}; use base q{Parse::Dia::SQL::Output}; # extends require Parse::Dia::SQL::Logger; require Parse::Dia::SQL::Const; =head2 new The constructor. Arguments: =cut sub new { my ( $class, %param ) = @_; my $self = {}; # Set defaults for ingres $param{db} = q{ingres}; $param{object_name_max_length} = $param{object_name_max_length} || 30; $param{end_of_statement} = $param{end_of_statement} || "\n\\g"; $self = $class->SUPER::new(%param); bless( $self, $class ); return $self; } =head2 _get_drop_index_sql create drop index for index on table with given name. drop index idx_foo for ingres =cut sub _get_drop_index_sql { my ( $self, $tablename, $indexname ) = @_; return qq{drop index $indexname for } . $self->{db} . $self->{end_of_statement} . $self->{newline}; } 1; __END__ Parse-Dia-SQL-0.27/lib/Parse/Dia/SQL/Output/HTML.pm0000644000175000017500000007110512254051017017275 0ustar affaffpackage Parse::Dia::SQL::Output::HTML; # $Id: $ =pod =head1 NAME Parse::Dia::SQL::Output::HTML - Create HTML documentation. =head1 SYNOPSIS use Parse::Dia::SQL; my $dia = Parse::Dia::SQL->new( file => 'foo.dia', db => 'html' [ , htmlformat => {formatfile} ] ); print $dia->get_sql(); =head1 DESCRIPTION This sub-class creates HTML formatted database documentation. HTML formatting is controlled by templates selected with the optional I parameter which supplies a format file. See L for more. The generated HTML is intended to be useful rather than beautiful. This sub-class follows the same structure as the rdbms output sub-classes with the intent of maintaining consistency, even though this give less than optimum efficiency. =cut use warnings; use strict; use Text::Table; use Data::Dumper; use File::Spec::Functions qw(catfile); use lib q{lib}; use base q{Parse::Dia::SQL::Output}; # extends use Config; require Parse::Dia::SQL::Logger; require Parse::Dia::SQL::Const; =head2 new The constructor. Object names in HTML have no inherent limit. 64 has been arbitrarily chosen. =cut sub new { my ( $class, %param ) = @_; my $self = {}; # Set defaults for sqlite $param{db} = q{html}; $param{object_name_max_length} = $param{object_name_max_length} || 64; $param{htmlformat} = $param{htmlformat} || ''; $self = $class->SUPER::new( %param ); bless( $self, $class ); $self->{dbdata} = {}; # table data, keyed by tablename $self->{htmltemplate} = {}; # html template elements $self->set_html_template($param{htmlformat}); # find the template elements based on the selected format return $self; } =head2 get_sql Return all sql documentation. First build the data structures: schema create view create permissions create inserts associations create (indices first, then foreign keys) Then generate the output: html start html comments body start generate main html body end html end =cut sub get_sql { my $self = shift; ## no critic (NoWarnings) no warnings q{uninitialized}; $self->get_schema_create(); $self->get_view_create(); $self->get_permissions_create(); $self->get_inserts(); $self->get_associations_create(); my $html = '' . $self->_get_preamble() . $self->_get_comment() . $self->get_smallpackage_pre_sql() . $self->generate_html() . $self->get_smallpackage_post_sql() . $self->_get_postscript() ; return $html; } =head2 _get_preamble HTML Header =cut sub _get_preamble { my $self = shift; my $files_word = (scalar(@{ $self->{files} }) > 1) ? q{Input files} : q{Input file}; my $data = $self->{htmltemplate}{htmlpreamble}; # File name my $value = $self->{files}[0]; $data =~ s/{filename}/$value/mgi; # todo: meta tags? return $data } =head2 _get_comment Comment for HTML Header =cut sub _get_comment { my $self = shift; my $files_word = (scalar(@{ $self->{files} }) > 1) ? q{Input files} : q{Input file}; $self->{gentime} = scalar localtime(); my @arr = ( [ q{Parse::SQL::Dia}, qq{version $Parse::Dia::SQL::VERSION} ], [ q{Documentation}, q{http://search.cpan.org/dist/Parse-Dia-SQL/} ], [ q{Environment}, qq{Perl $], $^X} ], [ q{Architecture}, qq{$Config{archname}} ], [ q{Target Database}, $self->{db} ], [ $files_word, join(q{, }, @{ $self->{files} }) ], [ q{Generated at}, $self->{gentime} ], ); $self->{filename} = join(q{, }, @{ $self->{files} }); my $value = ''; my $data = $self->{htmltemplate}{htmlcomment}; my $tb = Text::Table->new(); $tb->load(@arr); $value = scalar $tb->table(); $data =~ s/{htmlcomment}/$value/mgi; return $data; } =head2 get_smallpackage_pre_sql HTML Body start =cut sub get_smallpackage_pre_sql { my $self = shift; my $data; $data = $self->{htmltemplate}{htmlstartbody}; return $data } =head2 get_smallpackage_post_sql HTML Body close =cut sub get_smallpackage_post_sql { my $self = shift; my $data; $data = $self->{htmltemplate}{htmlendbody}; $data =~ s/{gentime}/$self->{gentime}/mgi; return $data } =head2 _get_postscript HTML close =cut sub _get_postscript { my $self = shift; my $data = ''; $data = $self->{htmltemplate}{htmlend}; return $data } =head2 _get_create_table_sql Extracts the documentation details for a single table. =cut sub _get_create_table_sql { my ( $self, $table ) = @_; #my $sqlstr = ''; my $temp; my $comment; my $tablename; my $update; my $primary_keys = ''; my $order = 0; my $tabletemplate = ''; my $tablerowemplate = ''; my $tabledata = ''; my $tablerowdata = ''; # Table name $tablename = $table->{name}; $self->{'dbdata'}{$tablename} = {}; # Comments 1 - strip the autoupdate bits $comment = $table->{comment}; if ( !defined( $comment ) ) { $comment = ''; } if ( $comment ne '' ) { $comment =~ s/\n//g; $comment =~ s///mgi; } # Comments 2 - just the autoupdate bits $update = $table->{comment}; if ( !defined( $update ) ) { $update = ''; } if ( $update =~ //mi ) { $update = $3; # update code } # Set up build the table documentation $self->{'dbdata'}{$tablename}{'name'} = $tablename; $self->{'dbdata'}{$tablename}{'comment'} = $comment; $self->{'dbdata'}{$tablename}{'autoupdate'} = $update; $self->{'dbdata'}{$tablename}{'fields'} = {}; # field list, keyed by field name $self->{'dbdata'}{$tablename}{'keyfields'} = {}; # primary key fields $self->{'dbdata'}{$tablename}{'ref_by'} = {}; # tables that use this as a FK $self->{'dbdata'}{$tablename}{'ref_to'} = {}; # tables that this uses for FK $self->{'dbdata'}{$tablename}{'permissions'} = []; # permissions array $self->{'dbdata'}{$tablename}{'indices'} = {}; # indices keyed by index name # Fields # Check not null and primary key property for each column. Column # visibility is given in $columns[3]. A value of 2 in this field # signifies a primary key (which also must be defined as 'not null'. $tablerowdata = ''; foreach my $column (@{ $table->{attList} }) { if (ref($column) ne 'ARRAY') { $self->{log} ->error(q{Error in view attList input - expect an ARRAY ref!}); next COLUMN; } # Don't warn on uninitialized values here since there are lots # of them. ## no critic (ProhibitNoWarnings) no warnings q{uninitialized}; # Field sequence: my ($col_name, $col_type, $col_val, $col_vis, $col_com) = @{$column}; $self->{'dbdata'}{$tablename}{'fields'}{$col_name} = { 'name' => $col_name, 'type' => $col_type, 'default' => $col_val, 'comment' => $col_com, 'order' => $order, }; $order ++; ## Add 'not null' if field is primary key if ($col_vis == 2) { $self->{'dbdata'}{$tablename}{'fields'}{$col_name}{'default'} = 'not null'; $self->{'dbdata'}{$tablename}{'keyfields'}{$col_name} = 1; } } return ''; } =head2 get_schema_drop Do nothing =cut sub get_schema_drop { return ''; } =head2 get_view_drop Do nothing =cut sub get_view_drop { return ''; } =head2 _get_fk_drop Do nothing =cut sub _get_fk_drop { return ''; } =head2 _get_drop_index_sql Do nothing =cut sub _get_drop_index_sql { return ''; } =head2 get_permissions_create Permissions are formatted as C<{type} {name} to {list of roles}> where: C is the operation C, C etc C is the permission name C