Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replace chr(13) + chr(10)
Message
From
31/03/2019 17:27:31
Antonio Lopes (Online)
BookMARC
Coimbra, Portugal
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01667754
Message ID:
01667791
Views:
43
>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...
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform