xsharp.eu • SqlExec() is alive!!!!
Page 1 of 1

SqlExec() is alive!!!!

Posted: Wed Apr 22, 2020 11:08 pm
by Anonymous
What a great day!! I installed ver 2.4, and the first thing I did was test SqlExec(). Ka-boom! Works like a charm! Good work X# team.

This code will look very familiar to any VFP coder:
.

Code: Select all




FUNCTION TestSqlQuery AS VOID

	VAR connString = "driver={Sql Server}; server=192.168.X.XXSQLEXPRESS; database=XXXX; uid=XXXX; pwd=XXXX;"
	VAR nHandle = SqlStringConnect(connString)
	
	VAR cSql = "Select * From Customers Order by CustomerNo"
	
	VAR nResult = SqlExec(nHandle, cSql, "csrSqlQuery1")

	FIELD CustomerNo, Company  && Add this to make compiler happy when we reference field names in Scan statement.

	SCAN 
	  ? CustomerNo + ": " + Company 
	ENDSCAN

ENDFUNC

Re: SqlExec() is alive!!!!

Posted: Sun Jul 21, 2024 10:27 am
by Irwin
1. I'm using 2.20.0.3 and SQLEXEC() always returns -1 even when the query is ok. @robert Is that a bug?
2. SQLEXEC() just works with the old SQL Server driver, I'm testing it against the following drivers:
1. SQL Server -> Works
2. SQL Server Native Client 10.0 -> Does not work
3. SQL Server Native Client 11.0 -> Does not work
4. ODBC Driver 17 for SQL Server -> Does not work

All testing was in a x86 console app.

Re: SqlExec() is alive!!!!

Posted: Sun Jul 21, 2024 5:18 pm
by robert
易文翰
Can you give an example of the query that you are using?

Robert

Re: SqlExec() is alive!!!!

Posted: Mon Jul 22, 2024 9:05 am
by Irwin
robert wrote: Sun Jul 21, 2024 5:18 pm 易文翰
Can you give an example of the query that you are using?

Robert
Hi @Robert, sure.

Code: Select all

LOCAL lnHandle := SQLSTRINGCONNECT("Driver={SQL Server};Server=the_server;Database=the_db;Uid=sa;Pwd=secret;") AS LONG
IF lnHandle > 0
	TRY
		VAR lnResult := SQLEXEC(lnHandle, "SELECT top 10 * FROM sometable", "cursor1")
		? lnResult // this is always -1 even when the query is ok.
		SCAN
			? i"{cursor1.field1}"
		ENDSCAN
	CATCH TO loEx
		?loEx.Message
	FINALLY
		SQLDISCONNECT(lnHandle)
		CLOSE
	END TRY
ENDIF

Re: SqlExec() is alive!!!!

Posted: Mon Jul 22, 2024 4:33 pm
by robert
Irwin,
This looks like a bug.
I will check this for the next build

Robert