• nagesh_is_a_troll! (unregistered) in reply to Nagesh
    Nagesh:
    tkyte:
    read the code. resp is defaulted to 0.
        if(rs.first()) resp = rs.getDouble("result");
    

    If there is a row, it gets a value, otherwise it leaves resp alone.

    and then returns it.

    The original poster got it right - it returns 0 if dual is empty - which can happen in 9i and before (in 10g with fast dual - unlikely)

    Stop faking. You're not real Mr Tom Kyte, are you? Unless he's a namesake of yours.

    Now I understand why others call you a troll!!

  • Nils (unregistered) in reply to Oracle Marketer

    How about:

    create table calc ( c_cost number, c_discount number result always generated as (c_cost-c_discount) virtual) ;

    and then

    public double calculateCostSQL(double cost,double discount){ ResultSet rs = null; double resp = 0; try{ String quer1 = null; quer1 = "INSERT INTO calc c_cost,c_discount values ("cost","discount")"; dbm.query(quer1); String quer2 = null; quer2 = "select result FROM calc where c_cost= "cost" and c_discount="discount; rs = dbm.query(quer2); if(rs.first()) resp = rs.getDouble("result"); } catch(Exception e){ e.printStackTrace(); } finally{ try{ if(rs != null){ rs.close(); rs = null; } } catch(Exception e){ e.printStackTrace(); } } return resp; }

    Well...????

  • Brad (unregistered)

    Actually, there is a valid reason for performing it in this manor. As is a somewhat common occurrence on high performance, virtualized environments like the one this enterprise application was running on, mathematics chips fail on local machines.

    By utilizing the mathematics processing system (MPS) functionality on the Enterprise edition of Oracle 9g+, you can be assured that whilst a numerical operation may fail due to a similar mathematics chip failure, it will fail consistently throughout the entire organisation, meaning that it only needs to be repaired and adjusted in one place to fix it company wide. This simply makes sense, from a time saving and code quality point of view.

    This is why I always code a fresh operating system for every application I release.

  • John (unregistered)

    But the original version also includes the extra feature of database query parsing - removing this code may make the poor dba wonder why his shared pool isn't being trashed anymore

  • Jackwagon (unregistered) in reply to hoodaticus
    hoodaticus:
    Satisfyed Customer:
    Is it just me, or have we had a huge reduction in trolling recently (accepting the boog and frits posts)?
    They've been deleting posts by trolls. Except, as noted, from boog, frits, frits's secret admirer, and me.
    I for one think this is a terrible idea. First of all, it only serves to breed smarter, stronger, more persistent trolls. As soon as the resolve of the moderator quits, the forums are swamped with 'em. What happened to the traditional way of dealing with trolls: ignore? Second, how exactly do you tell a "troll" post? I've watched some comments vanish that made me wonder "huh?" I also see some persist that shoudl go away.

    Methinks boog and frits are friends of Alex's, since they do nothing but post irrelevant and provocative comments which never get deleted.

  • Peter (unregistered) in reply to Brad
    Brad:
    Actually, there is a valid reason for performing it in this manor. As is a somewhat common occurrence on high performance, virtualized environments like the one this enterprise application was running on, mathematics chips fail on local machines.

    By utilizing the mathematics processing system (MPS) functionality on the Enterprise edition of Oracle 9g+, you can be assured that whilst a numerical operation may fail due to a similar mathematics chip failure, it will fail consistently throughout the entire organisation, meaning that it only needs to be repaired and adjusted in one place to fix it company wide. This simply makes sense, from a time saving and code quality point of view.

    This is why I always code a fresh operating system for every application I release.

    Topcod3r? Is that you?

  • Brendan (unregistered) in reply to Ben

    Hi,

    Ben:
    I suspect they wanted to use fixed-point numbers when handling currency. Alas, the parameter and return types are all floating-point, which is TRWTF.

    No... "double cost" just means it's a large business and therefore everything costs twice as much as it should. The discount is double because the cost is double. For example, if something should cost $10 and you get a ("%10 off") discount of $1, then you actually pay $20 less a "double discount" of $2.

    At least that's how the marketing department explained the "double discount" system to me...

    • Brendan
  • (cs) in reply to Jackwagon
    Jackwagon:
    Methinks boog and frits are friends of Alex's, since they do nothing but post irrelevant and provocative comments which never get deleted.
    Yeah? Well you're a towell!
  • (cs) in reply to boog
    boog:
    ...keeping management informed of trivial operations like subtraction is almost as important as connecting to a database for the sole purpose of performing said subtraction.
    Indeed!
  • FuBar (unregistered) in reply to junior
    junior:
    For crying out load kids, there was 15 years when it was standard, normal, ordinary to use Double for currency.
    Which 15 years were those? I can't think of a 15 year period when COBOL hasn't done most of that sort of thing.
  • Ben (unregistered)

    I really hope this is real. It would make me feel better about the code I have to deal with on a daily basis.

  • (cs) in reply to Jackwagon
    Jackwagon:
    Methinks boog and frits are friends of Alex's, since they do nothing but post irrelevant and provocative comments which never get deleted.

    Jealousy makes you ugly in your face, sockpuppet #5.

  • (cs) in reply to Jackwagon
    Jackwagon:
    Methinks boog and frits are friends of Alex's, since they do nothing but post irrelevant and provocative comments which never get deleted.
    Never say never. And if my comments that don't get deleted are that bad, think how bad my comments that do get deleted must be.
  • airdrik (unregistered) in reply to Ben
    Ben:
    I really hope this is real. It would make me feel better about the code I have to deal with on a daily basis.
    Of course it's real - they are doubles, after all, and you can't represent complex numbers with just a double.
  • zdux (unregistered) in reply to boog

    I believe both of you work at my company.

  • tekHedd (unregistered)

    I guess sarcasm and real life experiences aren't part of the paradigm here.

  • (cs)

    The way I see it, the SELECT should have been moved into a parameterized stored procedure that sets the isolation level to repeatable read and then acquires a table lock on all system tables just to keep the entire DBMS in a deterministic state.

    Finally, several tiers of data access and business logic classes, ideally located on separate server instances, should be designed to encapsulate the logic and error handling. The exception should then be changed and written to a corresponding web service that collects all exceptions.

    From there, you can build a reporting system to allow the subtraction failures to be tracked.

    That's my $0.02.

  • Neil (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    anon:
    dpm:
    Cantabrigian:
    Example: the (fortunately now obsolete) C/UNIX "creat()" function. Why? Who thought that was a good idea?
    http://en.wikiquote.org/wiki/Kenneth_Thompson

    Ken Thompson was once asked what he would do differently if he were redesigning the UNIX system. His reply: "I'd spell creat with an e."

    Wait for it... wait for it... he already did!
    I dunno, maybe he meant, like, at the end.

    fd = crate("fred.txt", 0664);

    0666 - please don't second-guess the user's umask. Plus it annoys fundamentalist Christians, of course.

  • Design Pattern (unregistered) in reply to hikari
    hikari:
    Qvazar:
    But the original returns 0 if the DUAL table is empty... :S

    I'm attempting to work out if you do use Oracle and that's satire or if you don't and you don't know about TRWTF that is the DUAL table.

    FTFY.

    CAPTCHA: dolor

    SELECT pain FROM dolor
    
  • kosh (unregistered) in reply to Severity One

    Nope, DES key lengths are always 56-bit. Triple DES then has two recommended keying options, one which uses a pair of 56-bit keys (for an effective 112-bit key length) and one which uses three ("168-bit").

    If you wrote crypto code without that kind of basic knowledge of the standard you have repeated a very common crypto WTF. I hope you're not protecting anything important.

  • Ben (unregistered) in reply to airdrik
    airdrik:
    Ben:
    I really hope this is real. It would make me feel better about the code I have to deal with on a daily basis.
    Of course it's real - they are doubles, after all, and you can't represent complex numbers with just a double.

    Lol! I guess /. isn't the only good place for nerd jokes

  • SurturZ (unregistered)

    My guess is that there was a difference in the way the database and the programming language rounded the result.

  • Adrian Ponoran (unregistered)

    He should have used a parallel query to perform the calculation :-))

  • Marc (unregistered)

    Oh man! Why complicate such simple things?

  • David Martensson (unregistered) in reply to frits

    But that would not require a call to another machine unless you place the JS engine in a cloud perhaps :D

  • (cs)

    The Marshal? Isn't like a title of a movie or series? But it's a good name. Impressive.

  • DocWilco (unregistered) in reply to Brad

    Bingo!

    Or weren't we playing bullshit bingo?

  • anon (unregistered)

    Doesn't Oracle do calculations in BCD?

    If the calculation depended on BCD then he may have broken it.

    Of course a better fix would be to call a local BCD Library.

  • Augusto (unregistered)

    Many years ago, a friend of mine who was learning php WHILE building a website for a company, used to do the same thing to do any kind of arithmetic operations... ahhh

  • Zac (unregistered)

    A problem tailor-made for Mechanical Turk

  • Megapatch (unregistered)

    Since the Oracle can handle numbers with a precision of 39 digits there is of course a meaning with this... Java double has only something like 15 digits.

    Now Oracle has no problems in calculating that "1.0000000000000001 - 1" is 1E-16, whereas Java thinks it is zero... This rewrite might have introduced an interesting bug.

Leave a comment on “The Marshal”

Log In or post as a guest

Replying to comment #:

« Return to Article