Re: Fixed dia2sql

2004-04-28 Thread Colin Watson
On Wed, Apr 28, 2004 at 04:52:24PM +0200, Juraj Michalek wrote:
> I fixed bug #240459 in dia2sql.
> 
> Problem was that dia2sql crashes when there was no Protected attribute
> in diagram. Protected attribute is considered as primary key.
> 
> So I added small test if value is defined, and added small warning with
> explanation how to create a primary key in Dia diagram.
> 
> Fixes script is attached.

Can you send this in the form of a patch, please?

  diff -u old-script new-script

This is easier to deal with in the event that somebody comes back to
your mail some time later.

Also, please send the patch to [EMAIL PROTECTED] so that it gets
archived in our bug tracking system. This is important because dia2sql
doesn't have a Debian maintainer at the moment so it may be some time
before anyone gets to it.

Thanks,

-- 
Colin Watson  [EMAIL PROTECTED]



Fixed dia2sql

2004-04-28 Thread Juraj Michalek
Hello

I fixed bug #240459 in dia2sql.

Problem was that dia2sql crashes when there was no Protected attribute
in diagram. Protected attribute is considered as primary key.

So I added small test if value is defined, and added small warning with
explanation how to create a primary key in Dia diagram.

Fixes script is attached.


Have a nice day

Georgik
-- 
-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-
 Bc. Juraj Michalek - http://georgik.blucina.net
   Every application is a game. 
 The question is: How much you can enjoy it.
   Games for Linux - http://games.linux.sk
#!/usr/bin/perl -w
#
# dia2sql.pl - version 1.2 - 2001/03/20
# Entity-relationship with UML diagrams from Dia
#
# Copyright (c) 2001 by Alexander Troppmann
# http://www.cocktaildreams.de - [EMAIL PROTECTED]
#
# This program releases under the GNU Public License;
# You can redistribute it or modify it under the terms of GPL.
#
# Featurelist:
# - Creates a table for each UML class
# - All attributes of a Dia UML class will be converted to SQL statements:
#   "Name" = SQL column name,
#   "Type" = SQL datatype and also additional attributes,
#   "Visibility" = if set to "protected" the attribute will be a primary key
#   "Value" = if set a default value will be defined for this column
# - DROP TABLE statement can be created
# - For each column starting with "FK_" a foreign key constraint will be
#   created (PostgreSQL only). Do not use "REFERENCES" attributes in the UML
#   diagram!
# - Support for indexed columns (PostgreSQL only)
#
# Required stuff:
# - First get the expat library (> v1.95.0) as RPM package or from
#   http://www.jclark.com/xml/expat.html which is a XML1.0 parser written in C.
# - Second install XML::Parser from CPAN, just type in at your shell prompt:
#
#  [EMAIL PROTECTED]:~ > perl -MCPAN -e 'install XML::Parser'
#
# That's all! :-)

use strict;

use XML::Parser;

eval "use Compress::Zlib;";
my $use_zlib = ($@) ? 0 : 1;

use vars qw($VERSION $DEBUG $CREATECOMMENTS $MYSQL $POSTGRESQL $DROPTABLE 
$CREATEDROPTABLES);
use vars qw($infile $outfile);
use vars qw($buffer $ctag $prefix $text $table $tablename $column $columnname
$columnvalue $columnvi $commentprefix $columntype);
use vars qw(%attr @myTables $myTablename $myColumnname $myColumnvalue 
$myColumntype
$myIndexMarker %myIndexMarker %myIndexColumns $myKeyMarker 
%myKeyMarker %myPrimaryKeys
%myTableContents $myTableUsesIndizes $myTableUsesForeignKeys);
use vars qw(@myTablesIncludingFKs);
$VERSION = 'dia2sql.pl v1.2';

###
## CONFIG - MAKE ANY CHANGES HERE

$DEBUG = 0; # 1 if you want to get debug messages to STDERR
$CREATECOMMENTS = 0;# 1 if you want to get comments like mysqldump 
does

$MYSQL = 1; # choose either MySQL or 
PostgreSQL support
$POSTGRESQL = 0;# by setting 0 and 1 values here

$CREATEDROPTABLES = 0;  # 1 if you want to have "DROP TABLE" statements

if($MYSQL) {
$DROPTABLE = "DROP TABLE IF EXISTS";# DROP TABLE statement to be 
used
} elsif($POSTGRESQL) {
$DROPTABLE = "DROP TABLE";
} else {
die "ERROR: You didn't choose a database!\n";
}


###
## VARIABLES

$table = 0; # 1 if inside table
$tablename = 0; # 1 if tablename tag detected
$column = 0;# 1 if inside column
$columnname = 0;# 1 if columnname detected
$columntype = 0;# 1 if datatype for column detected
$columnvi = 0;  # 1 if "visibility" for primary key definitions
$columnvalue = 0;   # 1 if value attribute detected
$commentprefix = ($MYSQL) ? '# ' : '-- ';

undef($myTablename);# current table
undef(%myTableContents);# hash with columns for a certain table
undef(%myKeyMarker);# marker for primary keys
undef(%myIndexMarker);  # marker for indexed column
undef(%myPrimaryKeys);  # hash with primary keys for a certain 
table
undef(%myIndexColumns); # columns for index
undef($myColumnvalue);  # default value for datatype
undef($myTableUsesForeignKeys); # is my current table using foreign keys?
undef($myTableUsesIndizes); # is my current table using indexed 
columns?
undef(@myTablesIncludingFKs);   # build these tables later
undef(@myTables);   # build tables first (cause 
they're referenced)


###
## INIT

## get infile (and outfile) from command line
#
if(@ARGV < 1) {

die <<"_USAGE_END_"
Usage: dia2sql.pl file.dia [file.sql]

$VERSION - (c) 2001 by Alexander Troppmann

Converts xml data input from Dia to sql statements. If file.sql is not
specified the sql statements will be