• cut thread (unregistered) in reply to fennec
    fennec:
    Easy enough.

    SELECT * FROM some_user_table WHERE onlinestatus = @Online OR onlinestatus = @Offline

    (forgive my weak variables-in-SQL-fu if there's anything wrong in that syntax.)

    -----------------8<----------------------

  • Auschunky (unregistered)

    I'm currently writing an application that must display a list of items (like a catalogue). The items can live online to be downloaded and displayed, or retrieved from the client PC. The user can choose to view either online items, offline items or both. Perhaps this code is for something similar.

  • (cs)

    The only possible reason i could think of for this are

    The user has subscribed for some content which has both an online and offline component and this checks whether to provide them with both, that would also explain why it's in a stored proc.

    If this is the case it's still a bit wftey but kind of understandable

  • Jman (unregistered)

    The 'users' of this application are actually spin-1/2 particles, and thus need the possibility of being in a linear superposition of two states. Come on guys, basic quantum mechanics.

  • Spinner (unregistered) in reply to Slacker
    Slacker:
    Welcome to the world of quantum computing, where a system can be online and offline at the same time. Until you measure it that is.

    ...at which point the entangled system goes into the opposite state. Bugger!

  • (cs)

    The real WTF is T-SQL's stored procedure syntax. I mean, who needs semicolons when the DB can just guess the start and end of your queries!

  • Michael (unregistered) in reply to emurphy
    emurphy:
    DDT:
    And while we're at it, isOnline should be a BIT to begin with.

    isOnline should be a BOOLEAN, but (as of SQL:2003) BOOLEAN is optional because people keep arguing about how NULL and/or UNKNOWN (sound familiar?) should be handled. PostgreSQL gets it right (I wish I could use PostgreSQL at work), everyone else has an ugly-but-good-enough equivalent (BIT is MS SQL's), which makes Joe Celko roll in his grave (despite the minor detail that he isn't actually dead).

    I don't know why there is an argument over how NULL/UNKNOWN are suppossed to be handled in logic. There happen to be two very good systems binary and trinary (digraph, and trigraph). Boolean fields have two possible values and a third that may or may not be imposed by the database, all you have to do is tick or not the "required" option. If its required it can't store null (binary logic) otherwise welcome to the joys of any operation on null returns null.

    savar:

    But...

    isOnline = null

    is not valid SQL, is it?

    you get a null. and that makes the statement (just before evaluation completes) auto mutate into a false.

    Moral of the story only perform mission critical actions in the true part of an if (especial when there are nulls about).

    I just saw the tortoise pass by...

    they failed to mention that the cat could have a third state, bloody furious.

    CAPTCHA: cognac (Yes please)

  • Anonymous (unregistered) in reply to Samah

    It's not a guess. The end (and thus the start) of each statement is precisely defined. The only reason to require semi-colons would be that you like typing.

  • Anonymous (unregistered) in reply to Trash
    Trash:
    I dont know this code context...but..I hope those values arent being used later on (umm..then, what's the point to initialize them?) because the possible values of @Online and @Offline are: ('Y','N','').

    This is T-SQL, so those values are ('Y', 'N', NULL).

  • Daef (unregistered)

    but online and offline are undefined in some cases!!

    Captha: smile ;)

  • Dougal Matthews (unregistered)

    The guy is just a retart. face it.

  • FridayUK (unregistered)

    To use a clichéd pharse around here, "The real WTF is..." is the discussion in defence of this outrageous wackyness (or grudging grossly understated acknowledgments along the lines of "well it is a bit wacky...").

    I see no compelling argument that this any but a complete "WTF?!".

    Sadly, I see madness like this fairly frequently (I can think of a similar very specific case of DB failover handling I've come across not too long ago) and find it depressing that people stick up for this sort of nonsense, let alone try and justify it.

    I'm entirely understanding of the sort of icky code and dubious kludges we all do from time to time, but the ingenious stupidity of the person who thought this up terrifies me.

    The poster who brought up the 'Gloves!' article was spot on.

    I might print this off and show this to canidates during interviews to see if I can get a feel for their revulsion to this sort of thing.

  • Daef (unregistered) in reply to gwenhwyfaer

    i think you even cannot compare to null - you have to use the IS statement

    (WHERE col IS NULL // WHERE NOT col IS NULL instead of WHERE col = NULL // WHERE col != NULL)

    Captcha: dreadlocks - funny... i have problems with deadlocks in here...

    who messed the r into my captha!?

  • Anonymous (unregistered)

    the real WTF is his failure to handle the "isVeryOnline" or "isVeryOffline" status.

  • Dave (unregistered)

    This is a clear example of Childhood Logic. Children do crazy-dumb things everyday that make perfect sense to them, and yet they don't know why they did it in the first place!

  • Dave (unregistered)

    Also, I want to see the rest of the code, especially the part that sets OnlineOffline to 'Both'. Only then can I determine if this code is truly WTF-Worthy or if it indeed makes sense from a larger perspective....or 'Both'!

  • Incen (unregistered) in reply to DDT
    DDT:
    Well if you want to be picky...
    WHERE 
        @OnlineOffline = 'Both' OR
        @OnlineOffLine = isOnline
    

    And while we're at it, isOnline should be a BIT to begin with.

    As I said in my first post, the solution is less than perfect, but it works pretty well. It is clearly not a WTF.

    Ahh, but that's not identical to the assumed intent. If @OnlineOffline = 'Both', that code would return all rows, where the original would only return those where the value is 'Y' or 'N', and not rows where it's NULL or 'WTFCentaurs'. Gotta love NULL.

  • coditza (unregistered)

    You CAN have a system both online and offline. For example Yahoo Messenger. You have a setting there that allows you to apear offline to everyone else, while you are actually online. Then you can stare for ages at the buddy list wondering why isn't anyone saying something to you. The varchar was used for extensibility. Maybe a module that would be developed latter will require a stronger Yes, like someone sugested before. However, I wonder what would happen if you finish with a value for that thing like: "YYYYYYNYYYY". This sounds like that computer nightmare.

    Captcha is "waffles" and you can see from my post I'm not hungry. Or sleepy.

  • bebo (unregistered) in reply to coditza
    coditza:
    You CAN have a system both online and offline. For example Yahoo Messenger. You have a setting there that allows you to apear offline to everyone else, while you are actually online. Then you can stare for ages at the buddy list wondering why isn't anyone saying something to you. The varchar was used for extensibility. Maybe a module that would be developed latter will require a stronger Yes, like someone sugested before. However, I wonder what would happen if you finish with a value for that thing like: "YYYYYYNYYYY". This sounds like that computer nightmare.

    Captcha is "waffles" and you can see from my post I'm not hungry. Or sleepy.

  • S (unregistered)

    Actually I know one place where this "both offline and online" stuff would've worked. Some years ago I worked for a company that tried to do messaging crap with huge money pouring in after they made some slideshows about projections and stuff that never realized. There the person could get their messages delivered online (directly to their messaging app), offline (to the offline store, e.g. IMAP mailbox) or both. So in that case it would be reasonable to see a state "both" for offline and online.

    You're just too narrow minded to think that it's always a question of someone's online status... :)

  • GrouchyAdmin (unregistered) in reply to denz
    denz:
    "Both" is obviously the authors implementation of the third boolean value...

    Precisely what I thought. I mean, what the... even if he wanted to do something dumbtarded, there's a reason for SET (Which I still feel would be inappropriate), however, if this was used to test, say, if a user has access to a feature both in 'online' and 'offline' mode..

    It's still fucking wrong, though.

Leave a comment on “Online Offline”

Log In or post as a guest

Replying to comment #:

« Return to Article