You will not have any more records from this database! No!



  • Wasn't sure if this was front page material or not... so decided to post here anyway - mainly to see if anyone could explain it to me... I get the feeling that (mainly as i'm not a vb programmer) there might be a reason for this one.

    Anyway, here it is:

    I work as a consultant at an investment bank. Today I was asked to fix a problem with a trading application.
    The application had a function that allowed a user to type in a select query to pull out information from a database. The whole application was a bit of a mess - using a visual basic dll written as a "quick solution" a long time ago. So reluctantly (not being a vb programmer), I took a look.

    The problem was that no query on a database would return more than 1820 rows...
    This has been a major problem for months apparently. And the users had been writing work-arounds such as select ... where id > 1820 to pull out extra information.

    I open the dodgy vb code for what I expect to be a lengthy debugging session of horrible code and the very first thing I see is:

    If ((numrows > 1820) And SpdSheet) Then numrows = 1820
            'this is the limit that an array can take
           
            myarray = myRecord.GetRows(numrows)

    So some programmer decided to limit the results returned for everyone and enter in the spurious reason that "this is the limit that an array can take"... which is of course : bollocks.

    Fixing it so quickly made me look good though. I didn't bother telling them how.

    Note: I did do a search on google and could find no evidence of vb using odbc having any kind of limit ever on number of rows returned... I did think that the programmer could have had a legitimate reason for doing this... perhaps someone could explain my "wtf?".



  • is it returning an Excel spreadsheet?

    You did mention that this is rather old code. Excel has a limit to the number of rows it can handle and that limit may at some point have been 1820.



  • The dll is also used to return rows to an excel spreadsheet - yes.
    However the maximum number of rows in excel is 65536 (i believe...or at least it was). I can't believe it was as low as 1820? Anyone?
    Either way - the code is old... but not that old i don't think. 5 years max at a guess i would say.



  • Well, however the case might be, you certainly came to the right place :-)

    Rest, relax and enjoy life; you're among friends now ;-)



  • <FONT face=Arial>In Excel 7.0 (the win95 version) the limit was 16,384 by 256 columns, and believe this was the limit up to Excel 7.0.

    Not sure why a limit should be 1820 so can understand your wtf :)</FONT>



  • @dcollis said:

    The dll is also used to return rows to an excel spreadsheet - yes.
    However the maximum number of rows in excel is 65536 (i believe...or at least it was). I can't believe it was as low as 1820? Anyone?
    Either way - the code is old... but not that old i don't think. 5 years max at a guess i would say.

    Often times, these WTF arise from the human engineering factor. I can just see the boss saying, "What's with all these rows? I can't read all this! Let's cut this down to size..."

    I'm only half joking.



  • @dcollis said:



    I open the dodgy vb code for what I expect to be a lengthy debugging session of horrible code and the very first thing I see is:

    If ((numrows > 1820) And SpdSheet) Then numrows = 1820
            'this is the limit that an array can take
           
            myarray = myRecord.GetRows(numrows)

    "wtf?".


    My two cents: I'm a little fuzzy on this topic, but I did used to be a VB 6 programmer, back at a lab in school. :^) Then I discovered [your favorite real OO language--not the other one you like to disparage].

    Anyway, we don't know the type of the array, but the code snippet says it's actually a VB "array". Guess what? If you declare an array variable inside a function like this:

    Function funky()
        Dim myarray() as [TYPE]
    End Function

    then myarray is a giant value on the stack, IIRC. In other words, it has a maximum size--a horribly small maximum size, dependent on the size of the type the array is containing. 4 bytes each for Integers (or Ints or whatever VB called them) and I think 20 bytes each for Objects. How big is the function call stack in VB 6? 64kB? Best case, how many 20-byte Objects (references) can you fit in it? About 3200.

    I'm guessing GetRows() in fact does return an array of some kind of Object, not a primitive type, so it follows that our friend probably just started guessing numbers, compiled, and tested, until he got the biggest array he could without overflowing the stack (after whatever the calling function already had on the stack, etc.

    How does all that sound?



  • @Brendan Kidwell said:

    @dcollis said:


    I open the dodgy vb code for what I expect to be a lengthy debugging session of horrible code and the very first thing I see is:

    If ((numrows > 1820) And SpdSheet) Then numrows = 1820
            'this is the limit that an array can take
           
            myarray = myRecord.GetRows(numrows)

    "wtf?".
    ...I'm
    guessing GetRows() in fact does return an array of some kind of Object,
    not a primitive type, so it follows that our friend probably just
    started guessing numbers, compiled, and tested, until he got the
    biggest array he could without overflowing the stack (after whatever
    the calling function already had on the stack, etc.

    How does all that sound?

    <font size="5">I</font> think you have hit upon it.  65536 bytes is the largest array size in a 16-bit application.




  • That could be it you know! Nice reasoning :).

    Although, it could also be that the guy had just had a bad day and wanted to screw things up for people in the future...


Log in to reply