SqlExec() is alive!!!!

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Anonymous

SqlExec() is alive!!!!

Post 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
User avatar
Irwin
Posts: 49
Joined: Wed Mar 23, 2022 10:24 am
Location: España

Re: SqlExec() is alive!!!!

Post 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.
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: SqlExec() is alive!!!!

Post by robert »

易文翰
Can you give an example of the query that you are using?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Irwin
Posts: 49
Joined: Wed Mar 23, 2022 10:24 am
Location: España

Re: SqlExec() is alive!!!!

Post 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
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: SqlExec() is alive!!!!

Post by robert »

Irwin,
This looks like a bug.
I will check this for the next build

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply