How to Verify that a given SQL statemen is a valid

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

How to Verify that a given SQL statemen is a valid

#1 Post 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

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

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

#2 Post 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.
The eXpress train is coming - and it has more cars.

k-insis
Posts: 94
Joined: Fri Jan 28, 2011 4:07 am

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

#3 Post 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

Post Reply