HOWTO: Create an SQL Command with > 255 Characters

Last reviewed: February 21, 1997
Article ID: Q163800
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0, 5.0

SUMMARY

It is often necessary to create an SQLEXEC command that contains more than 255 characters. But, if the command does contain more than 255 characters you will get a "syntax error" message. This article demonstrates one example of how the "insert string" might be concatenated to avoid this behavior.

MORE INFORMATION

The following is an example of how you might use concatenation to execute a SQLEXEC command that would require more that 255 characters:

      handle=SQLCONNECT("<data source>")
      m=SQLEXEC(handle, "CREATE TABLE t255 (one char(50)," + ;
         "two char(50), three char(50), four char(50)," + ;
         "five char(50), six char(50))")


      * The next command will insert the string successfully.
      b=SQLEXEC(handle, "INSERT INTO t255 (one) ;
         VALUES('xxxxxxjklmnopqrstuvwabcdefghijklmnopqrstuvw')")

      * The next command will also insert successfully.
      b=SQLEXEC(handle, "INSERT INTO t255 (one,two,three,four) ;
        VALUES("'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'"))

      *The next command will produce a syntax error because the length
      *of the string starting with insert is more than 255 characters.
      b=SQLEXEC(handle, "INSERT INTO t255 (one,two,three,four,five) ;
         "VALUES("'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'," + ;
         "'abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'")")

      f1='abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'
      f2='abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'
      f3='abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'
      f4='abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'
      f5='abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'
      f6='abcdefghijklmnopqrstuvwabcdefghijklmnopqrstuvw'

      *The next line works because there is no string
      *longer than 255 characters
      b=SQLEXEC(handle, "INSERT INTO t255" + ;
         "(one,two,three,four,five,six) " + ;
         "VALUES('"+ f1 + "','" + f2 + "','" + ;
         f3 + "','" + f4 + "','" + f5 + "','" + ;
         f6 + "')")


KBCategory: kbusage kbhowto
KBSubcategory: FxenvMemory FxprgClientsvr vfoxwin
Additional reference words: 3.00 5.00



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 21, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.