Announcement

Collapse
No announcement yet.

Any limits to string literals using the _ (line continuation)?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Any limits to string literals using the _ (line continuation)?

    I'm developing a rather long SQL instruction set to create some tables for a database. Is there a limit to the size of a string literal that I can code using the underscore for line continuation?
    Bernard Ertl
    InterPlan Systems

  • #2
    255 characters.

    Comment


    • #3
      255 may be PER LINE

      By concatenating, it's essentially limitless as far as I can tell ..
      Code:
         CreateStmt  =  "CREATE TABLE  foo  (" _ 
                             &  "col1 NUMBER (12,0), " _ 
                             &  "col2 TIMESTAMP, " _ 
                             &  "col3 VARCHAR2(60), " _ 
                             &  .....
                             & "lastcol INTEGER ) "
      MCM
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Thanks Bob, I just got a compile time error for too long/complex of a MACRO which consists of trying to execute my SQL statement.

        I did mean string literal, not string equate. The compiler complained on line 32 of my (currently) 37 line statement. I'm fairly certain it's more than just 255 characters.

        Anyway, what is the best way to handle this situation? I have a known/predefined large string that I need to pass as a parameter to a function.
        Bernard Ertl
        InterPlan Systems

        Comment


        • #5
          Use a string resource
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            Code:
            // myprog.rc 
            101    RCDATA 
            BEGIN 
                 "create table foo  (", 
                 " col1 number(12,0),", 
                  "col2 TIMESTAMP,",  
                  ...,             ///  TRAILING COMMA EACH LINE IMPORTANT!
                 " lastcol INTEGER)" 
            END
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Code:
              DATA  "Create Table foo (col1 NUMBER (12,0), col2 VARCHAR(64)," 
              DATA  "col3 TIMESTAMP," 
              DATA  "coln datatype (params), ...
              DATA  ...
              DATA  "lastcol  BLOB)" 
              
                CreateStmt = READ$(1) & READ$(2).....
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                I've always wondered about that too Bern, because Visual Basic would only allow me to go ten or twelve lines or something like that. Where I run into it is with SQL statements, which I like to format like so...

                Code:
                szCreate= _
                  "CREATE TABLE Main " & _
                  "(" & _
                    "Dist         int            NOT NULL," & _
                    "Yr           int            NOT NULL," & _
                    "Num          int            NOT NULL," & _
                    "Type         int            NOT NULL," & _
                    "BF           int                NULL," & _
                    "ValBF        money              NULL," & _
                    "Hcf          int                NULL," & _
                    "ValHcf       money              NULL," & _
                    "Acres        int                NULL," & _
                    "minBid       money              NULL," & _
                    "rdCost       money              NULL," & _
                    "dtOpen       smalldatetime      NULL," & _
                    "dtExpir      smalldatetime      NULL," & _
                    "nBids        int                NULL," & _
                    "bidPrice     money              NULL," & _
                    "strBuyer     nvarchar(100)      NULL," & _
                    "Status       int                NULL," & _
                    "SawPercent   float              NULL," & _
                    "ValPerAc     money              NULL," & _
                    "ValPerMbf    money              NULL," & _
                    "ValPerHcf    money              NULL," & _
                    "FormClass    bit                NULL," & _
                    "dtExecuted   smalldatetime      NULL," & _
                    "dtTerminated smalldatetime      NULL," & _
                    "Forester     nvarchar(24)       NULL," & _
                    "SaleName     nvarchar(48)       NULL," & _
                    "gisLink      nvarchar(10)       NULL," & _
                    "cords        int                NULL," & _
                    "valcords     money              NULL," & _
                    "valothr      money              NULL," & _
                    "ObjectID     int IDENTITY(1,1)  NOT NULL," & _
                    "CONSTRAINT   [PK_Main] PRIMARY KEY CLUSTERED" & _
                    "(" & _
                      "Dist   ASC," & _
                      "Yr     ASC," & _
                      "Num    ASC," & _
                      "Type   ASC" & _
                    ")" & _
                  ");"
                
                
                             szQuery= _
                             "SELECT " & _
                               "Dist, " & _
                               "Yr, " & _
                               "Num, " & _
                               "Type, " & _
                               "BF, " & _
                               "Hcf, " & _
                               "Acres, " & _
                               "bidPrice, " & _
                               "strBuyer, " & _
                               "SawPercent, " & _
                               "dtExecuted, " & _
                               "Status " & _
                             "FROM " & _
                               "Main " & _
                             "WHERE " & _
                               "Dist=" & Trim$(Str$(i)) & " AND " & _
                               "Type" & strCriteria & " AND " & _
                               "dtExecuted>=" & strDtFirst & " And " & _
                               "dtExecuted<=" & strDtLast & " " & _
                             "ORDER BY " & _
                               "Yr, Num;"
                
                        szQuery= _
                        "SELECT " & _
                          "Species.Species, " & _
                          "Species.NetVol, " & _
                          "Main.dtExecuted " & _
                        "FROM " & _
                          "Main " & _
                        "LEFT JOIN " & _
                          "Species " & _
                        "ON " & _
                          "(Main.Type = Species.Type) AND " & _
                          "(Main.Num = Species.Num) AND " & _
                          "(Main.Yr = Species.Yr) AND " & _
                          "(Main.Dist = Species.Dist) " & _
                        "WHERE " & _
                          "(((Species.Species) Is Not Null) AND " & _
                          "((Species.NetVol) Is Not Null) AND " & _
                          "((Main.dtExecuted)>="+strDtFirst+" And " & _
                          "(Main.dtExecuted)<="+strDtLast+"));"
                So far I've never hit PowerBASIC's limit. Every time I get doing something like that and keep getting away with it I think nice thoughts of Mr. Zale.
                Last edited by Fred Harris; 10 Feb 2009, 05:13 PM.
                Fred
                "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                Comment


                • #9
                  Have you considered concanitation?

                  i.e., t$ = a$ + b$ + c$ etc.
                  ***************************

                  Nevermind. I misread your post.
                  There are no atheists in a fox hole or the morning of a math test.
                  If my flag offends you, I'll help you pack.

                  Comment


                  • #10
                    I did a bit more testing and it appears the problem is that my function call with the large string literal is located inside a MACRO. If I copy the same code directly into a function, it compiles without error.
                    Bernard Ertl
                    InterPlan Systems

                    Comment


                    • #11
                      Somewhere in help is a documented number of characters limit for MACROs.
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Not sure about Literals, but at some point I would think "Under-The-Hood" would become either

                        String - Directly from the docs ("Dynamic strings can contain up to approximately 2 Gb (2^31) characters")

                        Asciiz String - Directly from the docs ("STATIC and GLOBAL Scalar (non-array) ASCIIZ strings may be up to 16,777,216 bytes each.")

                        as a further point of examination that I have not done myself but could be easily tested would be "Are the Characters wide? or not?)....safe bet would be ASSUME 2 bytes per character, but testing point would be 1 byte per char
                        :shhh:
                        Engineer's Motto: If it aint broke take it apart and fix it

                        "If at 1st you don't succeed... call it version 1.0"

                        "Half of Programming is coding"....."The other 90% is DEBUGGING"

                        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                        Comment


                        • #13
                          Just for fun (I like to see the numbers roll over). The string rolls over after about 5 or 6 hundred million characters, several times, then GPF's.

                          No point here, just a curiosity.

                          '
                          Code:
                          'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
                          #Dim All 
                          #Compile Exe  
                          #Include "WIN32API.INC"
                          '
                          Global hdlg As Dword                
                          %Id_Exit_Btn = 1000
                          %Id_Sample_Textbox = 1001
                          %Id_Show_Result_Btn = 1002
                          ' 
                          Macro Common_Locals 'Macro easier than retyping and maintains coding consistency
                            Global Dlg_hght, Dlg_Wd As Long 'Global in case want to use in Controls
                            Local Row, col, hght, wd, Longest,ctr, ln, ln1, i As Long
                            Local  l, s As String
                          End Macro  
                          '
                          CallBack Function Dialog_Processor              
                            Common_Locals
                            Select Case CbMsg     'This is TO determine the message TYPE 
                               '       
                               Case %WM_INITDIALOG'<- Initialiaton when the program loads 
                               '
                               Case %WM_SYSCOMMAND 'Traps Any Alt key but only F4 closes              
                               '
                               Case %WM_COMMAND  'This processes command messages
                                 Select Case CbCtl
                                   Case %Id_Show_Result_Btn 
                                      For ctr = 1 To 1000000 'million
                                          s$ = s$ & String$(9999973,  (ctr Mod 128))
                                          Control Set Text CbHndl, %Id_Sample_Textbox, Using$("#, times String = #, Bytes long   ", ctr, Len(s$)) & Right$(s$, 1000)
                                          Control ReDraw CB.Hndl, %Id_Sample_Textbox
                                      Next ctr  
                          
                            ? Using$("string = #, characters", Len(s$)),, "Done testing"
                                        ? l$, , FuncName$
                                   Case %Id_Exit_Btn
                                     Select Case CbCtlMsg        
                                        Case 0
                                          Dialog End CbHndl 'Applikation beenden
                                     End Select
                                 End Select
                            End Select
                          End Function
                          '
                          Function PBMain
                            Common_Locals
                            Dlg_hght = 400
                            Dlg_Wd = 400
                            Dialog New Pixels, hdlg, "Demo", , , Dlg_Wd, Dlg_Hght, %WS_SYSMENU To hdlg 'centered
                            Row = 10
                            col = 10
                            Wd = 40
                            Hght = 12
                            Control Add Label, hdlg, -1, " Name & Address ", Col, Row, Wd, Hght
                            
                            s$ = "Hagstrom, Borje" & $CrLf & _
                                 "123 PBWin Avenue" & $CrLf & _
                                 "PowerBasic, FL 12345"
                                   
                            Col = Col + Wd + 10 'just past label 
                            Hght = 15 * 10 'Plenty room for 10 lines of text
                            Wd = Dlg_Wd - 40 - 30 'minus the label and leave a little
                            Control Add TextBox, hdlg, %Id_Sample_Textbox, s$, Col, Row, Wd, Hght, %ES_WantReturn Or %ES_MultiLine
                             hght = 25   
                             Wd = Dlg_Wd - 20
                             Col = 10 'center
                             Row = Dlg_hght - (Hght * 2) - 4 'Just off bottom
                               Control Add Button, hdlg, %Id_Show_Result_Btn, "Concatenate for a long timw", col, row, Wd, Hght
                             Row = Dlg_hght - Hght - 2 'Just off bottom
                               Control Add Button, hdlg, %Id_Exit_Btn, "Abandon Ship", col, row, Wd, Hght
                            
                               Dialog Show Modal hDlg   Call Dialog_Processor
                          End Function  '
                          ======================================
                          "The man who does not read good books
                          has no advantage
                          over the man who cannot read them."
                          Mark Twain (1835-1910)
                          ======================================
                          It's a pretty day. I hope you enjoy it.

                          Gösta

                          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                          Comment


                          • #14
                            Originally posted by Michael Mattias View Post
                            Somewhere in help is a documented number of characters limit for MACROs.
                            Yep, in the description of the MACRO keyword. 4,000 characters. That's the limit I was hitting.
                            Bernard Ertl
                            InterPlan Systems

                            Comment


                            • #15
                              Bern, if you have ver. 9/5 the BUILD$ function can make big strings very fast up to ~150K. If you don't have 9/5, the CHR$ function can substitute in place of BUILD$, but only to ~75K string length, and it is many times slower.

                              Remember too:
                              A macro definition may contain replacement text up to approximately 4000 characters. Macros may specify up to 240 parameters, which may occupy up to approximately 2000 bytes total expanded space per macro.

                              Macro Function substitutions are limited to an expanded total of approximately 16000 characters per line of original source code.
                              Code:
                              #COMPILE EXE
                              #DIM ALL
                              
                              FUNCTION PBMAIN () AS LONG
                                  LOCAL s AS STRING, ii AS LONG
                              
                                  FOR ii = 1 TO 1000000
                                     bigString(s)
                                     myFunction(s)
                                  NEXT
                              
                                  ? "Wowie, I just built and checked 2.7 gigs of strings!"
                              
                              END FUNCTION
                              
                              FUNCTION myFunction(s AS STRING) AS BYTE
                                 FUNCTION = ASC(s, 1000)
                              END FUNCTION
                              
                              FUNCTION bigString(bStr AS STRING) AS LONG
                                 bStr = BUILD$("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", _
                                               "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", _
                                               "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", _
                                               "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", _
                                               "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", _
                                               "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", _
                                               "ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", _
                                               "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", _
                                               "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiib", _
                                               "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", _
                                               "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", _
                                               "lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll", _
                                               "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", _
                                               "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn", _
                                               "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", _
                                               "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", _
                                               "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", _
                                               "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", _
                                               "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", _
                                               "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", _
                                               "ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", _
                                               "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", _
                                               "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiib", _
                                               "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", _
                                               "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", _
                                               "lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll", _
                                               "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", _
                                               "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn")
                              END FUNCTION

                              Comment


                              • #16
                                The string rolls over after about 5 or 6 hundred million characters, several times, then GPF's.
                                I'll bet testing the system ERR value would have told you something was wrong. Best guess is error 7, out of memory.
                                Michael Mattias
                                Tal Systems Inc. (retired)
                                Racine WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment

                                Working...
                                X