TAstaServerSocket.ThreadedDBSupplyQuery


 

Applies to
TAstaServerSocket

 

Declaration
type TAstaServerSupplyQueryEvent = procedure(Sender: TObject;
  ClientSocket: TCustomWinSocket; DBAction: TThreadDbAction;
  DataBaseStr: String; CreateNew: Boolean; var AQuery: Component;
  SQLOptions: TAstaSelectSQLOptionSet)
of object;

property ThreadDBSupplyQuery: TAstaServerSupplyQueryEvent;

 

Description
When an ASTAclient is connected to an ASTA server and it needs to do a Select or an Exec, or to execute a stored procedure, this routine will be called to create a new component to be used in the client process. Under the BDE, a TQuery is used for Selects and Execs and a TStoredProc is used for stored procedures. Under the ODBCExpress implementation, a TOEDataSet is created for both. The
DBAction indicates the type of process that the component will be used for.

 

The ThreadedDBSupplyQueryEvent sets the AQuery parameter. This allows you to create a single component like a TQuery for a specific action, or to use a component that was created in a data module. In the AstaBDEServer, TQueries or TStoredProcs are created as needed. Since individual components are created on the fly, they must be disposed of by the ASTA server when they have done their tasks. In this case, make sure the DisposeofQueriesForThreads property is set to True. This will tell the ASTA server to dispose of these components. In the AstaODBCExpress server example, a complete data module is created for each thread. In this case, the DisposeOfQueriesForThreads would be set to false, as any components that are part of a data module will be disposed of when the DataModule is destroyed.

 

NOTE: When ASTA servers utilize the tmPersistentSession Model, and packet fetch requests are received from AstaClientDataSets, components must be created on the fly and not used from data modules. In this case, the incoming TThreadDBAction will be set to ttPacketSelect. See the AstaODBCExpress server for an example of this. Since the component must be kept open to be able to return further packet requests, it must be created on the fly.

 

When running threaded the Sender parameter will come in as a TAstaThread otherwise in SingleThreaded mode it will be the AstaServerSocket itself.

 

Example

procedure TForm1.AstaServerSocket1ThreadedDBSupplyQuery(Sender: TObject;

  ClientSocket: TCustomWinSocket; DBAction: TThreadDbAction;

  DataBaseStr: String; CreateNew: Boolean; var AQuery: TComponent;

  SQLOptions: TAstaSelectSQLOptionSet);

begin

  try

    if CreateNew then begin

      case DBAction of

        ttStoredProc:

          begin

            AQuery := TStoredProc.Create(nil);

            with AQuery as TStoredProc do begin

              SessionName := TDataBase(TAstaThread(Sender).
                Session).SessionName;

              DataBaseName := TDataBase(TAstaThread(Sender).
                Session).DataBaseName;

            end;

          end;

        ttTransactionStart:

          AQuery := TDataBase(TAstaThread(Sender).Session);

      else

        AQuery := TQuery.Create(nil);

        with AQuery as TQuery do begin

          SessionName := TDataBase(TAstaThread(Sender).Session).
            Session.SessionName;

          DataBaseName := TDataBase(TAstaThread(Sender).Session).
            DataBaseName;

        end

      end;

    end else //create new

      case DBAction of

        ttStoredProc: AQuery := StoredProc1;

        ttTransactionStart: AQuery := MainDataBase;

      else

        AQuery := Query;

      end;

  except

    LogException(ClientSocket, Exception(exceptObject).Message, True);

  end;

end;

 

 



ASTA Overview TAstaServerSocket.SessionList TAstaServerSocket.ThreadedDBSupplyServerDataSet