Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » ParseForArguments does not take comments in account
ParseForArguments does not take comments in account [message #26736] Sun, 23 May 2010 23:01 Go to next message
frankdeprins is currently offline  frankdeprins
Messages: 99
Registered: September 2008
Location: Antwerp - Belgium
Member
Hi,

As I already pointed out in another thread, 'SQLITE3: Bind parameter by name', the function ParseForArguments in Sqlite3upp.cpp mistakingly counts question marks inside comments as bind variables, making it impossible to execute such statements.
I made some modifications to this function to correct this behaviour and would appreciate if you would consider it for inclusion.

int ParseForArgs(const char* sqlcmd)
{
   int numargs = 0;
   const char* ptr = sqlcmd;
   while (*ptr)
      if(*ptr == '\'')
         while(*++ptr && (*ptr != '\'' || *++ptr && *ptr == '\''))
            ;
      else if(*ptr == '-' && *++ptr && *ptr == '-')
         while(*++ptr && *ptr != '\n' && *ptr != '\r')
            ;
      else if(*ptr == '/' && *++ptr && *ptr == '*')
         while(*++ptr && *ptr != '*' && *++ptr && *ptr != '/')
            ;
      else if(*ptr++ == '?')
         ++numargs;
   return numargs;
}


frank
Re: ParseForArguments does not take comments in account [message #26797 is a reply to message #26736] Fri, 28 May 2010 14:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11844
Registered: November 2005
Ultimate Member
Thanks, applied.
Re: ParseForArguments does not take comments in account [message #26813 is a reply to message #26797] Sun, 30 May 2010 23:35 Go to previous messageGo to next message
frankdeprins is currently offline  frankdeprins
Messages: 99
Registered: September 2008
Location: Antwerp - Belgium
Member
I'm afraid I still spotted an error in it Embarassed . The line
   while(*++ptr && *ptr != '*' && *++ptr && *ptr != '/')
is still not correct because /* */ comments will be seen as closed as soon as there is an asterisk, even with or without a slash following it. I will look ino this tomorrow.

Sorry for the inconvenience

[Updated on: Sun, 30 May 2010 23:47]

Report message to a moderator

Re: ParseForArguments does not take comments in account [message #26821 is a reply to message #26813] Mon, 31 May 2010 11:26 Go to previous messageGo to next message
frankdeprins is currently offline  frankdeprins
Messages: 99
Registered: September 2008
Location: Antwerp - Belgium
Member
This should fix it
int ParseForArgs(const char* sqlcmd)
{
   int numargs = 0;
   const char* ptr = sqlcmd;
   while (*ptr)
      if(*ptr == '\'')
         while(*++ptr && (*ptr != '\'' || *++ptr && *ptr == '\''))
            ;
      else if(*ptr == '-' && *(ptr+1) == '-')
         while(*++ptr && *ptr != '\n' && *ptr != '\r')
            ;
      else if(*ptr == '/' && *(ptr+1) == '*')
      {
         ptr++;
         while(*++ptr && (*ptr != '*' || (*(ptr+1) && *(ptr+1) != '/')))
            ;
      }
      else if(*ptr++ == '?')
         ++numargs;
   return numargs;
}
Re: ParseForArguments does not take comments in account [message #26824 is a reply to message #26821] Mon, 31 May 2010 20:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11844
Registered: November 2005
Ultimate Member
Applied again Smile
Re: ParseForArguments does not take comments in account [message #26829 is a reply to message #26824] Tue, 01 June 2010 07:07 Go to previous message
frankdeprins is currently offline  frankdeprins
Messages: 99
Registered: September 2008
Location: Antwerp - Belgium
Member
thanks; I'll doublecheck twice, next time
Previous Topic: Column type for SQLite
Next Topic: Two tables sharing same field name?
Goto Forum:
  


Current Time: Thu Apr 25 12:40:53 CEST 2019

Total time taken to generate the page: 0.00978 seconds