[patch] forcing numeric pri keys as auto_increment

View: New views
1 Messages — Rating Filter:   Alert me  

[patch] forcing numeric pri keys as auto_increment

by pete-61 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi all,

first, mega thx for tim  & all the authors of tedia2sql! The code is
extremely nicely structured and well commented, so even I who is a perl
illiterate, was able to add this feature!

About the patch: it makes effect only when the -a switch is given on the
command line, and it forces an auto_increment attribute for mysql and innodb
table /dbms types if the primary key is a numeric (any kind of int).

The patch was generated using diff -Naur and applies for tedia2sql-1.2.12


best,
 ----
Péter


--- ./tedia2sql.old 2004-12-12 19:21:50.000000000 +0100
+++ ./tedia2sql 2007-01-29 16:39:30.117495300 +0100
@@ -126,7 +126,7 @@
 
 #Getopts ('i:o:t:v:p:gsdhcuCfbkmM');
 my %opts = ();
-getopts('i:o:t:v:p:gsdhcuCfbkmM', \%opts);
+getopts('i:o:t:v:p:gsdhcuCfbkmMa', \%opts);
 my $opt_i = $opts{'i'};
 my $opt_o = $opts{'o'};
 my $opt_t = $opts{'t'};
@@ -144,6 +144,7 @@
 my $opt_k = $opts{'k'};
 my $opt_m = $opts{'m'};
 my $opt_M = $opts{'M'};
+my $opt_a = $opts{'a'};
 
 my $defaultPK = [ ];
 
@@ -582,7 +583,7 @@
  print "FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\n";
  print "more details.\n";
  print "\n";
- print "Usage: $0 [-t <dbType>] [-g] [-s] [-d] [-v {1 | 2}] [-h] [-i <xmlIn>] -o <sqlOut> inputFiles...\n";
+ print "Usage: $0 [-t <dbType>] [-a] [-g] [-s] [-d] [-v {1 | 2}] [-h] [-i <xmlIn>] -o <sqlOut> inputFiles...\n";
  print "\n";
  print "\t  -g              (Deprecated, gzip status now autodeteced) Dia XML savefile *NOT* gzipped\n";
  print "\t  -t <dbType>     Type of database to gen SQL for (postgres, mysql, sybase, oracle, db2, innodb)\n";
@@ -595,6 +596,7 @@
  print "\t  -p names:types  Automatically generate primary keys when needed with name and type given\n";
  print "\t  -f              Automatically generate foreign keys in tables when needed\n";
  print "\t  -b              Backwards-compatibility - generate SQL more like tedia2sql v1.2.9b\n";
+ print "\t  -a              Force auto_increment for numeric primary key (innodb and mysql).\n";
  print "\t  -k              Write/keep output files even if there is an error\n";
  print "\t  -m              Produce warnings, not fatal errors where foreign key and primary keys don't have same type\n";
  print "\t  -M              Ignore cases where foreign key and primary keys don't have same type\n";
@@ -1502,8 +1504,11 @@
  #    - go figure...
  # 3. $colVal being something else should make the column be
  #    "default $colVal", being the default of the column
- if (($opt_t eq 'mysql' || $opt_t eq 'innodb') &&
-    ($colVal =~ s/auto_increment// || $colVal =~ s/AUTO_INCREMENT//)){
+ if ( ($opt_t eq 'mysql' || $opt_t eq 'innodb') &&
+     # explicitly defined auto_increment attribute
+     (($colVal =~ s/auto_increment// || $colVal =~ s/AUTO_INCREMENT//) ||
+     # or attibute forced by the -a switch for a numeric pri key
+       ($opt_a && $colVis == 2 && ($colType =~ m/int/i))) ){
     # Strip off white space at ends, left after removing auto_increment.
     $colVal =~ s/^\s+//;
     $colVal =~ s/\s+$//;


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...
LightInTheBox - Buy quality products at wholesale price