Working with the QMF for Windows API

The following steps provide an overview of how you work with the API to control QMF for Windows:

  1. Create an instance of the QMF for Windows API object.

    If you are using Microsoft Visual Basic, add a reference to the QMF for Windows type library, qmfwin.tlb. Then use the Dim statement: Dim QMFWin As New QMFWin

    or the CreateObject statement:

    Dim QMFWin As Object
    Set QMFWin = CreateObject("QMFWin.Interface")
    

    If you are using Microsoft Visual C++ and Microsoft Foundation Class (MFC), create a wrapper class for the QMF for Windows API object from the QMF for Windows type library, qmfwin.tlb. Then use the following CreateDispatch() function:

    COleException e;
    IQMFWin QMFWin;
    QMFWin.CreateDispatch("QMFWin.Interface", &e);
    
    Note:
    If you are using a different development environment, refer to your product documentation on how to complete this step.
  2. Select the server you want to use and call InitializeServer() to initialize a connection to the database.

    Note:
    A user ID and password are required in order to connect to a server. You can have QMF for Windows prompt for the user ID and password, or you can prompt for them in your application and pass them as parameters in the InitializeServer() function call.
  3. Select the query you want to run using InitializeQuery(). If the query contains variables, use the SetVariable() function to set the variable values.
  4. Open or execute the query. Use the Open() function to open the query's cursor for SELECT statements, and use the Execute() function to execute the SQL for non-SELECT statements.
  5. If the query is a SELECT statement, fetch rows of data by repeatedly calling FetchNextRow(). To fetch more than one row at a time, use FetchNextRows(), or use CompleteQuery() to direct QMF for Windows to fetch all of the rows.
  6. If the query is a SELECT statement, close the query using the Close() function.
  7. Terminate the unit of work using the Commit() or Rollback() functions.