Contents IndexWord and WSQL DDE Server Chapter 38.  The WSQL HLI Interface

User's Guide
   Part V. The SQL Anywhere Programming Interfaces
     Chapter 37. The WSQL DDE Server
      Visual Basic and WSQL DDE Server

The following Visual Basic code fragment initializes a DDE conversation, connects to a database, requests and clips some data, executes a command and finally disconnects from the database.

LinkTimeout property
Visual Basic controls have a LinkTimeout property, which specifies the amount of time the application will wait for a DDE function to execute. Some database queries can be time-consuming, so you may wish to set the LinkTimeout property to -1 (wait forever). The problem with this is that if there are link errors it may seem as though your computer has `locked up'. If this happens, try pressing the alt or esc key to abort the operation.

     ' INITIALIZING A DDE CONVERSATION
     MyTextBox.LinkTopic = "WSQLDDE|DBA,SQL,sademo"
         ' Set the service name to WSQLDDE
         ' and the topic name to DBA,SQL,sademo
     MyTextBox.LinkMode = 2
         ' Two is cold link mode
     
     ' The DDE conversation has now been initiated,
     ' but the Database Engine has not been accessed.
     
     ' CONNECTING
     MyTextBox.LinkItem = "Connect"
     MyTextBox.LinkPoke
         ' The Connect command has just been poked.
         ' WSQL DDE Server tries to connect to
         ' the sample database using
         ' the user name dba and password sql.
         ' The contents of MyTextBox are ignored
         ' and unaltered.
     
     'REQUESTING A QUERY
     MyTextBox.LinkItem = "Clear"
     MyTextBox.Text = "SELECT * FROM department"
     MyTextBox.LinkPoke
         ' The query buffer is cleared and
         ' the SELECT statement is
         ' added to it.
     
     MyTextBox.LinkItem = "Column_Names_And_Data"
     MyTextBox.LinkRequest
         ' The LinkRequest sets MyTextBox to
         ' the results of the query
         ' that we just added to it.
         ' Had the LinkItem been "Column_Names"
         ' then only the column names
         ' would have appeared in MyTextBox.
         ' Similarly, if the LinkItem
         ' had been "Data" then just the data rows
         ' would have appeared.
     
     'CLIPPING A QUERY
     MyTextBox.LinkItem = "Clear"
     MyTextBox.Text = " SELECT emp_lname, emp_id FROM employee "
     MyTextBox.LinkPoke
         ' The query buffer is cleared and
         ' the SELECT statement is added.
     
     MyTextBox.LinkItem = "Add"
     MyTextBox.Text = " WHERE emp_id < 150 "
     MyTextBox.LinkPoke
         ' The query buffer now contains:
         ' SELECT emp_lname, emp_id
         ' FROM employee WHERE emp_id < 150
     
     MyTextBox.LinkItem = "Clip_Data"
     MyTextBox.Text = " ORDER BY emp_lname "
     MyTextBox.LinkPoke
         ' The ORDER BY clause is appended to the
         ' query buffer, and the
         ' data from the query is placed on the
         ' clipboard. The LinkItem
         ' could also have been "Clip_Column_Names" or
         ' "Clip_Column_Names_And_Data"
     
     MyTextBox.Text = ClipBoard.GetText( )
         ' This pastes the contents of the clipboard
         ' to the text box.
     
     'EXECUTING A COMMAND
     MyTextBox.LinkItem = "Clear"
     MyTextBox.Text = "UPDATE employee SET dept_id=200 "
     MyTextBox.LinkPoke
     MyTextBox.LinkExecute " WHERE emp_lname='Chin' "
     ' The WHERE clause is appended to the query buffer and the command
     ' UPDATE employee SET dept_id=200 WHERE emp_lname='Chin'
     ' is sent to the database engine.
     
     'DISCONNECTING
     MyTextBox.LinkItem = "Disconnect"
     MyTextBox.LinkPoke
         ' The connection to the database
         ' engine is terminated.
         ' The DDE conversation still exists,
         ' so another Connect
         ' could be done.

Top of page


The test application

There is a Visual Basic test application (both source and executable) included with WSQL DDE Server (see directory C:\SQLANY50\ACCXMP\VB) which demonstrates the features of WSQL DDE Server. The filename is WSQLDDET.EXE. You can take a look at the source by loading the project WSQLDDET.MAK if you have the Visual Basic software.

Top of page


Running the test application

Start the database engine (on the sample database), WSQL DDE Server, and the test application. A window containing a large text box, a small text box and a button marked Connect will appear. Press the Connect button. (If you want to use a different username or password than the default, enter them into the small text box before connecting. The contents of this box will become the Link Topic.)

Pressing the Connect button terminates the current DDE conversation (if one exists), starts a new DDE conversation with the given topic, and pokes a Connect to the DDE server. After a moment, the Test Application screen will change. There will now be a combobox and seven buttons: Disconnect, Query to Clipboard, Query to Memory, Add to Buffer, Clear Buffer, ClearScreen and Execute Command.

The combo box is used to select which portions of a result set you want. There are three selections, which allow you to see just column names, just data, or both column names and data.

The Disconnect button terminates the database connection, but not the DDE conversation. (The DDE conversation can be terminated by quitting the test application.) You will then be given the option to connect again. You should disconnect from the database engine before quitting the test application.

Pressing the Query to Clipboard button first adds the contents of the small text box to the query buffer, and then gets the query results from the database engine. The result set is placed on the clipboard, and the clipboard contents are placed in the large text box. Finally, the query buffer is cleared.

Pressing the Query to Memory button first adds the contents of the small text box to the query buffer, and then sends a DDE request transaction. The result set is placed directly in the large text box. The query buffer is then cleared.

Pressing the Execute button first adds the contents of the small text box to the query buffer, and then executes the contents of the query buffer. The execute command does not put any data in the large text box.

The execute command uses the DDE execute transaction.

Pressing the Add to Query Buffer button adds the contents of the small text box to the query buffer.

Pressing the Clear Query Buffer button erases the whole query buffer.

Pressing the Clear Screen button clears the contents of the large text box.

Top of page


Contents IndexWord and WSQL DDE Server Chapter 38.  The WSQL HLI Interface