Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replace chr(13) + chr(10)
Message
 
 
To
31/03/2019 17:27:31
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01667754
Message ID:
01667792
Views:
35
>>Thank you for your input. I have done parameterized INSERT INTO with SQL Server many times and no problem. But this case (the topic of this thread) is about VFP table (which I have never done before). And what bothers me is I am running in a very simple problem. I don't put the INSERT INTO into a variable but execute it as a command in my code. For example:
>>
>>INSERT INTO EMAILHIS (STR_FIELD) VALUES (?cStr2Insert)
>>
>>I checked the cStr2Insert is in scope and has a simple value (without even chr(13) and chr(10).) And I get error "Syntax error". I don't understand why.
>>If I put the entire INSERT INTO expression in a variable, how would I execute it against VFP table? I know that for a SQL server you use:
>>
>>SQLEXEC(nSqlHandle,cSqlInsert)
>>
>>But what am I doing wrong with the VFP table insert?
>
>Dmitry, I believe that unfortunately you're not doing anything wrong, it's just that VFP implementation of inline parameterized SQL statements stopped half-way. I think it works only in SELECT statements.
>
>
>CREATE CURSOR TestCursor (TestColumn Varchar(50))
>
>LOCAL SQLStatement AS String
>LOCAL SQLParameter AS String
>LOCAL TrapError AS Exception
>
>m.SQLParameter = "line 1" + CHR(13) + CHR(10) + "line 2"
>
>TRY
>	INSERT INTO TestCursor (TestColumn) VALUES (?m.SQLParameter)
>CATCH TO m.TrapError
>	MESSAGEBOX("Parameter not allowed in INSERT. Reverting to simple variable reference." + ;
>		CHR(13) + "Error message: " + m.TrapError.Message, 48)
>	INSERT INTO TestCursor (TestColumn) VALUES (m.SQLParameter)
>ENDTRY
>
>TRY
>	SELECT * FROM TestCursor WHERE TestColumn  = ?m.SQLParameter
>CATCH TO m.TrapError
>	MESSAGEBOX("Parameter not allowed in SELECT. Reverting to simple variable reference." + ;
>		CHR(13) + "Error message: " + m.TrapError.Message, 48)
>	SELECT * FROM TestCursor WHERE TestColumn  = ?m.SQLParameter
>ENDTRY
>
>TRY
>	UPDATE TestCursor SET TestColumn = ?m.SQLParameter
>CATCH TO m.TrapError
>	MESSAGEBOX("Parameter not allowed in UPDATE SET clause. Reverting to simple variable reference." + ;
>		CHR(13) + "Error message: " + m.TrapError.Message, 48)
>	UPDATE TestCursor SET TestColumn = m.SQLParameter
>ENDTRY
>
>TRY
>	UPDATE TestCursor SET TestColumn = m.SQLParameter WHERE TestColumn = ?m.SQLParameter
>CATCH TO m.TrapError
>	MESSAGEBOX("Parameter not allowed in UPDATE WHERE clause. Reverting to simple variable reference." + ;
>		CHR(13) + "Error message: " + m.TrapError.Message, 48)
>	UPDATE TestCursor SET TestColumn = m.SQLParameter WHERE TestColumn = m.SQLParameter
>ENDTRY
>
>
>You can't move the statement up to an SQL server, but the not-so-bad side of this is that variable references are as sanitized as parameters...

Antonio,
I am glad that I have not completely lost my mind :) (I was going crazy). Thank you for the code that illustrates the problem.
Regarding my original issue, I decided to replace the chr(13) + chr(10) with
" <CR> "
which eliminated the error message. And since - in this particular case - the content of the string that goes into the VFP table field is not super important it will do. Also, I am trying to convert as many customers as possible to using SQL Server as the database. There are many benefits of SQL server vs VFP data. And since my customers rarely have large databases, the SQL Server Express (free) works well.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform