1. Perl / Говнокод #705

    −255.6

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    sub player_win{
            my $self = shift;
            my ($T, $U) = @_;
            my $H = $self->file_to_hash($T);
            my $WIN = 0;
            my ($i, $k, $c, $z) = (0, 0, 0, 0);
            if( $T->{_MAX_COUNT} == 32 ){
              for($i = 0; $i < 2; $i++){
    	     for($k = 0; $k < 2; $k++){
                    for($c = 0; $c < 2; $c++){
                      for($z = 0; $z < 2; $z++){
                        foreach(0..1){
                            if($H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{f16}[$z]->{ppl}[$_]->{id} == $U->{_ID}){
                                 if($H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{f16}[$z]->{id} == 0){
    				$H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{f16}[$z]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{f16}[0]->{id} if $z == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{f16}[1]->{id} if $z == 0;
                                 } elsif($H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{id} == 0){
    				$H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[$c]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[0]->{id} if $c == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{f8}[1]->{id} if $c == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{id} == 0){
    				$H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[$k]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[0]->{id} if $k == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$i]->{f4}[1]->{id} if $k == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{f2}[$i]->{id} == 0){
    			        $H->{data}->{grid}->{f1}->{f2}[$i]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[0]->{id} if $i == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[1]->{id} if $i == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{id} == 0){
                                    $H->{data}->{grid}->{f1}->{id} = $U->{_ID};
                                    $WIN = -1;
                                 }
                            }
                        }
                      }
                    }
                 }
              }
            } elsif( $T->{_MAX_COUNT} == 16 ){
              for($i = 0; $i < 2; $i++){
    	     for($k = 0; $k < 2; $k++){
                    for($c = 0; $c < 2; $c++){
                        foreach(0..1){
                            if($H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{f8}[$i]->{ppl}[$_]->{id} == $U->{_ID}){
                                 if($H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{f8}[$i]->{id} == 0){
    				$H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{f8}[$i]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{f8}[0]->{id} if $i == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{f8}[1]->{id} if $i == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{id} == 0){
    				$H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[0]->{id} if $k == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[1]->{id} if $k == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{f2}[$c]->{id} == 0){
    			        $H->{data}->{grid}->{f1}->{f2}[$c]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[0]->{id} if $c == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[1]->{id} if $c == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{id} == 0){
                                    $H->{data}->{grid}->{f1}->{id} = $U->{_ID};
                                    $WIN = -1;
                                 }
                            }
                        }
                    }
                 }
              }
            } elsif($T->{_MAX_COUNT} == 8){
    	     for($k = 0; $k < 2; $k++){
                    for($c = 0; $c < 2; $c++){
                        foreach(0..1){
                            if($H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{ppl}[$_]->{id} == $U->{_ID}){
                                 if($H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{id} == 0){
                                    $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[$k]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[0]->{id} if $k == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[$c]->{f4}[1]->{id} if $k == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{f2}[$c]->{id} == 0){
    			        $H->{data}->{grid}->{f1}->{f2}[$c]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[0]->{id} if $c == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[1]->{id} if $c == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{id} == 0){
                                    $H->{data}->{grid}->{f1}->{id} = $U->{_ID};
                                    $WIN = -1;
                                 }
                            }
                        }
                    }
                 }
            } elsif($T->{_MAX_COUNT} == 4){
                    for($c = 0; $c < 2; $c++){
                        foreach(0..1){
                            if($H->{data}->{grid}->{f1}->{f2}[$c]->{ppl}[$_]->{id} == $U->{_ID}){
                                 if($H->{data}->{grid}->{f1}->{f2}[$c]->{id} == 0){
                                    $H->{data}->{grid}->{f1}->{f2}[$c]->{id} = $U->{_ID};
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[0]->{id} if $c == 1;
                                    $WIN = $H->{data}->{grid}->{f1}->{f2}[1]->{id} if $c == 0;
                                 } elsif ($H->{data}->{grid}->{f1}->{id} == 0){
                                    $H->{data}->{grid}->{f1}->{id} = $U->{_ID};
                                    $WIN = -1;
                                 }
                            }

    Очень "гибкий" алгоритм.

    guest, 13 Марта 2009

    Комментарии (2)
  2. Perl / Говнокод #704

    −305.1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    my ($_bonus1_l, $_bonus1_y, $_bonus2_l, $_bonus2_y) = ($l1*10 > rand(100) ? 1 : 0, $y1*10 > rand(100) ? 1 : 0, $l2*10 > rand(100) ? 1 : 0, $y2*10 > rand(100) ? 1 : 0);
          ($_bonus1_l, $_bonus2_l) = (0, 0) if $_bonus1_l == 1 and $_bonus2_l == 1;
          ($_bonus1_y, $_bonus2_y) = (0, 0) if $_bonus1_y == 1 and $_bonus2_y == 1;
    if($turn > 12){
          my ($_a1_def, $_b1_def, $_c1_def) = mass($pl1_mov, $User1, "def");
          my ($_a1_att, $_b1_att, $_c1_att) = mass($pl1_att, $User1, "att");
          my ($_a2_def, $_b2_def, $_c2_def) = mass($pl2_mov, $User2, "def");
          my ($_a2_att, $_b2_att, $_c2_att) = mass($pl2_att, $User2, "att");
    
    $N1 += $_a1_att if $_a2_def < 1000000;
    $N1 += $_b1_att if $_b2_def < 1000000;
    $N1 += $_c1_att if $_c2_def < 1000000;
    $N2 += $_a2_att if $_a1_def < 1000000;
    $N2 += $_b2_att if $_b1_def < 1000000;
    $N2 += $_c2_att if $_c1_def < 1000000;
    
          if($_bonus1_l){
           	 my $l = int(rand(3));
    	 ## сБНПНР
             if($l == 0){
             	my $r = 0;
    	 	($_a2_att, $r) = (0, 1) if $_a2_att > 0 and $_a1_def < 1000000;
          	 	($_b2_att, $r) = (0, 1) if $_b2_att > 0 and $_a1_def < 1000000 and $r == 0;
    		($_c2_att, $r) = (0, 1) if $_c2_att > 0 and $_a1_def < 1000000 and $r == 0;
                    $U1 = $r;
             } elsif($l == 1){
                    my $r = 0;
                    ($_a1_att, $r, $K2) = (int($_a1_att * 1.5), 1, int($_a1_att/2)) if $_a1_att > 0  and $_a2_def < 1000000;
                    ($_b1_att, $r, $K2) = (int($_b1_att * 1.5), 1, int($_b1_att/2)) if $_b1_att > 0  and $_b2_def < 1000000 and $r == 0;
                    ($_c1_att, $r, $K2) = (int($_c1_att * 1.5), 1, int($_c1_att/2)) if $_c1_att > 0  and $_c2_def < 1000000 and $r == 0;
             } elsif($l == 2){
                    my ($r, $ov, $v) = (0, 0, int(rand(3)));
                    ($_a1_att, $r, $ov) = (0, 1, (int($_a2_att/2))) if $_a2_att > 0 and $_a1_def > 1000000;
                    ($_b1_att, $r, $ov) = (0, 1, (int($_b2_att/2))) if $_b2_att > 0 and $_b1_def > 1000000 and $r == 0;
                    ($_c1_att, $r, $ov) = (0, 1, (int($_c2_att/2))) if $_c2_att > 0 and $_c1_def > 1000000 and $r == 0;
                    $_a1_att += $ov if $v == 0;
                    $_b1_att += $ov if $v == 1;
                    $_c1_att += $ov if $v == 2;
                    $O1 = $ov;
             }
          }
          if($_bonus2_l){
           	 my $l = int(rand(100));
             if($l == 0){
             	my $r = 0;
    	 	($_a1_att, $r) = (0, 1) if $_a1_att > 0 and $_a2_def < 1000000;
          	 	($_b1_att, $r) = (0, 1) if $_b1_att > 0 and $_a2_def < 1000000 and $r == 0;
    		($_c1_att, $r) = (0, 1) if $_c1_att > 0 and $_a2_def < 1000000 and $r == 0;
                     $U2 = $r;
             } elsif($l == 1){
                    my $r = 0;
                    ($_a2_att, $r, $K1) = (int($_a2_att * 1.5), 1, int($_a2_att/2)) if $_a2_att > 0  and $_a1_def < 1000000;
                    ($_b2_att, $r, $K1) = (int($_b2_att * 1.5), 1, int($_b2_att/2)) if $_b2_att > 0  and $_b1_def < 1000000 and $r == 0;
                    ($_c2_att, $r, $K1) = (int($_c2_att * 1.5), 1, int($_c2_att/2)) if $_c2_att > 0  and $_c1_def < 1000000 and $r == 0;
             } elsif($l == 2){
             	my ($r, $ov, $v) = (0, 0, int(rand(3)));
                    ($_a2_att, $r, $ov) = (0, 1, (int($_a1_att/2))) if $_a1_att > 0 and $_a2_def > 1000000;
                    ($_b2_att, $r, $ov) = (0, 1, (int($_b1_att/2))) if $_b1_att > 0 and $_b2_def > 1000000 and $r == 0;
                    ($_c2_att, $r, $ov) = (0, 1, (int($_c1_att/2))) if $_c1_att > 0 and $_c2_def > 1000000 and $r == 0;
                    $_a2_att += $ov if $v == 0;
                    $_b2_att += $ov if $v == 1;
                    $_c2_att += $ov if $v == 2;
                    $O2 = $ov;
             }
          }
          if($_bonus1_y){
              my $l = int(rand(2));
             if($l == 0){
                my ($r, $rik, $V1) = (0, 0, int(rand(3)) + 1);
                ($r, $rik) = (1, (int($_a1_att/2))) if $_a1_att > 0 and $_a2_def < 1000000 and $V1 == 1;
                ($r, $rik) = (1, (int($_b1_att/2))) if $_b1_att > 0 and $_b2_def < 1000000 and $r == 0 and $V1 == 2;
                ($r, $rik) = (1, (int($_c1_att/2))) if $_c1_att > 0 and $_c2_def < 1000000 and $r == 0 and $V1 == 3;
                $R2 = $rik;
                $db->query("UPDATE duel set pl1_rik = CONCAT(pl1_rik, $V1) where sid = \"$dsid\"") if $R2 > 0;
    
             } elsif($l == 1){
                my $r = 0;
                ($_a2_def, $r) = ($_a2_def - 1000000, 1) if $_a1_att > 0 and $_a2_def > 1000000;
                ($_b2_def, $r) = ($_b2_def - 1000000, 2) if $_b1_att > 0 and $_b2_def > 1000000 and $r == 0;
                ($_c2_def, $r) = ($_c2_def - 1000000, 3) if $_c1_att > 0 and $_c2_def > 1000000 and $r == 0;
                $T2 = $r;
             }
          }
          if($_bonus2_y){
              my $l = int(rand(2));
             if($l == 0){
                my ($r, $rik, $V2) = (0, 0, int(rand(3)) + 1);
                ($r, $rik) = (1, (int($_a2_att/2))) if $_a2_att > 0 and $_a1_def < 1000000 and $V2 == 1;
                ($r, $rik) = (1, (int($_b2_att/2))) if $_b2_att > 0 and $_b1_def < 1000000 and $r == 0 and $V2 == 2;
                ($r, $rik) = (1, (int($_c2_att/2))) if $_c2_att > 0 and $_c1_def < 1000000 and $r == 0 and $V2 == 3;
    
                #$_a2_att += $rik if $V2 == 1;
                #$_b2_att += $rik if $V2 == 2;
                #$_c2_att += $rik if $V2 == 3;
                $R1 = $rik;
                $db->query("UPDATE duel set pl2_rik = CONCAT(pl2_rik, $V2) where sid = \"$dsid\"") if $R1 > 0;
             } elsif($l == 1){
                my $r = 0;
                ($_a1_def, $r) = ($_a1_def - 1000000, 1) if $_a2_att > 0 and $_a1_def > 1000000;
                ($_b1_def, $r) = ($_b1_def - 1000000, 2) if $_b2_att > 0 and $_b1_def > 1000000 and $r == 0;

    Из браузерной игрушки на mod_perl/mysql. Код наглядно демонстрирует, что говнокод зависит не от языка, а от программиста.

    guest, 13 Марта 2009

    Комментарии (1)
  3. JavaScript / Говнокод #703

    +167.2

    1. 1
    2. 2
    3. 3
    4. 4
    if (!!Flag === true)
    {
     ...
    }

    guest, 13 Марта 2009

    Комментарии (3)
  4. Perl / Говнокод #702

    −307.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    sub get_ppl{
    	my $self = shift;
            my ($U, $print_done, $team) = @_;
    
             return "<ppl team_id='$team' battle_stats='$U->{_CHAR}->{win},$U->{_CHAR}->{loose},$U->{_CHAR}->{nobody}' medals='".$U->get_medal_string_for_user($U)."' $clan team_id='0' av_id='$U->{_CHAR}->{av_id}' fn='$U->{_CHAR}->{avatara}' u='$U->{_CHAR}->{u}' hp_u='$U->{_CHAR}->{hp_u}' stat0_u='$U->{_CHAR}->{stat0_u}' stat0='$U->{_CHAR}->{f}' stat1='$U->{_CHAR}->{m}' stat2='$U->{_CHAR}->{y}'  stat3='$U->{_CHAR}->{l}' hpmax='$U->{_CHAR}->{maxhp}' hp='$U->{_CHAR}->{hp}' aname='$U->{_USER_NAME}' lvl='$U->{_CHAR}->{lvl}' cname='$U->{_CHAR}->{name}' id='$U->{_ID}' carma='$U->{_CHAR}->{carma}' sex='$U->{_CHAR}->{sex}' slot0='$Item[0]' slot8='$Item[8]' slot7='$Item[7]' slot6='$Item[6]' slot1='$Item[1]' weight='$U->{_CHAR}->{weight}' slot5='$Item[5]' slot4='$Item[4]' slot3='$Item[3]' slot2='$Item[2]' city_id='$U->{_CHAR}->{city_id}'/>" if !$print_done;
             return "<ppl done='true' battle_stats='$U->{_CHAR}->{win},$U->{_CHAR}->{loose},$U->{_CHAR}->{nobody}' medals='".$U->get_medal_string_for_user($U)."' $clan team_id='0' av_id='$U->{_CHAR}->{av_id}' fn='$U->{_CHAR}->{avatara}' u='$U->{_CHAR}->{u}' hp_u='$U->{_CHAR}->{hp_u}' stat0_u='$U->{_CHAR}->{stat0_u}' stat0='$U->{_CHAR}->{f}' stat1='$U->{_CHAR}->{m}' stat2='$U->{_CHAR}->{y}'  stat3='$U->{_CHAR}->{l}' hpmax='$U->{_CHAR}->{maxhp}' hp='$U->{_CHAR}->{hp}' aname='$U->{_USER_NAME}' lvl='$U->{_CHAR}->{lvl}' cname='$U->{_CHAR}->{name}' id='$U->{_ID}' carma='$U->{_CHAR}->{carma}' sex='$U->{_CHAR}->{sex}' slot0='$Item[0]' slot8='$Item[8]' slot7='$Item[7]' slot6='$Item[6]' slot1='$Item[1]' weight='$U->{_CHAR}->{weight}' slot5='$Item[5]' slot4='$Item[4]' slot3='$Item[3]' slot2='$Item[2]' city_id='$U->{_CHAR}->{city_id}'/>" if $print_done;
    }

    Забавная проверка

    guest, 12 Марта 2009

    Комментарии (1)
  5. SQL / Говнокод #701

    −868

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    CREATE OR REPLACE VIEW my_schema.my_view AS
    SELECT 
       TO_NUMBER (c.payment_term_code) ID, 
       c.payment_term_code sap_code, c.payment_term_name longname,
              c.short_name shortname, c.comment_line comments, c.cust_relevant, c.vend_relevant, c.active active,
              c.updated_by created_by, c.updated_by updated_by, c.updated_on created_on, c.updated_on updated_on, 1 txn_ver
         FROM my_schema.my_table c
        WHERE (    LENGTH (c.payment_term_code) = 1
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 2
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 3
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 4
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 4, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
           OR (    LENGTH (c.payment_term_code) = 5
               AND SUBSTR (c.payment_term_code, 1, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 2, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 3, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 4, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
               AND SUBSTR (c.payment_term_code, 5, 1) IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
              )
       UNION
       SELECT ID, sap_code, longname, shortname, comments, 'Y', 'Y', active, created_by, updated_by, created_on, updated_on, 1
         FROM my_schema.my_other_table) tt

    Вот так в 30 строк пиндосы защищаются от проникновения буковков в TO_NUMBER()

    guest, 12 Марта 2009

    Комментарии (6)
  6. SQL / Говнокод #700

    −870.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    select 
    --
    (case
        when (sum(distinct sub.est_cost) - sum(distinct sub.act_cost)) > 0 then
          (sum(distinct sub.est_cost) - sum(distinct sub.act_cost))
        when (sum(distinct sub.est_cost) - sum(distinct sub.act_cost)) < 0 then
          (sum(distinct sub.est_cost) - sum(distinct sub.act_cost))
        else
           0
    end)
    --
    from blablabla

    Не пускайте бразильских футболистов к компьютеру!

    guest, 12 Марта 2009

    Комментарии (0)
  7. SQL / Говнокод #699

    −873.4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    SELECT BE.SORT as SORT,BE.ID as ID,DATE_FORMAT(BE.TIMESTAMP_X, '%d.%m.%Y %H:%i:%s') as TIMESTAMP_X,BE.MODIFIED_BY as
     MODIFIED_BY,DATE_FORMAT(BE.DATE_CREATE, '%d.%m.%Y %H:%i:%s') as DATE_CREATE,BE.CREATED_BY as CREATED_BY,BE.IBLOCK_ID as
     IBLOCK_ID,BE.IBLOCK_SECTION_ID as IBLOCK_SECTION_ID,BE.ACTIVE as ACTIVE,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_FROM)>0,
     DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y %H:%i:%s'), DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y')) as ACTIVE_FROM,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_TO)>0, DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y %H:%i:%s'), DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y')) as
     ACTIVE_TO,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_FROM)>0, DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y %H:%i:%s'),
     DATE_FORMAT(BE.ACTIVE_FROM, '%d.%m.%Y')) as DATE_ACTIVE_FROM,IF(EXTRACT(HOUR_SECOND FROM BE.ACTIVE_TO)>0, DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y %H:%i:%s'), DATE_FORMAT(BE.ACTIVE_TO, '%d.%m.%Y')) as DATE_ACTIVE_TO,BE.NAME as NAME,BE.PREVIEW_PICTURE as 
     PREVIEW_PICTURE,BE.PREVIEW_TEXT as PREVIEW_TEXT,BE.PREVIEW_TEXT_TYPE as PREVIEW_TEXT_TYPE,BE.DETAIL_PICTURE as
     DETAIL_PICTURE,BE.DETAIL_TEXT as DETAIL_TEXT,BE.DETAIL_TEXT_TYPE as DETAIL_TEXT_TYPE,BE.SEARCHABLE_CONTENT as
     SEARCHABLE_CONTENT,BE.WF_STATUS_ID as WF_STATUS_ID,BE.WF_PARENT_ELEMENT_ID as WF_PARENT_ELEMENT_ID,BE.WF_NEW as WF_NEW,if (BE.WF_DATE_LOCK is null, 'green', if(DATE_ADD(BE.WF_DATE_LOCK, interval 60 MINUTE)<now(), 'green', if(BE.WF_LOCKED_BY=0, 'yellow', 'red'))) as LOCK_STATUS,BE.WF_LOCKED_BY as WF_LOCKED_BY,DATE_FORMAT(BE.WF_DATE_LOCK, '%d.%m.%Y %H:%i:%s') as
     WF_DATE_LOCK,BE.WF_COMMENTS as WF_COMMENTS,BE.IN_SECTIONS as IN_SECTIONS,BE.SHOW_COUNTER as SHOW_COUNTER,BE.SHOW_COUNTER_START as
     SHOW_COUNTER_START,BE.CODE as CODE,BE.TAGS as TAGS,BE.XML_ID as XML_ID,BE.XML_ID as EXTERNAL_ID,BE.TMP_ID as
     TMP_ID,concat('(',U.LOGIN,') ',ifnull(U.NAME,''),' ',ifnull(U.LAST_NAME,'')) as USER_NAME,concat('(',UL.LOGIN,') ',ifnull(UL.NAME,''),' ',ifnull(UL.LAST_NAME,'')) as LOCKED_USER_NAME,concat('(',UC.LOGIN,') ',ifnull(UC.NAME,''),' ',ifnull(UC.LAST_NAME,'')) as CREATED_USER_NAME,L.DIR as LANG_DIR,B.LID as LID,B.IBLOCK_TYPE_ID as IBLOCK_TYPE_ID,B.CODE as
     IBLOCK_CODE,B.NAME as IBLOCK_NAME,B.XML_ID as IBLOCK_EXTERNAL_ID,B.DETAIL_PAGE_URL as DETAIL_PAGE_URL,B.LIST_PAGE_URL as
     LIST_PAGE_URL FROM b_iblock B INNER JOIN b_lang L ON B.LID=L.LID INNER JOIN b_iblock_element BE ON BE.IBLOCK_ID = B.ID INNER JOIN b_iblock_property FP1 ON FP1.IBLOCK_ID=B.ID AND FP1.CODE='DAY' INNER JOIN b_iblock_element_property FPV1 ON
     FP1.ID=FPV1.IBLOCK_PROPERTY_ID AND FPV1.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property_enum FPEN1 ON FP1.ID = FPEN1.PROPERTY_ID AND FPV1.VALUE_ENUM=FPEN1.ID INNER JOIN b_iblock_property FP2 ON FP2.IBLOCK_ID=B.ID AND FP2.CODE='MONTH' INNER JOIN
     b_iblock_element_property FPV2 ON FP2.ID=FPV2.IBLOCK_PROPERTY_ID AND FPV2.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property_enum FPEN2 ON FP2.ID = FPEN2.PROPERTY_ID AND FPV2.VALUE_ENUM=FPEN2.ID LEFT JOIN b_user U ON U.ID=BE.MODIFIED_BY LEFT JOIN b_user UL ON
     UL.ID=BE.WF_LOCKED_BY LEFT JOIN b_user UC ON UC.ID=BE.CREATED_BY WHERE 1=1 AND B.ID IN (0,72) AND ( (BE.WF_STATUS_ID=1 AND
     BE.WF_PARENT_ELEMENT_ID IS NULL) ) AND ((((BE.IBLOCK_ID = '72')))) AND (((BE.ACTIVE_TO >= now() OR BE.ACTIVE_TO IS NULL) AND
     (BE.ACTIVE_FROM <= now() OR BE.ACTIVE_FROM IS NULL))) AND ((((BE.ACTIVE='Y')))) AND (BE.IN_SECTIONS ='N' ) AND ((((FPEN1.VALUE LIKE
     '-1')))) AND ((((FPEN2.VALUE LIKE 'Март')))) ORDER BY BE.SORT asc

    Вот что бывает когда человека заменет скрипт, причем написаные тупым человеком, ORM рулить.

    guest, 12 Марта 2009

    Комментарии (12)
  8. SQL / Говнокод #698

    −852.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    UPDATE DKNDRECTMPL SET
        TARGET = IIF(OPERATION IN (0, 1, 3, 4, 5), 0, 1),
        ACT = CASE OPERATION
              WHEN 0 THEN 0
              WHEN 1 THEN 1
          WHEN 2 THEN 1
          WHEN 3 THEN 1
          WHEN 4 THEN 1
          WHEN 5 THEN 3
              END;

    Это Firebird если чё.

    guest, 12 Марта 2009

    Комментарии (5)
  9. SQL / Говнокод #697

    −854.7

    1. 1
    2. 2
    UPDATE CARD SET STATE = (STATE - 1) * (-1);
    //таким экзотическим способом инвертируем значения 0/1, чтобы не подцеплять лишних UDF

    SQL-инвертор

    guest, 12 Марта 2009

    Комментарии (12)
  10. PHP / Говнокод #696

    +173.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $h_month = date("m");
    $h_day = date("d");
    $h_year = date("Y");
    $h_hour = date("H");
    $h_minute = date("i");
    
    $history = mysql_query("insert into history values('','$h_month','$h_day','$h_year','$h_hour','$h_minute','$total_open','$beat','$wins','$tie','$can_change_up','$can_change_down','$cannot_win','$t_adjusted_gain','$t_adjusted_loss','$t_dollar_amount')");

    вот так вот человек хранит дату в БД =)

    guest, 12 Марта 2009

    Комментарии (23)