Menu

#20 Index out of Range Error in changeNamedToQmark

v1.0_(example)
closed
None
5
2014-07-28
2014-07-14
George
No

There seems to be an error in the logic of changeNamedToQmark which causes an index out of range error to be raised if the named parameter is the last word in the file (and hence there isn't non-alphanumeric character after it).

I've re-written the logic in mine to be...

            if chunk:  # there was a parameter - parse it out
                i = 0
                while i < len(chunk) and (chunk[i].isalnum() or chunk[i] == '_'):
                    c = chunk[i]
                    i += 1

                s = chunk[:i]
                chunk = chunk[i:]

Which seems to have resolved the problem.

Discussion

  • Vernon Cole

    Vernon Cole - 2014-07-14

    Dear George:
    I cannot figure out how to write a regression test for this fix.
    Would you be so kind as to look in test/adodbapitest.py around line 648 to 681 and suggest an SQL statement that will cause the failure?
    --
    Vernon

     
  • George

    George - 2014-07-15

    If you change the test on line 674 so that the parameter and field are reversed as:

    crsr.execute("SELECT fldData FROM xx_%s WHERE fldID=:Id" % config.tmp, {'Id':fldId})
    

    Then this exhibits the problem. The problem is it doesn't cope with the parameter name ending at the end of the string.

     
  • Vernon Cole

    Vernon Cole - 2014-07-28

    Doh! I must have been tired that day.

    I fixed it using "easier to get forgiveness than permission" style:

                        while c.isalnum() or c == '_':
                            i += 1
                            try:
                                c = chunk[i]
                            except IndexError:
                                break
                        s = chunk[:i]
    

    fixed in 2.6.1.0

     
  • Vernon Cole

    Vernon Cole - 2014-07-28
    • status: open --> closed
    • assigned_to: Vernon Cole
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.