Difference between revisions of "SQLEXEC()"

From Lianjapedia
Jump to: navigation, search
Line 41: Line 41:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
nStatHand=SQLSTRINGCONNECT("rec@rec1:user1/pass1-/usr/recital/uas/data/southwind.tcpip",.T.)
+
nStatHand=SQLCONNECT("awhr")
 
if nStatHand < 1
 
if nStatHand < 1
    messagebox("Cannot make connection", 16, "SQL Connect Error")
+
messagebox("Cannot make connection", 16, "SQL Connect Error")
 
else
 
else
    messagebox('Connection made', 48, 'SQL Connect Message')
+
messagebox("Connection made", 48, "SQL Connect Message")
    store "00010" to myVar
+
SQLEXEC(nStatHand,"create table doc1 (ACCOUNT_NO char(5), lastname char(25), balance dec(10,2))")
    SQLEXEC(nStatHand, "SELECT * FROM example WHERE account_no = ?myVar", "restab")
+
messagebox("Table created")
    browse
+
m_accno =  "00699"
    SQLDISCONNECT(nStatHand)
+
m_lastname = "Smith"
 +
m_balance = 12345.67
 +
SQLEXEC(nStatHand,"INSERT INTO dbo.doc1 (ACCOUNT_NO,lastname,balance) VALUES ('&m_accno','&m_lastname',&m_balance)")
 +
nRET=SQLEXEC(nStatHand,"SELECT * from dbo.doc1","mycursor")
 +
if nRET < 1
 +
messagebox(sqlerror(nstatHand))
 +
else
 +
messagebox("Record selected")
 +
list
 +
endif
 +
SQLDISCONNECT(nStatHand)
 
endif
 
endif
 
</code>
 
</code>

Revision as of 09:37, 7 January 2013

Purpose

Send an SQL statement to a data source

Syntax

SQLEXEC(<nStatementHandle> [, <cSQLCommand> [, <cCursorName>]])

See Also

SQLCANCEL(), SQLCOLUMNS(), SQLCOMMIT(), SQLCONNECT(), SQLDISCONNECT(), SQLERROR(), SQLGETPROP(), SQLMORERESULTS(), SQLPREPARE(), SQLROLLBACK(), SQLSETPROP(), SQLSTRINGCONNECT(), SQLTABLES()

Description

The SQLEXEC() function is used to send an SQL statement to the specified data source.

The SQLEXEC() function operates on the data source specified by <nStatementHandle>. The SQLERROR() function can be used to return the error message if the SQL statement fails.

Keywords Description
nStatementHandle The workarea in which the gateway data source is open.
cSQLCommand The SQL statement to be passed to the data source. The cSQLCommand can be omitted if the SQL statement has already been set up using SQLPREPARE().
cCursorName The name of the temporary table to use. If cCursorName is not specified, the default name SQLRESULT is used. If the SQLEXEC() is running a pre-prepared statement, the cCursorName is taken from the SQLPREPARE() setting.

Return values:

Return Value Description
<n> Number of results sets if more than 1
0 SQLEXEC() is still executing
1 SQLEXEC() finished executing
-1 Connection error

Example

nStatHand=SQLCONNECT("awhr")
if nStatHand < 1
	messagebox("Cannot make connection", 16, "SQL Connect Error")
else
	messagebox("Connection made", 48, "SQL Connect Message")
	SQLEXEC(nStatHand,"create table doc1 (ACCOUNT_NO char(5), lastname char(25), balance dec(10,2))")
	messagebox("Table created")
	m_accno =  "00699"
	m_lastname = "Smith"
	m_balance = 12345.67
	SQLEXEC(nStatHand,"INSERT INTO dbo.doc1 (ACCOUNT_NO,lastname,balance) VALUES ('&m_accno','&m_lastname',&m_balance)")
	nRET=SQLEXEC(nStatHand,"SELECT * from dbo.doc1","mycursor")
	if nRET < 1
		messagebox(sqlerror(nstatHand))
	else
		messagebox("Record selected")
		list
	endif
	SQLDISCONNECT(nStatHand)
endif