Click here to Skip to main content
15,887,266 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: JavaScript Conditional Pin
Jeroen De Dauw24-Jun-10 3:54
Jeroen De Dauw24-Jun-10 3:54 
GeneralRe: JavaScript Conditional Pin
Tsuda Kageyu24-Jun-10 17:38
Tsuda Kageyu24-Jun-10 17:38 
GeneralRe: JavaScript Conditional Pin
whatrevolution25-Jun-10 2:54
whatrevolution25-Jun-10 2:54 
GeneralRe: JavaScript Conditional Pin
Lutosław27-Jun-10 1:12
Lutosław27-Jun-10 1:12 
GeneralRe: JavaScript Conditional Pin
whatrevolution27-Jun-10 3:18
whatrevolution27-Jun-10 3:18 
GeneralRe: JavaScript Conditional Pin
jsc4222-Jul-10 23:35
professionaljsc4222-Jul-10 23:35 
GeneralRe: JavaScript Conditional Pin
whatrevolution23-Jul-10 9:36
whatrevolution23-Jul-10 9:36 
GeneralWhat a trigger Pin
Bernhard Hiller22-Jun-10 23:39
Bernhard Hiller22-Jun-10 23:39 
We all like Oracle, don't we:
CREATE TRIGGER "LOGIN_ID_TRG" BEFORE INSERT ON "LOGIN" REFERENCING OLD AS OLD NEW AS NEW FOR EACH ROW 
DECLARE 
v_newVal NUMBER(12) := 0;
v_incval NUMBER(12) := 0;
BEGIN
IF INSERTING AND :new.ID IS NULL THEN
SELECT Login_ID_SEQ.NEXTVAL INTO v_newVal FROM DUAL;
    IF v_newVal = 1 THEN  
      SELECT NVL(max(ID),0) INTO v_newVal FROM Login; 
      v_newVal := v_newVal + 1; 
      LOOP 
           EXIT WHEN v_incval>=v_newVal; 
           SELECT Login_ID_SEQ.nextval INTO v_incval FROM dual; 
      END LOOP; 
    END IF; 
   :new.ID := v_newVal; 
  END IF; 
END;
/


Does that gem do what it is expected to do?
Hm, the first row inserted into the (empty) table gets the ID 1 (and is inserted into the table with ID 1), but Login_ID_SEQ.curr_val is already 2, and consequently the C# application communicating with that Oracle db received a wrong value (it calls SELECT Login_ID_SEQ.CURRVAL FROM DUAL in order to get the last insert id). By the way, the second row inserted receives ID 3.

For the first value inserted into an empty table, the LOOP is executed once, and thus Login_ID_SEQ.nextval twice. Setting the start value of v_incval to 1 did the trick. But I fear the trigger will fail if some when a row would be inserted with an ID different from null (fortunately, we had not activated the IdentityInsert property in our SQL Server database, and hence I am confident that our application won't do that).

How did I find that gem? I used an Oracle tool to convert my SQL Server database. Then I wrote a script to set up all the tables, sequences, triggers, and some start values for my "schema" using the "Show SQL" feature of Oracle Enterprise Manager for each of these objects. Then I tested that with a fresh schema, and my application threw an error with the first login attempt. Thanks a lot, Oracle!
GeneralRe: What a trigger Pin
Chris Meech23-Jun-10 6:16
Chris Meech23-Jun-10 6:16 
GeneralRe: What a trigger Pin
David Skelly23-Jun-10 22:52
David Skelly23-Jun-10 22:52 
GeneralRe: What a trigger Pin
Bernhard Hiller23-Jun-10 20:16
Bernhard Hiller23-Jun-10 20:16 
GeneralRe: What a trigger Pin
Covean23-Jun-10 23:20
Covean23-Jun-10 23:20 
GeneralDeliberate Crash Pin
ARopo16-Jun-10 4:01
ARopo16-Jun-10 4:01 
GeneralRe: Deliberate Crash Pin
rentzk16-Jun-10 6:18
rentzk16-Jun-10 6:18 
GeneralRe: Deliberate Crash Pin
Chris Meech16-Jun-10 6:40
Chris Meech16-Jun-10 6:40 
GeneralRe: Deliberate Crash Pin
Stryder_116-Jun-10 8:37
Stryder_116-Jun-10 8:37 
GeneralRe: Deliberate Crash Pin
ARopo16-Jun-10 23:41
ARopo16-Jun-10 23:41 
GeneralRe: Deliberate Crash Pin
Steve Wellens18-Jun-10 17:48
Steve Wellens18-Jun-10 17:48 
GeneralRe: Deliberate Crash Pin
ARopo21-Jun-10 6:04
ARopo21-Jun-10 6:04 
GeneralRe: Deliberate Crash Pin
Stephen Hewitt20-Jun-10 15:03
Stephen Hewitt20-Jun-10 15:03 
GeneralRe: Deliberate Crash Pin
ARopo21-Jun-10 6:11
ARopo21-Jun-10 6:11 
GeneralTidying up PinPopular
AnnieMacD14-Jun-10 13:03
AnnieMacD14-Jun-10 13:03 
GeneralRe: Tidying up Pin
Dr.Walt Fair, PE14-Jun-10 13:33
professionalDr.Walt Fair, PE14-Jun-10 13:33 
GeneralRe: Tidying up Pin
Dan Mos14-Jun-10 14:33
Dan Mos14-Jun-10 14:33 
GeneralRe: Tidying up Pin
PIEBALDconsult14-Jun-10 16:56
mvePIEBALDconsult14-Jun-10 16:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.