Server_Execute() function - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Purpose

Sends a SQL string to execute on a remote data server. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

Server_Execute( ConnectionNumber, server_string )

ConnectionNumber is an integer value that identifies the specific connection.

server_string is any valid SQL statement supported by the connected server. Refer to the SQL language guide of your server database for information on valid SQL statements.

Return Value

Integer

Description

The Server_Execute() function sends the server_string (an SQL statement) to the server connection specified by the ConnectionNumber. Any valid SQL statement supported by the active server is a valid value for the server_string parameter. Refer to the SQL language guide of your server database for information on valid SQL statements.

This function returns a statement number. The statement number is used to associate subsequent SQL requests, like the Server Fetch statement and the Server Close statement, to a particular SQL statement.

You should perform a Server Close statement for each Server_Execute() function as soon as you are done using the statement handle. For selects, this is as soon as you are done fetching the desired data. This will close the cursor on the remote server and free up the result set. Otherwise, you can exceed the cursor limit and further executes will fail. Not all database servers support forward and reverse scrolling cursors. For other SQL commands, issue a Server Close statement immediately following the Server_Execute() function.

Dim hdbc, hstmt As Integer
hdbc = Server_Connect("ODBC", "DLG=1")
hstmt = Server_Execute(hdbc, "Select * from ADDR")
Server hstmt Close

Example

Dim hdbc, hstmt As Integer
hdbc = Server_Connect("ODBC", DSN=ORACLE7;DLG=1")
hstmt = Server_Execute (hdbc, 
	"CREATE TABLE NAME_TABLE (NAME CHAR (20))")
Server hstmt Close
hstmt = Server_Execute (hdbc, 
	"INSERT INTO NAME_TABLE VALUES ('Steve')")
Server hstmt Close 
hstmt = Server_Execute ( hdbc, 
	"UPDATE NAME_TABLE SET name = 'Tim' ")
Server hstmt Close 
Server hdbc Disconnect

See Also:

Server Close statement, Server Fetch statement