Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] General Discussion

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-14-2005, 01:45 PM
mseminatore mseminatore is online now
Registered User
 
Join Date: 09-14-2005
Posts: 17
Macros containing single quotes

I am trying to create a failure step which logs the text of a failed step to a database via SQL. The text of the failed step is as follows:

Error message from the server: 'an item with that name already exists'

The SQL step is essentially:

INSERT INTO errors ("ErrorText") VALUES('%FAILSTEP_OUTPUT%');

The issue is that the single quotes within the text cause an error in expansion of the text so that the last single quote is not passed to SQL Server.

What gets passed to ISQL is:

'Error message from the server: 'an item with that name already exists'
Reply With Quote
  #2  
Old 09-14-2005, 01:57 PM
mseminatore mseminatore is online now
Registered User
 
Join Date: 09-14-2005
Posts: 17
I even tried a script step to filter out the quotes:

Set failText = Application.Macros(vbldProject).Item("FAILURE_TEXT ")

Dim failOutput
failOutput = "%FAILSTEP_OUTPUT%"
Escape(failOutput)

If failText Is Nothing Then
' if the macro doesn't exist yet, initialize to one
Application.Macros(vbldProject).Add "FAILURE_TEXT", Application.ExpandMacros(failOutput)
Else
failText.Value = Application.ExpandMacros(failOutput)
End If

Then I get this error:

Error at Line 4, Column 85 (Unterminated string constant)
Code: failOutput = "Error message from the server: 'an item with that name already exists'
Reply With Quote
  #3  
Old 09-14-2005, 04:32 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
It sounds like the FAILSTEP_OUTPUT contains newlines (that would cause the 'unterminated string constant' error in the 2nd post). You need to process the string in a variable without expanding it in the script code that gets executed (which happens when using %FAILSTEP_OUTPUT%):

INSERT INTO errors ("ErrorText") VALUES('[Escape(vbld_AllMacros().Item("FAILSTEP_OUTPUT").Va lue)]');
Reply With Quote
  #4  
Old 09-14-2005, 06:01 PM
mseminatore mseminatore is online now
Registered User
 
Join Date: 09-14-2005
Posts: 17
Ok, I tried that. My exact SQL step looks like this

SELECT build_seterrortext('%BUILD_KEY%', %CURRENT_STEP%, '[Escape(vbld_AllMacros().Item("FAILSTEP_OUTPUT").Va lue)]');

and now I get the following error message:

Building failure step 'Log error to DB'...
Error expanding macros in property InputStr: <Error parsing macros: Unrecoverable Parse Error at position 221 - expecting percent_sign>
Reply With Quote
  #5  
Old 09-14-2005, 06:05 PM
mseminatore mseminatore is online now
Registered User
 
Join Date: 09-14-2005
Posts: 17
I should add that there are definitlely newlines in the FAILSTEP_OUTPUT. The text is:

"Error message from the server: 'an item with that name already exists'

Process completed with exit code 1"

I had thought the issue was with the single quotes but perhaps not.
Reply With Quote
  #6  
Old 09-14-2005, 06:45 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Regarding the "Error parsing macros: Unrecoverable Parse Error at position 221 - expecting percent_sign" error, if the macro value could contain VBP special chars (% [ ]), those need to be escaped via the vbld_EscapeString system script function:

SELECT build_seterrortext('%BUILD_KEY%', %CURRENT_STEP%, '[vbld_EscapeString(Escape(vbld_AllMacros().Item("FA ILSTEP_OUTPUT").Value))]');

Regarding the 'an item with that name already exists' error, that sounds like a error message from the database.
Reply With Quote
  #7  
Old 09-15-2005, 11:33 AM
mseminatore mseminatore is online now
Registered User
 
Join Date: 09-14-2005
Posts: 17
It is an error from a build step before the database. What I am trying to do is, in an error step, log that error text into a database.

So the database doesn't really play into this issue except that it is being given a badly formed text string from VBScript, or VBScript fails itself in trying to format the text.

I tried the vbld_escapestring around Escape and it works but the text is all full of html escapes. Is there an easy way to just remove the newlines?

thanks
Reply With Quote
  #8  
Old 09-15-2005, 11:41 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Ah, so Escape is a built-in VBScript function that escapes a string into valid URL format. I thought it was a function you wrote to convert newlines to something else. To do just that instead, something like this would work (and you don't actually need to use vbld_EscapeString on FAILSTEP_OUTPUT, since special characters will already be escaped -- the Escape method is what was adding non-VBP-escaped chars):

SELECT build_seterrortext('%BUILD_KEY%', %CURRENT_STEP%, '[Replace(vbld_AllMacros().Item("FAILSTEP_OUTPUT").V alue, vbCrLf, "")]');
Reply With Quote
  #9  
Old 09-15-2005, 01:40 PM
mseminatore mseminatore is online now
Registered User
 
Join Date: 09-14-2005
Posts: 17
Excellent! That did it. For reference here is what I wound up with:

SELECT build_seterrortext('%BUILD_KEY%', %CURRENT_STEP%, '[Replace(Replace(vbld_AllMacros().Item("FAILSTEP_OU TPUT").Value, vbCrLf, ""), "'","")]');

I had to replace (remove) both single quotes and newlines.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 04:10 PM.


Copyright © 1999-2023 Kinook Software, Inc.