Hi, I am using the MSSQL Plugin. I am capturing user information on a custom page with text boxes. I save the user's input to variables to be used later in a SQL statement.
The problem that I am having is if the user inputs information into the text box with an apostrophe, i.e. "Jason's". It works fine if the user doesn't use an apostrophe, but I want to cover the possibility that they might.
Here is my code:
MSSQL_OLEDB::SQL_Execute /NOUNLOAD 'UPDATE DatabaseName.dbo.TableName SET ColumnName = "$SCHOOLDISTRICT" WHERE AnotherColumn = "SomeValue"'
Thanks.
Textbox and Apostrophe
7 posts
I don't understand where you have the problem? The resulting SQL statement runs correctly under query analyzer? Isn't that a problem of SQL syntax? Try using square brackets or dequoting the offending character
You need to use StrReplace on the variables to escape the string.
Stu
Stu
Hey, did anyone ever come up with a better way to handle this? I'm having a similar issue with System::Call. I'm trying to pass in an apostrophe. StrReplace is OK if you control the DLL you are calling into but not so nice if you don't.
Showing us the full System::Call line would help. And if it is a non-Windows API, the function definition as well...Originally Posted by jfehr View PostHey, did anyone ever come up with a better way to handle this? I'm having a similar issue with System::Call. I'm trying to pass in an apostrophe. StrReplace is OK if you control the DLL you are calling into but not so nice if you don't.
The NSIS Script
==========================
Function ${undot}MyTextTest
System::Call "MyDll::MyTextTest(t '$0', t '$1') i.r2"
Push $2
FunctionEnd
!macro ${undot}_MyTextTest OUT TEXT1 TEXT2
Push ${TEXT2}
Push ${TEXT1}
Call ${undot}MyTextTest
Pop ${OUT}
!macroend
!define MyTextTest '!insertmacro "${undot}_MyTextTest"'
In the C code
===========================
__declspec(dllexport) unsigned int __cdecl MyTextTest(wchar_t* text1, wchar_t* text2)
{
printf("text1 = %ws, text2 = %ws\r\n", text1, text2);
return 0UL;
}
When I call MyTextTest like this:
StrCpy @text1 “Jake’s Test” ; I’m actually getting this from an input box but declaring at a variable here
@{MyTextTest} $0 $text1 “Test Test 2”
This would print garbage to the console. Something like:
Text1 = Jake, text2 = <random memory>
==========================
Function ${undot}MyTextTest
System::Call "MyDll::MyTextTest(t '$0', t '$1') i.r2"
Push $2
FunctionEnd
!macro ${undot}_MyTextTest OUT TEXT1 TEXT2
Push ${TEXT2}
Push ${TEXT1}
Call ${undot}MyTextTest
Pop ${OUT}
!macroend
!define MyTextTest '!insertmacro "${undot}_MyTextTest"'
In the C code
===========================
__declspec(dllexport) unsigned int __cdecl MyTextTest(wchar_t* text1, wchar_t* text2)
{
printf("text1 = %ws, text2 = %ws\r\n", text1, text2);
return 0UL;
}
When I call MyTextTest like this:
StrCpy @text1 “Jake’s Test” ; I’m actually getting this from an input box but declaring at a variable here
@{MyTextTest} $0 $text1 “Test Test 2”
This would print garbage to the console. Something like:
Text1 = Jake, text2 = <random memory>
There are three problems with your code:
1) The 't' type can be char* or wchar_t*, use 'w' for wchar_t*.
2) $0 will get expanded too early and breaks the System plugin's parser.
3) The way you are using Push and Pop in your example does not really make sense but I'm ignoring that for now.
So you should do something like this:
1) The 't' type can be char* or wchar_t*, use 'w' for wchar_t*.
2) $0 will get expanded too early and breaks the System plugin's parser.
3) The way you are using Push and Pop in your example does not really make sense but I'm ignoring that for now.
So you should do something like this:
StrCpy $0 "Jake’s Test"I'm using the 'w' type and using r0 (alias for $0 in System syntax).
System::Call "user32::MessageBoxW(i$hwndparent, w r0, w 'whatever', i0)i.r2"