Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to execute an SQL Select created at runtime
Message
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01358128
Message ID:
01358129
Vues:
24
>I want to create an SQL SELECT statement at runtime as a string.
>
>How can I then execue that SELECT statement?
>
>Thanks,
>Jim

Using macro.

&lcSQL

or

RunSQL(lcSQL,'myCursor')
FUNCTION RunSQL
LPARAMETERS tcSql, tcHoldCursor, tcIntoClause

LOCAL lcErrorMsg

IF VARTYPE(m.tcSql) != "C"
	= MESSAGEBOX("Error in executing RunSQL! " + ;
		"The first parameter must be character type",0,;
		"Error from RunSQL procedure")
	RETURN .F.
ENDIF

LOCAL llRtnVal, loEx

llRtnVal = .T.

IF PCOUNT() < 2
	tcHoldCursor = 'cDelme'
ENDIF

IF EMPTY(m.tcHoldCursor)
	tcHoldCursor= 'cDelme'
ENDIF

tcSql = CHRTRAN(m.tcSql, CHR(9) + CRLF + ";","    ")

IF EMPTY(m.tcIntoClause)
	tcSql = m.tcSql + " INTO CURSOR " + m.tcHoldCursor + " READWRITE "
ELSE
	tcSql = m.tcSql + " INTO " + m.tcIntoClause
ENDIF
TRY
	&tcSql
CATCH TO loEx
	_CLIPTEXT = m.tcSql
	lcErrorMsg = "Error in executing SQL!" + CRLF + ;
		Log_Error(m.loEx) + CRLF + ;
		"The SQL is: " + m.tcSql + CRLF + ;
		GetStackInfo()
	llRtnVal = .F.
ENDTRY

RETURN m.llRtnVal
ENDFUNC
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform