Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The Connection object, which manages the connection between OpenInsight and Access.  The The functions that use the Connection object have the prefix XO (XOGetProperty(), XOInstance(), XOMethod(), and XOSetProperty()).  BASICBASIC+ communicates with the Northwind database through the  NWIND connection, defined previously in the Client/Server workspace.

  • The Query object, which sends the query to Access using the Connection object and receives the results.  The The functions that use the Query object have the prefix Qry (QryGetProperty(), QryInstance(), QryMethod(), and QrySetProperty()).  Once Once the NWIND connection object has been established ("instantiated" is the fancy object-oriented term), the Query object can be used to run database queries using that connection.

...

  1. Create ("instantiate") a Connection object.  To To instantiate the object, call XOInstance(), passing the connection name.  If successful, the connection "handle", a nonzero number, is returned in hXO.  Calling Calling XOInstance() is the equivalent, in code, of the NWIND connection object we created in the Client/Server workspace.  The The code is as follows:

    Code Block
    hXO = XOInstance('NWIND')
  2. Instantiate a Query object.   After After we have a handle to the Connection object, we can use it to create a Query object.  This This is done using QryInstance().  If If successful, the query handle will be a nonzero number, returned in hQry.  The The code is as follows:

    Code Block
    hQry = QryInstance(hXO)
  3. Execute the Query.  The The query handle can be used to execute the query.  To To execute a "method" (function), use QryMethod().  The The QRY_EXECUTE$ code (equated to 4 in XO_Equates) is used to execute the query.  The The third parameter is the actual query to execute.  The The code is shown below:

    Code Block
    flag = QryMethod(hQry, QRY_EXECUTE$, "select companyname from customers order by companyname")
  4. Process the Results.  After After the query has successfully executed,  the the rows are available to BASIC+.  The The QRY_GETROW$ code (equated to 5 in XO_Equates) retrieves the next row from Access. QryMethod() is called with this code, and the results variable is built through a loop.

    Code Block
    row = ""
    results = ""
    loop
      flag = QryMethod(hQry, QRY_GETROW$, row)
      while flag
        results<-1> = row
      repeat
  5. Destroy the Query and Connection Objects, and populate the combo box.   To To prevent memory problems, the query and connection objects must be destroyed after use.  The The QRY_DESTROY$ code (equated to 1 in XO_Equates) passed to QryMethod() instructs the server to destroy the Query object.  The The XO_DESTROY$ code (also equated to 1 in XO_Equates) passed to XOMethod() instructs the server to destroy the Connection object, closing the connection.  The The Set_Property() call sets the LIST property of the combo box, populating it with the results of the query.

    Code Block
    QryMethod(hQry, QRY_DESTROY$)
    end
      
    rv = Set_Property (@window : '.COMPANIES', 'LIST', results)
    XOMethod(hXO, XO_DESTROY$)
     
    end