/[libdata]/trunk/my2pg/insert-next_id.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/my2pg/insert-next_id.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 73 - (show annotations)
Thu Mar 18 21:27:37 2004 UTC (20 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 1017 byte(s)
sync trunk to HEAD of pear-db (without changes specific to PEAR which will be dropped)

1 #!/usr/bin/perl -w
2
3
4 my $php;
5
6 while(<STDIN>) {
7 next if (/textInmySQL/);
8 $php .= $_;
9 }
10
11 sub fix_php {
12 my ($sql,$filler1,$query,$filler2,$var,$filler3) = @_;
13
14 my @vars;
15 while ($sql =~ s/'*"\s*\.\s*(\$\w+)\s*\.\s*"'*/ ? /s) {
16 push @vars, $1;
17 }
18
19 my ($table,$cols);
20 if ($sql =~ m/insert\s+into\s+(\S+)\s+\(([^\)]+)\)/i) {
21 ($table, $cols) = ($1,$2);
22 $cols =~ s/\s*,\s*/ = ? and /g;
23 $cols .= " = ?";
24 } else {
25 die "can't parse: $sql";
26 }
27
28 my $nl = "\n\t\t\t";
29
30 my $php .= '// '.$var.$filler3.$nl;
31 $php .= '$insert_res = xx_prepare_execute("select '.$table.'_id from '.$table.' where '.$cols.'", '.join(", ",@vars).');'.$nl;
32 $php .= 'list('.$var.') = $insert_res->fetchRow(DB_FETCHMODE_ORDERED);'.$nl;
33
34 return $sql . $filler1 . 'xx_prepare_execute($sql, '.join(", ",@vars).')' . $filler2 . $php;
35 }
36
37 my $fixed = 0;
38
39 $php =~ s/(\$sql\s*=\s*"[^;]+?;)([^{]+?)(xx_query\s*\(\$sql[^\)]+\))([^{]+?{[^}]+?}\s*else\s*{[^}]+?)(\$\w+)(\s*=\s*xx_insert_id\([^\)]+?\))/fix_php($1,$2,$3,$4,$5,$6)/seg;
40
41 print $php;

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26