• (cs)

    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.)

  • the forum software is really really bad (unregistered)

    how about this forum software?

  • Dave (not that one) (unregistered)

    I like the way both variables are declared varchar(100)just in case you want them to be 'YYYYYYYYEEEEEEESSSSSSS' or something like that. Why send a bit when 100 bytes will work? Unfortunately, he didn't use nvarchar(100) so this is clearly not suitable for international applications.

  • pFOOTi (unregistered)

    For the first time in ages, I stared at the code and actually said "What the F!"

  • denz (unregistered)

    "Both" is obviously the authors implementation of the third boolean value...

  • (cs)

    Theory.

    The application was written with separate variables for Online and Offline, because the author was stupid. Thousands of features were added which depend on having these two variables.

    A smarter person said "these are the same variable" and created the OnlineOffline variable. For compatibility, he used it to set the original two variables, so he didn't have to fix the old code.

    Along comes someone either stupid or brilliant (or more likely brillant), who says "there's actually a third mode which is both online AND offline" and creates the "Both" value.

    And of course, a rarely-used function deep in the bowels of the system sets the OnlineOffline variable to "FileNotFound", which breaks everything.

  • (cs) in reply to CDarklock

    It is a case of enmeshed double-backloop logic, in which the truth of the opposite does not necessarily imply the falsness of the other, nor does it negate the other way around if the same becomes truly false.

    See? Simple!

    It's that higher system Godel implied which can express the contradictory/recursive/closured logic found in our current system.

  • Slacker (unregistered)

    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.

  • Jax (unregistered)

    -True -False -FileNotFound

    The CAPTCHA is "ewww" which is exactly my thoughts about this section of code.

  • Pol (unregistered)

    I'm confused how someone can be online and offline at the smae time!

  • Unomi (unregistered)

    The WTF is actually:

    He states 'Both':

    Online = 'Y' // Thus it's online Offline = 'N' // Thus it's NOT offline

    He states 'Y': Online = 'Y' // Thus it's online

    He states 'Y': Offline = 'N' // Thus it's NOT offline

    So.... It is ALWAYS online!!!! There is nothing to check, since the answer is always the same!!!! Simply saying:

    Online = TRUE

    Would be the only answer possible and saves a lot of lines.

    Captcha: howdy (I'm fine thank you)

    • Unomi -
  • (cs) in reply to Pol
    Pol:
    I'm confused how someone can be online and offline at the smae time!

    I'm confused about someone can be online and not be offline. Sounds like the Matrix to me.

  • Unomi (unregistered) in reply to Unomi
    Unomi:
    The WTF is actually: He states 'Y': Offline = 'N' // Thus it's NOT offline

    Should be:

    He states 'N': Offline = 'N' // Thus it's NOT offline

    Sorry about that...

    Captcha: ewww (I already said sorry, 'K??)

    • Unomi -
  • (cs) in reply to cout
    cout:

    I'm confused about someone can be online and not be offline. Sounds like the Matrix to me.

    unfortunately, no one can be told what offline is.

    I suggest the blue pill.

  • (cs)

    FOOLS!!! It's simple ternary logic. Using varchar as the data type to represent it is the real WTF.

    Captcha: doom (you didn't need to tell me)

  • DDT (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.)

    I think you got it.

    Taking snippets out of context can cause them to not make any sense, but in context you understand the code easily.

    Sure, in this particular case, it may not be a perfect solution, but it works quite well if you think about it.

  • Matt (unregistered) in reply to DDT

    It's obvious that this is for a high availability system that must always be online.

  • Trash (unregistered)

    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','').

    So, it's a FileNotFound inside a FileNotFound.In fact, if @OnlineOffline='Both',at least it gets "consistent" values for @Online and @Offline...

  • webdev101 (unregistered) in reply to CDarklock
    CDarklock:
    Theory.

    The application was written with separate variables for Online and Offline, because the author was stupid. Thousands of features were added which depend on having these two variables.

    A smarter person said "these are the same variable" and created the OnlineOffline variable. For compatibility, he used it to set the original two variables, so he didn't have to fix the old code.

    Along comes someone either stupid or brilliant (or more likely brillant), who says "there's actually a third mode which is both online AND offline" and creates the "Both" value.

    And of course, a rarely-used function deep in the bowels of the system sets the OnlineOffline variable to "FileNotFound", which breaks everything.

    As far as I can see the @Online variable will always have one of the two values null or 'Y' and @Offline variable will always have one of the two values null or 'N'. I am not sure what he does with the values.

    Captcha: smile :)

  • Thimp (unregistered) in reply to dhromed

    Yes, I believe you are right, it's a godel thingy. Still .. if you are neither online, nor offline, and i accept that is follows that you have to be both, I still dont accept you are either ...

    At least that's wat my tortoise named Achilles claimes

  • Pablo (unregistered)

    That is NOT a piece of SQL

  • Rich (unregistered) in reply to 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.

    So we're checking online/offline status of Schroedinger's cat?

    captcha: sanitarium

  • (cs) in reply to DDT
    DDT:
    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.)

    I think you got it.

    Taking snippets out of context can cause them to not make any sense, but in context you understand the code easily.

    Sure, in this particular case, it may not be a perfect solution, but it works quite well if you think about it.

    That still begs the questions why you need to check for onlinestatus. You are either online or you aren't. That would make these two SQL statements identical in functionality:

    SELECT * FROM some_user_table WHERE onlinestatus = @Online OR onlinestatus = @Offline //always returns all records

    SELECT * FROM some_user_table //always returns all records

  • DDT (unregistered) in reply to Rich

    Ok, let me spell it out for you all.

    Imagine this :

    CREATE PROCEDURE GetUsersByOnlineStatus
        @OnlineOffline VARCHAR(100)
    AS
    
    DECLARE @Online varchar(100)
    DECLARE @Offline varchar(100)
    
    IF @OnlineOffline = 'Both'
    BEGIN
        SET @Online = 'Y'
        SET @Offline = 'N'
    END
    
    IF @OnlineOffline = 'Y'
        SET @Online = 'Y'
    
    IF @OnlineOffline = 'N'
        SET @Offline = 'N'
    
    
    SELECT * 
    FROM users 
    WHERE 
        isOnline = @Online OR 
        isOnline = @Offline 
    
    END
    

    So when you call GetUsersByOnlineStatus with 'Y' you get online users, with 'N' you get offline users, and with 'Both' you get... both.

  • DF5 (unregistered) in reply to Pablo

    Oh! That's the WTF.

    quake - ahh, those were the days.

  • Pon (unregistered) in reply to akatherder
    akatherder:

    That still begs the questions why you need to check for onlinestatus. You are either online or you aren't. That would make these two SQL statements identical in functionality:

    SELECT * FROM some_user_table WHERE onlinestatus = @Online OR onlinestatus = @Offline //always returns all records

    SELECT * FROM some_user_table //always returns all records

    Take MSN for example. You can be online (i.e. signed in), and appear offline at the same time. So, you would be both online and offline... Depending on your frame of reference ;)

    CAPTCHA: relativity ftw

  • (cs)

    We should consider, that it could be online or not in about 6,6*10^240 Ways. So, about 256^100. And we also consider that it is the same with offline (or not).

    I want to see anybody working out that much ways of beeing online or offline ;)

  • (cs)

    I think this SQL fragment is the equivalent of Abbot & Costello's "Who's on First" skit. Or maybe that scene from Airplane 2: "Unger, didn't you serve under Oveur in the Air Force?" "Not directly. Technically, Dunn was under Oveur and I was under Dunn." Et cetera.

  • Asd (unregistered) in reply to DDT
    DDT:
    Ok, let me spell it out for you all. So when you call GetUsersByOnlineStatus with 'Y' you get online users, with 'N' you get offline users, and with 'Both' you get... both.

    That actually is kind off clever, in a really stupid way.

  • Andy (unregistered)

    It looks like the @OnlineOffline field is used to indicate which of the other two fields, or both, is to be set.

    The code is called when the status becomes online.

    There should be a similar block of code when the status becomes offline.

    captcha: Tesla. But give the credit to Edison since he had the business case right.

  • Anonymous (unregistered) in reply to Andy

    Is like Womens. Womens are online. Only not available to YOU.

  • (cs) in reply to DDT
    DDT:
    Ok, let me spell it out for you all.

    Imagine this :

    CREATE PROCEDURE GetUsersByOnlineStatus
        @OnlineOffline VARCHAR(100)
    AS
    
    DECLARE @Online varchar(100)
    DECLARE @Offline varchar(100)
    
    IF @OnlineOffline = 'Both'
    BEGIN
        SET @Online = 'Y'
        SET @Offline = 'N'
    END
    
    IF @OnlineOffline = 'Y'
        SET @Online = 'Y'
    
    IF @OnlineOffline = 'N'
        SET @Offline = 'N'
    
    
    SELECT * 
    FROM users 
    WHERE 
        isOnline = @Online OR 
        isOnline = @Offline 
    
    END
    

    So when you call GetUsersByOnlineStatus with 'Y' you get online users, with 'N' you get offline users, and with 'Both' you get... both.

    Rather than crazy logic like that, why not just roll the checks into the sql query:

    
    CREATE PROCEDURE GetUsersByOnlineStatus
        @OnlineOffline VARCHAR(100)
    AS
    BEGIN
    
    SELECT * 
    FROM users 
    WHERE 
        @OnlineOffline = 'Both' OR
        (
          ( @OnlineOffLine = 'Y' and isOnline = 'Y' )
             OR 
          ( @OnlineOffline = 'N' and isOnline = 'N' )
        )
    
    END
    
  • DDT (unregistered) in reply to s0be
    s0be:
    Rather than crazy logic like that, why not just roll the checks into the sql query:
    
    CREATE PROCEDURE GetUsersByOnlineStatus
        @OnlineOffline VARCHAR(100)
    AS
    BEGIN
    
    SELECT * 
    FROM users 
    WHERE 
        @OnlineOffline = 'Both' OR
        (
          ( @OnlineOffLine = 'Y' and isOnline = 'Y' )
             OR 
          ( @OnlineOffline = 'N' and isOnline = 'N' )
        )
    
    END
    

    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.

  • (cs) in reply to Pol
    Pol:
    I'm confused how someone can be online and offline at the smae time!
    what about systems that allow multiple connections? One could be online, the other offline; Of course, then an intelligent person would have 2 flags: loggedInChannelOne and loggedInChannel2, but hey, what do I know?
  • DM (unregistered) in reply to pFOOTi
    pFOOTi:
    For the first time in ages, I stared at the code and actually said "What the F!"

    For the millionth time....I laughed my @$$ off.

  • jKent (unregistered) in reply to Thimp
    Thimp:
    Yes, I believe you are right, it's a godel thingy. Still .. if you are neither online, nor offline, and i accept that is follows that you have to be both, I still dont accept you are either ...

    At least that's wat my tortoise named Achilles claimes

    It's really quite simple: as long as you accept that x) you have to be both online and offline, and y) (a AND b) IMPLIES a (similarly, (a AND b) IMPLIES b) then because ((p IMPLIES q) AND p) IMPLIES q z) you have to be online (similarly, you have to be offline)

    Finally, I have a record for your tortise to listen to...

  • Harry (unregistered)

    An intelligent person would just keep a list of places where it was online.

    The real question is what the complete list of OnlineOffline states are. Both, None, Tuesday etc.

  • (cs) 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.

    The reason I did it my way rather than your way is yours does not deal with @OnlineOffline and isOnline both being the same, invalid value. Both could be 'Space Shuttle' and it would be returned. Doing the @a = 'Y' and @b = 'Y' would be the same as @a = 'Y' and @a = @b, with one fewer variable references. I don't have the DB schema, so I don't know whether isOnline would be enum'd into only Y or N values, in which case yours would be the same effect. But for a non enum'd varchar(100), @OnlineOffLine = isOnline could return false positives.

  • (cs) in reply to DDT
    DDT:
    Ok, let me spell it out for you all.

    So when you call GetUsersByOnlineStatus with 'Y' you get online users, with 'N' you get offline users, and with 'Both' you get... both.

    But...

    isOnline = null

    is not valid SQL, is it?

  • twp (unregistered) in reply to DDT
    DDT:
    As I said in my first post, the solution is less than perfect, but it works pretty well. It is clearly not a WTF.

    Oh, I disagree. The code shouldn't have to be a failure in order to qualify as a WTF. A function or code snippet can be technically exactly functional, may even be a smart solution to a problem in its context, and yet generate that "WTF?" reaction upon reading. I think this is an excellent example: when I saw the post, I could not possibly imagine what the author had intended, and yet you and fennec came up with an entirely plausible explanation. Kudos to you both.

  • Ben S. (unregistered)

    Hehe, man you guys have WAY too much time on your hands.

    Actually it is not regarding users online, it is regarding the status of some piece of data.

    Some pieces can be online, others offline. Some users want to see both of these.

    The WTF is really that they used a stupid dropdown to provide a parameter for a reporting services stored procedure.

    The naming is totally not logical.

    Would you like coffe or tea? Yes please!

  • (cs) in reply to DDT
    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).

  • GrandmasterB (unregistered) in reply to Dave (not that one)
    Dave (not that one):
    I like the way both variables are declared varchar(100)just in case you want them to be 'YYYYYYYYEEEEEEESSSSSSS' or something like that. Why send a bit when 100 bytes will work? Unfortunately, he didn't use nvarchar(100) so this is clearly not suitable for international applications.

    Its a 'varchar', so the db will store up to 100 bytes, depending on what was in the field. Unlike a 'char' type, which would always store exactly 100 bytes, regardless of the field's value. So that in of itself isnt a big deal.

  • Twm (unregistered) in reply to denz

    "Both" I thought I was witnessing a Qubit!

  • justin (unregistered)

    Out of context or not, here's the results of the three possible(?) values off OnlineOffline:

    when OnlineOffline = 'Both'
    OnlineOffline Online Offline
    ------------- ------ -------
    Both          Y      N
    

    when OnlineOffline = 'Y'

    OnlineOffline Online Offline
    ------------- ------ -------
    Y             Y      NULL
    

    when OnlineOffline = 'N'

    OnlineOffline Online Offline
    ------------- ------ -------
    N             NULL   N
    

    I'm guessing there's some appendix code here somewhere. Offline is either 'N' or null, Online is either 'Y' or null. I haven't even touched on the fact that we don't see what may have happened to OnlineOffline prior to this snippet, and assuming it's also varchar(100), the value could be just about anything. Hm, what happens then?

    OnlineOffline        Online Offline
    -------------------- ------ -------
    Just About Anything  NULL   NULL
    

    WTF?

  • (cs) in reply to savar

    As I understand it, you can compare things with NULL - it's just that the result of such a comparison is always false. So

    SELECT 1 WHERE 1 = null
    and
    SELECT 1 WHERE 1 != null

    should both return 0 rows.

  • Gloves (unregistered)

    the real wtf is everybody discussing this poor code...

    Another wtf is my CAPTCHA test right now... YUMMY!

    Gloves, remember and keep for yourself: gloves! http://thedailywtf.com/Articles/The_Complicator's_Gloves.aspx

    screenshot: http://img256.imageshack.us/img256/8049/yummy6pt.jpg

  • (cs) in reply to akatherder
    akatherder:
    DDT:
    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.)

    I think you got it.

    Taking snippets out of context can cause them to not make any sense, but in context you understand the code easily.

    Sure, in this particular case, it may not be a perfect solution, but it works quite well if you think about it.

    That still begs the questions why you need to check for onlinestatus. You are either online or you aren't. That would make these two SQL statements identical in functionality:

    SELECT * FROM some_user_table WHERE onlinestatus = @Online OR onlinestatus = @Offline //always returns all records

    SELECT * FROM some_user_table //always returns all records

    Mmm, nope. Wrong. You're thinking of @Online and @Offline as the actual state. They're not. They're variables, string variables (varchar) and the way they're set out, it works like this: @OnlineOffline = 'Y' => @Online = 'Y' => @Offline = null (I think) => SELECT * FROM some_user_table WHERE onlinestatus = 'Y' OR onlinestatus = null

    @OnlineOffline = 'N' => @Online = null => @Offline = 'N' => SELECT * FROM some_user_table WHERE onlinestatus = null OR onlinestatus = 'N'

    @OnlineOffline = 'Both' => @Online = 'Y' => @Offline = 'N' => SELECT * FROM some_user_table WHERE onlinestatus = 'Y' OR onlinestatus = 'N'

    --- this one, and only this one, is equivalent to SELECT * FROM some_user_table

    • Of course this does assume a couple of things about the database (mostly that comparing to the default value / null of the variable is okay to do and doesn't return any extraneous rows - presumably the column IS NOT NULL - and 'Y'/'N' are the only values). And it's a fairly lousy way to do things, all told, really. But anywho. :)
  • RockinJack (unregistered)

    Obviously, the code is an attempt at world domination.

  • JGM (unregistered) in reply to Rich

    Nah, just Schroedinger's Mouse in this case.

Leave a comment on “Online Offline”

Log In or post as a guest

Replying to comment #112929:

« Return to Article