Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:27 PM
[workmute] Let's talk about the stupidest bug I've encountered to date at this job
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:28 PM
This is for a piece of functionality related to search and SQL statements
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:29 PM
where part of it is passing in a list of IDs to a SQL statement
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:29 PM
I will try to keep this newbie-parsable if I can
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:29 PM
so basically it's going "find things in this table where the IDs are in this list"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:29 PM
and when it's correct, that last bit looks something like "WHERE ID IN (5, 7, 100, 150)"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:30 PM
And how it gets that list is that it takes the IDs, kludges them together into a comma-delimited string, and throws it into the SQL statement
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:30 PM
so on the code side, there's an "idString" that has the string "5,7,100,150"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:30 PM
but
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:30 PM
and here's where it gets stupid
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:30 PM
some of these IDs are very large
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:31 PM
and being stored as strings, not numbers, because some of our tables use string-based IDs
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:31 PM
and for some fucking reason,
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:31 PM
these large numbers as strings are coming in with commas separating every third digit, like you do when writing numbers traditionally
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:31 PM
like, ID 77500 is stored as "77,500"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:32 PM
fellow programmers may see where this is going
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:32 PM
if the function tries to get the info on the records with IDs 50, 100, and 77500
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:32 PM
then the SQL ends up being "WHERE ID IN (50,100,77,500)"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:32 PM
and instead of looking for ID 77500, it looks for ID 77 and ID 500
kamikasei
@kamikasei
Fri, Sep 12, 2014 2:32 PM
Who the fuck thought the toString() function for internal use should pretty-print?
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:33 PM
I honestly don't know how it's happening
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:33 PM
but this is
so dumb
kamikasei
@kamikasei
Fri, Sep 12, 2014 2:33 PM
What's the language? Maybe there's some global setting somewhere telling it how to format string representations?
kamikasei
@kamikasei
Fri, Sep 12, 2014 2:34 PM
But yes that is super dumb.
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:34 PM
C#
izzy.vrm
@alqemizzy
Fri, Sep 12, 2014 2:34 PM
w ow that's super dumb
Rama
@Nerdorama
Fri, Sep 12, 2014 2:37 PM
Well, C# is a Microsoft language, so there you go
Rama
@Nerdorama
Fri, Sep 12, 2014 2:37 PM
Of course it breaks every piece of Microsoft software it has to interact with
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:45 PM
occasionally stupidities aside I actually reall like C#
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:45 PM
really*
Cold XC
@UltraDude
Fri, Sep 12, 2014 2:47 PM
ouch
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:48 PM
just because I fucking love Linq
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:48 PM
it's so useful for business programming
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:48 PM
like, if I have a requirement of "get the list of IDs from this list, but only from the list items that are Enabled, and strip the commas out of the IDs, then return the list"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:48 PM
I can do that in one fucking line of code
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 2:49 PM
list.Where(x => x.Enabled).Select(y => Regex.Replace(y, ",", string.Empty))
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 4:49 PM
in other workmute news
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 4:50 PM
>"Wow, it's already noon and I'm just starting to get hungry! My appetite is in good form today!"
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 4:50 PM
>I was checking the clock on a host I was remote desktopped into
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 4:50 PM
>That host is in New York
Quinneapolis
@quinn2win
Fri, Sep 12, 2014 4:50 PM
>Lunch is in an hour
載入新的回覆
list.Where(x => x.Enabled).Select(y => Regex.Replace(y, ",", string.Empty))