Page 1 of 1

How to Verify that a given SQL statemen is a valid

Posted: Thu Dec 30, 2021 1:29 pm
by unixkd
Hi all and merry Christmas,

I need a function to verify that a given SQL statement is a valid SQL statement. The statement is sent to the server where it is parsed but not executed and an exception is raised if the statement is not valid. ADS has it but I want to use it in SQLExpress

Thanks

Joe

Re: How to Verify that a given SQL statemen is a valid

Posted: Thu Dec 30, 2021 2:30 pm
by rdonnay
I think you will have to ask Boris Borzic about this, since he is the author of SqlExpress.

If you were using the ODBCDBE, this would be possible, just as in ADS, but I haven't used SqlExpress in many years.

Re: How to Verify that a given SQL statemen is a valid

Posted: Tue Jan 04, 2022 12:47 am
by k-insis
There is sqlfiddle (a online site) that does that (not sure how deep it supports ansi sql)

1) You are looking into wrong direction. For such testing purposes there are integrated environments that do that job (sql enterprise manager is good example, also mysql workbench and pgadmin for postgresql).

2) In SqlExpress there is always return status when doing either select or or execute:
oConn := SQLConnection():new('MyNewDSN', 'MyUserId', 'MyPassword')
if oConn:isConnected
oStmt := oConn:NewStatement()
oStmt:SQLString := 'CREATE TABLE MyTable (Field1 char(5), Field2 char(20))'
if oStmt:Execute() != SQL_XPP_ERROR
oStmt:SQLString := 'INSERT INTO MyTable (Field1, Field2) VALUES (?,?)'
for i := 1 to 10
oStmt:Execute(LTrim(Str(i)), Replicate(Chr(64+i),20))
next
MsgBox("New table created and 10 rows added!")
endif
endif



3) To replicate that (not sure why would you do that) one way is to use manual transaction support inside ODBC and database where you execute something than immediately do rollback with transaction rollback
:begintransaction()
:execute something check for errors etc
:RollbackTransaction()
:endtransaction()


And it is supported and implemented in SqlExpress