home *** CD-ROM | disk | FTP | other *** search
- unit uSqlObject;
-
- interface
-
- uses
- SysUtils, ComObj, ActiveX, Graphics, ASPTypeLibrary_TLB, delphi_TLB, dmTables;
-
- type
- // SQL automation object to manipulate data from the DBDEMOS tables using ASP.
- TSQLObj = class(TAutoObject, ISQLObj)
- private
- fScript : IScriptingContext;
- fSql : WideString; // User's sql statement retrieved from the client's browser.
- fUseProducer : Integer; // Indicate wheter to use the TDataSetTableProducer component or not.
- procedure BuildTableData;
- protected
- procedure ExecuteSql; safecall;
- procedure OnStartPage(const unk: IUnknown); safecall;
- procedure OnEndPage; safecall;
- function Get_SQL: WideString; safecall;
- procedure Set_SQL(const Value: WideString); safecall;
- function Get_UseProducer: Integer; safecall;
- procedure Set_UseProducer(Value: Integer); safecall;
- public
- procedure Initialize; override;
- end;
-
- implementation
-
- uses ComServ;
-
- // The BuildTableData method will print the result of the query to the Client's
- // browser using the IScriptingContext interface passed to us from the web server.
- procedure TSQLObj.BuildTableData;
- var
- i : integer;
- begin
- // Build the html response page to be sent to the client's browser.
- with fScript.Response, dmBioLife.qryTable do
- if ( fUseProducer = 0 ) then
- begin
- while not Eof do // Iterate through the data set.
- begin
- // Write field's values to the browser.
- for i := 0 to Pred( dmBioLife.qryTable.FieldCount ) do
- Write ( Format ( '%s, ', [ dmBioLife.qryTable.Fields[ i ].AsString ] ) );
- Next;
- Write ( '<br>' );
- end;
- end
- else // Display the data using the page producer.
- write ( dmBioLife.dsProducer.Content );
-
- end;
-
- // Pre-defined method called from the ASP page to initiate the sql manipulation.
- procedure TSQLObj.ExecuteSql;
- var
- sValue : string;
- begin
- try
- // Add the client's sql sentence.
- if ( Length ( fSql ) > 0 ) then
- begin
- dmBioLife.qryTable.Sql.Clear;
- dmBioLife.qryTable.Sql.Add ( fSql );
- end;
- dmBioLife.qryTable.Active := true;
- with fScript.Response, dmBioLife.qryTable do
- begin
- // Report back to user some custom data.
- Write ( Format ( 'After opening query - Rec No. = %d<br>', [ dmBioLife.qryTable.RecordCount ] ) );
- sValue := UpperCase ( fScript.Request.Form.Item [ 'cbDsProducer' ] );
- if ( sValue = '' ) then
- sValue := 'OFF';
- Write ( Format ( 'Checkbox value in html form = %s<br>', [ sValue ] ) );
- // Build the html response page to be sent to the client's browser.
- BuildTableData;
- end;
- finally
- end;
-
- end;
-
- procedure TSQLObj.Initialize;
- begin
- inherited Initialize;
- fSql := '';
- dmBioLife.qryTable.Active := false;
-
- end;
-
- procedure TSQLObj.OnStartPage(const unk: IUnknown);
- begin
- fScript := unk as IScriptingContext; // Save the IScriptingContext interface.
- end;
-
- procedure TSQLObj.OnEndPage;
- begin
- fScript := nil; // Release the IScriptingContext interface.
- end;
-
- function TSQLObj.Get_SQL: WideString;
- begin
- Result := fSql;
- end;
-
- procedure TSQLObj.Set_SQL(const Value: WideString);
- begin
- fSql := Value;
- end;
-
- function TSQLObj.Get_UseProducer: Integer;
- begin
- Result := fUseProducer;
- end;
-
- procedure TSQLObj.Set_UseProducer(Value: Integer);
- begin
- fUseProducer := Value;
- end;
-
- initialization
- TAutoObjectFactory.Create(ComServer, TSQLObj, Class_SQLObj,
- ciMultiInstance, tmApartment);
- end.
-