|
35 | 35 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
36 | 36 | # SUCH DAMAGE. |
37 | 37 | # |
38 | | -# $My2pg: my2pg.pl,v 1.24 2001/12/06 19:32:20 fonin Exp $ |
39 | | -# $Id: my2pg.pl,v 1.9 2002/08/22 00:01:39 tgl Exp $ |
40 | | - |
41 | | -# TODO: |
42 | | -# + Handle SETs |
43 | | -# - LIKE implementation |
44 | | -# - memory use optimisation in SET_output function |
45 | | -# - raw integer values as input values must be OK |
46 | | -# - Use autoconf & automake to auto-build makefiles |
| 38 | +# $My2pg: my2pg.pl,v 1.27 2001/12/06 19:32:20 fonin Exp $ |
| 39 | +# $Id: my2pg.pl,v 1.10 2003/01/07 22:18:43 momjian Exp $ |
47 | 40 |
|
48 | 41 | # |
49 | 42 | # $Log: my2pg.pl,v $ |
50 | | -# Revision 1.9 2002/08/22 00:01:39 tgl |
51 | | -# Add a bunch of pseudo-types to replace the behavior formerly associated |
52 | | -# with OPAQUE, as per recent pghackers discussion. I still want to do some |
53 | | -# more work on the 'cstring' pseudo-type, but I'm going to commit the bulk |
54 | | -# of the changes now before the tree starts shifting under me ... |
| 43 | +# Revision 1.10 2003/01/07 22:18:43 momjian |
| 44 | +# Upgrade to my2pg 1.9 |
| 45 | +# |
| 46 | +# Revision 1.27 2002/07/16 14:54:07 fonin |
| 47 | +# Bugfix - didn't quote the fields inside PRIMARY KEY with -d option. |
| 48 | +# Fix by Milan P. Stanic <mps@rns-nis.co.yu>. |
55 | 49 | # |
56 | | -# Revision 1.8 2002/04/24 01:42:29 momjian |
57 | | -# Update to my2pg 1.24. |
| 50 | +# Revision 1.26 2002/07/14 10:30:27 fonin |
| 51 | +# Bugfix - MySQL keywords inside data (INSERT INTO sentence) were replaced |
| 52 | +# with Postgres keywords and therefore messed up the data. |
| 53 | +# |
| 54 | +# Revision 1.25 2002/07/05 09:20:25 fonin |
| 55 | +# - fixed data that contains two consecutive timestamps - thanks to |
| 56 | +# Ben Darnell <bdarnell@google.com> |
| 57 | +# - word 'default' was converted to upper case inside the data - fixed. |
| 58 | +# Thanks to Madsen Wikholm <madsen@iki.fi> |
58 | 59 | # |
59 | 60 | # Revision 1.24 2002/04/20 14:15:43 fonin |
60 | 61 | # Patch by Felipe Nievinski <fnievinski@terra.com.br>. |
|
177 | 178 | $|=1; |
178 | 179 |
|
179 | 180 | print("------------------------------------------------------------------"); |
180 | | -print("\n-- My2Pg 1.24 translated dump"); |
| 181 | +print("\n-- My2Pg 1.27 translated dump"); |
181 | 182 | print("\n--"); |
182 | 183 | print("\n------------------------------------------------------------------"); |
183 | 184 |
|
|
199 | 200 | # push header to libtypes.c |
200 | 201 | open(LIBTYPES,">$libtypesource"); |
201 | 202 | print LIBTYPES "/******************************************************"; |
202 | | -print LIBTYPES "\n * My2Pg \$Revision: 1.9 $ \translated dump"; |
| 203 | +print LIBTYPES "\n * My2Pg 1.27 \translated dump"; |
203 | 204 | print LIBTYPES "\n * User types definitions"; |
204 | 205 | print LIBTYPES "\n ******************************************************/"; |
205 | 206 | print LIBTYPES "\n\n#include <postgres.h>\n"; |
|
211 | 212 |
|
212 | 213 | if(!$tabledef && /^CREATE TABLE \S+/i){ |
213 | 214 | $tabledef=1; |
214 | | - }elsif($tabledef && /^\);/i){ # /^\w/i |
| 215 | + } elsif($tabledef && /^\) type=\w*;/i){ # /^\w/i |
215 | 216 | $tabledef=0; |
216 | 217 | } |
217 | 218 |
|
|
253 | 254 |
|
254 | 255 | # small hack - convert "default" to uppercase, because below we |
255 | 256 | # enclose all lowercase words in double quotes |
256 | | - s/default/DEFAULT/; |
| 257 | + if(!/^INSERT/) { |
| 258 | + s/default/DEFAULT/; |
| 259 | + } |
257 | 260 |
|
258 | 261 | # Change all AUTO_INCREMENT fields to SERIAL ones with a pre-defined sequence |
259 | 262 | if(/([\w\d]+)\sint.*auto_increment/i) { |
|
314 | 317 | print LIBTYPES "\n * Types for table ".uc($table_name); |
315 | 318 | print LIBTYPES "\n */\n"; |
316 | 319 |
|
317 | | - $types.="\nCREATE FUNCTION $typename"."_in (cstring) |
| 320 | + $types.="\nCREATE FUNCTION $typename"."_in (opaque) |
318 | 321 | RETURNS $typename |
319 | 322 | AS '$libtypename' |
320 | 323 | LANGUAGE 'c' |
321 | | - WITH (ISSTRICT, ISCACHABLE);\n"; |
| 324 | + WITH (ISCACHABLE);\n"; |
322 | 325 |
|
323 | 326 | # creating output function |
324 | 327 | my $func_out=" |
|
368 | 371 | return (*a>=*b); |
369 | 372 | }\n"; |
370 | 373 |
|
371 | | - $types.="\nCREATE FUNCTION $typename"."_out ($typename) |
372 | | - RETURNS cstring |
| 374 | + $types.="\nCREATE FUNCTION $typename"."_out (opaque) |
| 375 | + RETURNS opaque |
373 | 376 | AS '$libtypename' |
374 | 377 | LANGUAGE 'c' |
375 | | - WITH (ISSTRICT, ISCACHABLE);\n"; |
| 378 | + WITH (ISCACHABLE);\n"; |
376 | 379 |
|
377 | 380 | $types.="\nCREATE TYPE $typename ( |
378 | 381 | internallength = 2, |
|
515 | 518 | print LIBTYPES "\n * Types for table ".uc($table_name); |
516 | 519 | print LIBTYPES "\n */\n"; |
517 | 520 |
|
518 | | - $types.="\nCREATE FUNCTION $typename"."_in (cstring) |
| 521 | + $types.="\nCREATE FUNCTION $typename"."_in (opaque) |
519 | 522 | RETURNS $typename |
520 | 523 | AS '$libtypename' |
521 | 524 | LANGUAGE 'c';\n"; |
|
567 | 570 |
|
568 | 571 | \n"; |
569 | 572 |
|
570 | | - $types.="\nCREATE FUNCTION $typename"."_out ($typename) |
571 | | - RETURNS cstring |
| 573 | + $types.="\nCREATE FUNCTION $typename"."_out (opaque) |
| 574 | + RETURNS opaque |
572 | 575 | AS '$libtypename' |
573 | 576 | LANGUAGE 'c';\n"; |
574 | 577 |
|
|
651 | 654 | } |
652 | 655 |
|
653 | 656 | # output CHECK constraints instead UNSIGNED modifiers |
654 | | - if(/PRIMARY KEY \((.*)\)/i) { |
| 657 | + if(/PRIMARY KEY\s+\((.*)\)/i) { |
655 | 658 | my $tmpfld=$1; |
656 | 659 | $tmpfld=~s/,/","/g if $dq; |
657 | 660 | $tmpfld=~s/ //g; |
658 | | - s/PRIMARY KEY (\(.*\))/PRIMARY KEY \($dq$tmpfld$dq\)/i; |
| 661 | + s/PRIMARY KEY\s+(\(.*\))/PRIMARY KEY \($dq$tmpfld$dq\)/i; |
659 | 662 | s/(PRIMARY KEY \(.*\)).*/$1$check\n/i; |
660 | 663 | } |
661 | 664 |
|
|
685 | 688 | # Fix timestamps |
686 | 689 | s/'0000-00-00/'0001-01-01/g; |
687 | 690 | # may work wrong !!! |
688 | | - s/([,(])00000000000000([,)])/$1'00010101 000000'$2/g; |
689 | | - s/([,(])(\d{8})(\d{6})([,)])/$1'$2 $3'$4/g; |
690 | | - s/([,(])(\d{4})(\d{2})(\d{2})([,)])/$1'$2-$3-$4 00:00:00'$5/g; |
| 691 | + s/([,(])00000000000000(?=[,)])/$1'00010101 000000'/g; |
| 692 | + s/([,(])(\d{8})(\d{6})(?=[,)])/$1'$2 $3'/g; |
| 693 | + s/([,(])(\d{4})(\d{2})(\d{2})(?=[,)])/$1'$2-$3-$4 00:00:00'/g; |
691 | 694 | #<Hackzone> --------------------------------------------------- |
692 | 695 | #</Hackzone> -------------------------------------------------- |
693 | 696 | $dump.=$_; |
|
731 | 734 |
|
732 | 735 | open(MAKE,">Makefile"); |
733 | 736 | print MAKE "# |
734 | | -# My2Pg \$Revision: 1.9 $ \translated dump |
| 737 | +# My2Pg \$Revision: 1.10 $ \translated dump |
735 | 738 | # Makefile |
736 | 739 | # |
737 | 740 |
|
|
0 commit comments