Update of /cvsroot/instantobjects/Source/Brokers/NexusDbSQL In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9673/Source/Brokers/NexusDbSQL Added Files: InstantNexusDbSQL.dcr InstantNexusDbSQL.pas InstantNexusDbSQLConnectionDefEdit.dfm InstantNexusDbSQLConnectionDefEdit.pas InstantNexusDbSQLReg.pas Log Message: Added Steve Mitchell changes for MM compatibility --- NEW FILE: InstantNexusDbSQL.pas --- (* * InstantObjects(tm) NexusDb SQL Broker Support - Broker * NexusDbSQL Support * * Copyright (c) Seleqt * Copyright (c) Carlo Wolter - cw...@te... * Copyright (c) Steven Mitchell - sr...@tp... * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is a combination of InstantObject NexusDb Broker and Seleqt InstantObjects InterBase Express Broker. Portions created by Steven Mitchell are Copyright (C) Steven Mitchell. Portions created by Carlo Wolter are Copyright (C) Carlo Wolter. Portions created by Seleqt are Copyright (C) Seleqt. All Rights Reserved. * Contributor(s): * Carlo Barazzetta and Nando Dessena ===================================================================== Limited warranty and disclaimer of warranty ===================================================================== This software and accompanying written materials are provided "as is" without warranty of any kind. Further, the author does not warrant, guarantee, or take any representations regarding the use, or the results of use, of the software or written materials in terms of correctness, accuracy, reliability, currentness or otherwise. The entire risk as to the results and performance of the software is assumed by you. Neither the author nor anyone else who has been involved in the creation, production or delivery of this product shall be liable for any direct, indirect, consequential or incidental damages (including damages for loss of business profits, business interruption, loss of business information and the like) arising out of the use or inability to use the product even if the author has been advised of the possibility of such damages. By using the InstantObject NexusDb SQL Broker component you acknowledge that you have read this limited warranty, understand it, and agree to be bound by its' terms and conditions. ===================================================================== *) unit InstantNexusDbSQL; {$I ..\..\Core\InstantDefines.inc} {$IFDEF D7+} {$WARN UNSAFE_TYPE OFF} {$WARN UNSAFE_CAST OFF} {$WARN UNSAFE_CODE OFF} {$ENDIF} interface uses Classes, Db, SysUtils, InstantPersistence, InstantClasses, InstantCommand, nxdb, nxsdServerEngine, nxreRemoteServerEngine, nxllComponent, nxllTransport, nxptBasePooledTransport, nxtwWinsockTransport, nxsdDataDictionary //, CSIntf ; type TNexusDbTable = class(TnxTable) end; TNexusDbQuery = class(TnxQuery) protected procedure SetRecNo(Value: Integer); override; end; TInstantNexusDbSQLConnectionDef = class(TInstantRelationalConnectionDef) private FAliasName: string; FAliasIsPath: boolean; FServerName: string; protected procedure InitConnector(Connector: TInstantConnector); override; public procedure LoadAliasList(FALiasList : TStrings); procedure LoadServerList(FServerList : TStrings); function Edit: Boolean; override; class function ConnectionTypeName: string; override; class function ConnectorClass: TInstantConnectorClass; override; published property AliasName: string read FAliasName write FAliasName; property AliasIsPath: boolean read FAliasIsPath write FAliasIsPath; property ServerName: string read FServerName write FServerName; end; TInstantNexusDbSQLConnector = class(TInstantRelationalConnector) private FDatabase: TnxDatabase; procedure DatabaseBuildFixup; procedure FillFieldMap(aTbl: TNexusDbTable; aList: TStrings); function CreateFixedPrimaryIndexDef(aTbl: TNexusDbTable; aDict: TnxDataDictionary; var aOldIdx: Integer): TnxIndexDescriptor; procedure DoTableFix(aTbl: TNexusDbTable); protected function CreateBroker: TInstantBroker; override; function GetConnected: Boolean; override; function GetDatabaseName: string; override; function GetDBMSName: string; override; procedure InternalBuildDatabase(Scheme: TInstantScheme); override; procedure InternalCommitTransaction; override; procedure InternalConnect; override; procedure InternalDisconnect; override; procedure InternalRollbackTransaction; override; procedure InternalStartTransaction; override; public class function ConnectionDefClass: TInstantConnectionDefClass; override; published property Database: TnxDatabase read FDatabase write FDatabase; end; TInstantNexusDbSQLBroker= class(TInstantSQLBroker) private function GetConnector: TInstantNexusDbSQLConnector; protected function CreateResolver(Map: TInstantAttributeMap): TInstantSQLResolver; override; function GetDBMSName: string; override; function GetSQLQuote: Char; override; function InternalCreateQuery: TInstantQuery; override; procedure PrepareQuery(DataSet : TDataSet); override; procedure UnprepareQuery(DataSet : TDataSet); override; function ExecuteQuery(DataSet : TDataSet) : integer; override; procedure AssignDataSetParams(DataSet : TDataSet; AParams: TParams); override; public function CreateDataSet(const AStatement: string; AParams: TParams = nil): TDataSet; override; function DataTypeToColumnType(DataType: TInstantDataType; Size: Integer): string; override; function Execute(const AStatement: string; AParams: TParams = nil): Integer; override; property Connector: TInstantNexusDbSQLConnector read GetConnector; end; TInstantNexusDbSQLResolver = class(TInstantSQLResolver); TInstantNexusDbSQLTranslator = class(TInstantRelationalTranslator); TInstantNexusDbSQLQuery = class(TInstantSQLQuery) protected class function TranslatorClass: TInstantRelationalTranslatorClass; override; end; implementation uses Controls, InstantConsts, InstantNexusDbSQLConnectionDefEdit, InstantUtils, nxdbBase, nxsdTypes; procedure TInstantNexusDbSQLConnectionDef.LoadAliasList(FALiasList : TStrings); var Transport: TnxWinsockTransport; Engine: TnxRemoteServerEngine; Session: TnxSession; begin if ServerName = '' then ServerName := 'NexusDb@localhost'; Session := nil; Engine := nil; Transport := nil; try Transport := TnxWinsockTransport.Create(nil); // Setup transport Transport.ServerNameRuntime := ServerName; FAliasList.Clear; try Transport.Active := True; Engine := TnxRemoteServerEngine.Create(nil); // Setup engine Engine.Transport := Transport; Engine.Active := True; Session := TnxSession.Create(nil); // Setup session Session.ServerEngine := Engine; Session.Active := True; Session.GetAliasNames(FAliasList); /// CodeSite.SendStringList('Alias list',AliasList); except //ignore connections problems on EnxTransportException do ; end; finally Session.Free; Engine.Free; Transport.Free; end; end; procedure TInstantNexusDbSQLConnectionDef.LoadServerList(FServerList : TStrings); var Transport: TnxWinsockTransport; begin Transport := nil; try Transport := TnxWinsockTransport.Create(nil); // Setup transport Transport.GetServerNames(FServerList, 5000); finally Transport.Free; end; end; class function TInstantNexusDbSQLConnectionDef.ConnectionTypeName: string; begin Result := 'NexusDbSQL'; end; class function TInstantNexusDbSQLConnectionDef.ConnectorClass: TInstantConnectorClass; begin Result := TInstantNexusDbSQLConnector; end; function TInstantNexusDbSQLConnectionDef.Edit: Boolean; begin with TInstantNexusDbSQLConnectionDefEditForm.Create(nil) do begin try LoadData(Self); Result := ShowModal = mrOk; if Result then begin SaveData(Self); end; finally Free; end; end; end; procedure TInstantNexusDbSQLConnectionDef.InitConnector(Connector: TInstantConnector); { TODO: Create and return connection instance } var Transport: TnxWinsockTransport; Engine: TnxRemoteServerEngine; Session: TnxSession; Database: TnxDatabase; begin //CodeSite.EnterMethod('TInstantNexusDbSQLConnectionDef.InitConnector'); inherited; Transport := TnxWinsockTransport.Create(Connector); // Setup transport Transport.ServerName := ServerName; Transport.Active := True; Engine := TnxRemoteServerEngine.Create(Connector); // Setup engine Engine.Transport := Transport; Engine.Active := True; Session := TnxSession.Create(Connector); // Setup session. Session.DisplayName := 'nxInitSession'; Session.ServerEngine := Engine; Session.Active := True; Database := TnxDatabase.Create(Connector); // Setup database Database.DisplayName := 'nxInitDatabase'; Database.Session := Session; try Database.Timeout := -1; Database.Active := False; if AliasIsPath then begin Database.AliasName := ''; Database.AliasPath := AliasName; // Path end else begin Database.AliasName := AliasName; // Alias Database.AliasPath := ''; end; Database.Active := True; (Connector as TInstantNexusDbSQLConnector).Database := Database; except Database.Free; raise; end; //CodeSite.ExitMethod('TInstantNexusDbSQLConnectionDef.InitConnector'); end; { TInstantNexusDbSQLConnector } class function TInstantNexusDbSQLConnector.ConnectionDefClass: TInstantConnectionDefClass; begin Result := TInstantNexusDbSQLConnectionDef; end; function TInstantNexusDbSQLConnector.CreateBroker: TInstantBroker; begin Result := TInstantNexusDbSQLBroker.Create(Self); end; function TInstantNexusDbSQLConnector.GetConnected: Boolean; begin Result := Assigned(Database) and Database.Connected; end; function TInstantNexusDbSQLConnector.GetDatabaseName: string; begin Result := Database.AliasName; end; function TInstantNexusDbSQLConnector.GetDBMSName: string; begin Result := 'NexusDb'; end; procedure TInstantNexusDbSQLConnector.FillFieldMap(aTbl: TNexusDbTable; aList: TStrings); var j: Integer; begin aList.Clear; for j := 0 to aTbl.FieldDefs.Count - 1 do begin aList.Add(aTbl.FieldDefs[j].Name); end; { for } end; { The CreateFixedPrimaryIndexDef function finds the primary index created in SQL and returns its index number in the aOldIdx param. The function returns a suitably named TnxIndexDescriptor that is used to replace the SQL generated primary index. } function TInstantNexusDbSQLConnector.CreateFixedPrimaryIndexDef( aTbl: TNexusDbTable; aDict: TnxDataDictionary; var aOldIdx: Integer): TnxIndexDescriptor; var k: Integer; j: Integer; lKeyFieldDef: TnxCompKeyDescriptor; begin result := nil; aOldIdx := 0; try for j := 0 to aDict.IndexCount - 1 do begin //CodeSite.SendFmtMsg('aDict.IndexDescriptor[%d].Name: %s', // [j, aTbl.IndexDefs[j].Name]); if aDict.IndexDescriptor[j].Name = 'key0' then begin result := TnxIndexDescriptor.CreateStandAlone(0, aTbl.TableName + '_ID', 0, TnxCompKeyDescriptor); lKeyFieldDef := aDict.IndexDescriptor[j].KeyDescriptor as TnxCompKeyDescriptor; for k := 0 to lKeyFieldDef.KeyFieldCount - 1 do begin TnxCompKeyDescriptor(result.KeyDescriptor).Add( lKeyFieldDef.KeyFields[k].FieldNumber); end; { for } aOldIdx := j; Break; end; { if } end; { for } except result := nil; end; { try/except } end; procedure TInstantNexusDbSQLConnector.DoTableFix(aTbl: TNexusDbTable); var lOldIdx: Integer; lFieldMap: TStrings; lCompleted: boolean; lStatus: TnxTaskStatus; lDict: TnxDataDictionary; lTaskInfo: TnxAbstractTaskInfo; lIdxDef: TnxIndexDescriptor; begin lDict := nil; lFieldMap := TStringList.Create; try FillFieldMap(aTbl, lFieldMap); aTbl.UpdateIndexDefs; if aTbl.IndexDefs.Count = 0 then Exit; aTbl.dsUpdateDataDictionary; lDict := TnxDataDictionary.Create; lDict.Assign(aTbl.Dictionary); lIdxDef := CreateFixedPrimaryIndexDef(aTbl, lDict, lOldIdx); if Assigned(lIdxDef) then begin lDict.RemoveIndex(lOldIdx); lIdxDef := lDict.AddIndex(lIdxDef); lDict.DefaultIndex := lIdxDef.Number; Check(Database.RestructureTable(aTbl.TableName, lDict, lFieldMap, lTaskInfo)); if Assigned(lTaskInfo) then begin repeat Sleep(250); lTaskInfo.GetStatus(lCompleted, lStatus); until lCompleted; end; { if } aTbl.FieldDefs.Clear; aTbl.IndexDefs.Clear; end; { if } finally lDict.Free; lFieldMap.Free; end; { try/finally } end; procedure TInstantNexusDbSQLConnector.DatabaseBuildFixup; var I: Integer; lTblList: TStrings; lTbl: TNexusDbTable; begin //CodeSite.EnterMethod('TInstantNexusDbSQLConnector.DatabaseBuildFixup'); lTblList := nil; lTbl := nil; try lTblList := TStringList.Create; Database.Session.CloseInactiveTables; Database.GetTableNames(lTblList); lTbl := TNexusDbTable.Create(nil); lTbl.Database := Database; for I := 0 to lTblList.Count - 1 do begin //CodeSite.SendFmtMsg('lTbl[%d].TableName: %s', [I, lTbl.TableName]); lTbl.TableName := lTblList[I]; DoTableFix(lTbl); end; { for } finally lTbl.Free; lTblList.Free; end; { try/finally } //CodeSite.ExitMethod('TInstantNexusDbSQLConnector.DatabaseBuildFixup'); end; procedure TInstantNexusDbSQLConnector.InternalBuildDatabase(Scheme: TInstantScheme); begin StartTransaction; try inherited; CommitTransaction; DatabaseBuildFixup; // Hopefully NexusDb V2 will not need this! except RollbackTransaction; raise; end; end; procedure TInstantNexusDbSQLConnector.InternalCommitTransaction; begin Database.Commit; end; procedure TInstantNexusDbSQLConnector.InternalConnect; begin //CodeSite.EnterMethod('TInstantNexusDbSQLConnector.InternalConnect'); //CodeSite.SendFmtMsg('Database.DisplayName: %s', [Database.DisplayName]); Database.Open; //CodeSite.ExitMethod('TInstantNexusDbSQLConnector.InternalConnect'); end; procedure TInstantNexusDbSQLConnector.InternalDisconnect; begin //CodeSite.EnterMethod('TInstantNexusDbSQLConnector.InternalDisconnect'); //CodeSite.SendFmtMsg('Database.DisplayName: %s', [Database.DisplayName]); Database.Close; //CodeSite.ExitMethod('TInstantNexusDbSQLConnector.InternalDisconnect'); end; procedure TInstantNexusDbSQLConnector.InternalRollbackTransaction; begin Database.Rollback; end; procedure TInstantNexusDbSQLConnector.InternalStartTransaction; begin Database.StartTransaction; end; { TInstantNexusDbSQLBroker} procedure TInstantNexusDbSQLBroker.AssignDataSetParams(DataSet : TDataSet; AParams: TParams); var I: Integer; TargetParams : TParams; SourceParam, TargetParam: TParam; begin //don't call inherited! TargetParams := TNexusDbQuery(DataSet).Params; for I := 0 to Pred(AParams.Count) do begin SourceParam := AParams[I]; TargetParam := TargetParams.FindParam(SourceParam.Name); if Assigned(TargetParam) then TargetParam.Assign(SourceParam); end; end; function TInstantNexusDbSQLBroker.CreateDataSet(const AStatement: string; AParams: TParams): TDataSet; var Query: TNexusDbQuery; begin Query := TNexusDbQuery.Create(nil); with Query do begin Database := Connector.Database; SQL.Text := AStatement; if Assigned(AParams) then AssignDataSetParams(Query, AParams); end; Result := Query; end; function TInstantNexusDbSQLBroker.CreateResolver( Map: TInstantAttributeMap): TInstantSQLResolver; begin Result := TInstantNexusDbSQLResolver.Create(Self, Map); end; function TInstantNexusDbSQLBroker.DataTypeToColumnType( DataType: TInstantDataType; Size: Integer): string; const Types: array[TInstantDataType] of string = ( 'INTEGER', 'REAL', 'MONEY', 'BOOLEAN', 'VARCHAR', 'TEXT', 'DATETIME', 'BLOB'); begin Result := Types[DataType]; if (DataType = dtString) and (Size > 0) then Result := Result + InstantEmbrace(IntToStr(Size), '()'); end; function TInstantNexusDbSQLBroker.Execute(const AStatement: string; AParams: TParams): Integer; begin with CreateDataSet(AStatement, AParams) as TNexusDbQuery do try ExecSQL; Result := RowsAffected; finally Free; end; end; function TInstantNexusDbSQLBroker.ExecuteQuery(DataSet: TDataSet) : integer; begin //don't call inherited! with TNexusDbQuery(DataSet) do begin ExecSQL; Result := RowsAffected; end; end; function TInstantNexusDbSQLBroker.GetConnector: TInstantNexusDbSQLConnector; begin Result := inherited Connector as TInstantNexusDbSQLConnector; end; function TInstantNexusDbSQLBroker.GetDBMSName: string; begin Result := 'NexusDbSQL'; end; function TInstantNexusDbSQLBroker.GetSQLQuote: Char; begin Result := ''''; end; function TInstantNexusDbSQLBroker.InternalCreateQuery: TInstantQuery; begin Result := TInstantNexusDbSQLQuery.Create(Connector); end; procedure TInstantNexusDbSQLBroker.PrepareQuery(DataSet: TDataSet); begin inherited; TNexusDbQuery(DataSet).Prepare; end; procedure TInstantNexusDbSQLBroker.UnprepareQuery(DataSet: TDataSet); begin inherited; TNexusDbQuery(DataSet).Unprepare; end; { TInstantNexusDbSQLQuery } class function TInstantNexusDbSQLQuery.TranslatorClass: TInstantRelationalTranslatorClass; begin Result := TInstantNexusDbSQLTranslator; end; { TNexusDbQuery } procedure TNexusDbQuery.SetRecNo(Value: Integer); begin inherited; if Value = Succ(RecNo) then Next else if Value = Pred(RecNo) then Prior; end; initialization RegisterClass(TInstantNexusDbSQLConnectionDef); TInstantNexusDbSQLConnector.RegisterClass; finalization TInstantNexusDbSQLConnector.UnregisterClass; end. --- NEW FILE: InstantNexusDbSQLConnectionDefEdit.dfm --- object InstantNexusDbSQLConnectionDefEditForm: TInstantNexusDbSQLConnectionDefEditForm Left = 299 Top = 202 BorderStyle = bsDialog Caption = ' NexusDbSQL Connection' ClientHeight = 309 ClientWidth = 393 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] Icon.Data = { 0000010001002020100000000000E80200001600000028000000200000004000 0000010004000000000080020000000000000000000000000000000000000000 000000008000008000000080800080000000800080008080000080808000C0C0 C0000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000 0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000 3333333000333333333333330000000030000000700000000000000300000000 3333333000333333333333330000000033333333033333333333333300000000 3333333303333333333333330000000033333300007744473333333300000000 33330088FF8444447333333300000000333077888F4444444333333300000000 33307888FF4444444333333300000000333077888F44F4444333333300000000 33307888FF8444447333333300000000333077888F8844473333333300000000 33307888FFF887333333333300000000333077888F8870333333333300000000 33307800000870333333333300000000333000FFF77777777777777700000000 3330FFFFF7FFFFFFFFFFFFF700000000333300FFF7FF0FF0F0FF0FF700000000 3333330007FF0F00F0FF0FF7000000003333333337FF0870FF00FFF700000000 3333333337FF00F0F0FF0FF7000000003333333337FF0FF0F0FF0FF700000000 3333333337FFFFFFFFFFFFF70000000033333333377777777777777700000000 0000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000FFFF FFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000FF000000FF000000FF000000FF000 000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000 000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000 000FF000000FF000000FF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF} OldCreateOrder = True Position = poScreenCenter OnCreate = FormCreate OnShow = FormShow PixelsPerInch = 96 TextHeight = 13 object BottomBevel: TBevel Left = 0 Top = 272 Width = 393 Height = 2 Align = alBottom Shape = bsBottomLine end object ClientPanel: TPanel Left = 0 Top = 0 Width = 393 Height = 272 Align = alClient BevelOuter = bvNone TabOrder = 0 object PathLabel: TLabel Left = 16 Top = 184 Width = 22 Height = 13 Caption = '&Path' end object AliasLabel: TLabel Left = 180 Top = 4 Width = 22 Height = 13 Caption = '&Alias' FocusControl = lbAlias end object ServerLabel: TLabel Left = 12 Top = 100 Width = 60 Height = 13 Caption = '&Server name' FocusControl = ServerComboBox end object StreamFormatLabel: TLabel Left = 16 Top = 233 Width = 53 Height = 13 Caption = 'Blob &format' FocusControl = StreamFormatComboBox end object lblIdDataType: TLabel Left = 168 Top = 233 Width = 62 Height = 13 Caption = 'Id Data Type' FocusControl = IdDataTypeComboBox end object lblIdSize: TLabel Left = 288 Top = 233 Width = 32 Height = 13 Caption = 'Id Size' FocusControl = IdDataTypeComboBox end object BrowseButton: TButton Left = 356 Top = 204 Width = 21 Height = 21 Caption = '...' TabOrder = 4 OnClick = BrowseButtonClick end object lbAlias: TListBox Left = 180 Top = 20 Width = 197 Height = 161 ItemHeight = 13 TabOrder = 2 end object rgSelDb: TRadioGroup Left = 12 Top = 16 Width = 157 Height = 73 Caption = '&Database Selection ' ItemIndex = 0 Items.Strings = ( 'Alias' 'Path') TabOrder = 0 OnClick = rgSelDbClick end object ePath: TEdit Left = 16 Top = 204 Width = 333 Height = 21 TabOrder = 3 end object ServerComboBox: TComboBox Left = 12 Top = 116 Width = 157 Height = 21 ItemHeight = 13 TabOrder = 1 OnCloseUp = ServerComboBoxLoadAlias OnDropDown = ServerComboBoxDropDown OnExit = ServerComboBoxLoadAlias OnSelect = ServerComboBoxSelect end object StreamFormatComboBox: TComboBox Left = 16 Top = 249 Width = 145 Height = 21 Style = csDropDownList ItemHeight = 13 Sorted = True TabOrder = 5 end object IdDataTypeComboBox: TComboBox Left = 168 Top = 249 Width = 113 Height = 21 Style = csDropDownList ItemHeight = 13 TabOrder = 6 end object IdSizeEdit: TEdit Left = 288 Top = 249 Width = 89 Height = 21 TabOrder = 7 end end object BottomPanel: TPanel Left = 0 Top = 274 Width = 393 Height = 35 Align = alBottom BevelOuter = bvNone TabOrder = 1 DesignSize = ( 393 35) object OkButton: TButton Left = 223 Top = 6 Width = 75 Height = 25 Anchors = [akTop, akRight] Caption = 'OK' Default = True ModalResult = 1 TabOrder = 0 end object CancelButton: TButton Left = 303 Top = 6 Width = 75 Height = 25 Anchors = [akTop, akRight] Cancel = True Caption = 'Cancel' ModalResult = 2 TabOrder = 1 end end end --- NEW FILE: InstantNexusDbSQL.dcr --- (This appears to be a binary file; contents omitted.) --- NEW FILE: InstantNexusDbSQLReg.pas --- (* * InstantObjects * NexusDbSQL Support *) (* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is: Seleqt InstantObjects * * The Initial Developer of the Original Code is: Seleqt * * Portions created by the Initial Developer are Copyright (C) 2001-2003 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** *) unit InstantNexusDbSQLReg; interface procedure Register; implementation uses Classes, InstantNexusDbSQL; procedure Register; begin RegisterComponents('InstantObjects', [TInstantNexusDbSQLConnector]); end; end. --- NEW FILE: InstantNexusDbSQLConnectionDefEdit.pas --- (* * InstantObjects(tm) NexusDbSQL Broker Support - ConnectionDefEdit * * Copyright (c) Seleqt * Copyright (c) Carlo Wolter - cw...@te... * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is InstantObject NexusDb Broker. The Initial Developer of the Original Code is Carlo Wolter. Portions created by Seleqt are Copyright (C) Seleqt. All Rights Reserved. ===================================================================== Limited warranty and disclaimer of warranty ===================================================================== This software and accompanying written materials are provided "as is" without warranty of any kind. Further, the author does not warrant, guarantee, or take any representations regarding the use, or the results of use, of the software or written materials in terms of correctness, accuracy, reliability, currentness or otherwise. The entire risk as to the results and performance of the software is assumed by you. Neither the author nor anyone else who has been involved in the creation, production or delivery of this product shall be liable for any direct, indirect, consequential or incidental damages (including damages for loss of business profits, business interruption, loss of business information and the like) arising out of the use or inability to use the product even if the author has been advised of the possibility of such damages. By using the InstantObject NexusDb Broker component you acknowledge that you have read this limited warranty, understand it, and agree to be bound by its' terms and conditions. ===================================================================== * Contributor(s): * Carlo Barazzetta: blob streaming in XML format (Part, Parts, References) * *) unit InstantNexusDbSQLConnectionDefEdit; interface {$IFNDEF VER130} {$WARN UNIT_PLATFORM OFF} {$ENDIF} uses Windows, Forms, StdCtrls, Controls, ExtCtrls, Classes ,InstantNexusDbSQL, nxllComponent, nxdb /// , CSIntf ; type TInstantNexusDbSQLConnectionDefEditForm = class(TForm) BottomBevel: TBevel; BottomPanel: TPanel; CancelButton: TButton; ClientPanel: TPanel; OkButton: TButton; PathLabel: TLabel; BrowseButton: TButton; AliasLabel: TLabel; lbAlias: TListBox; rgSelDb: TRadioGroup; ePath: TEdit; ServerComboBox: TComboBox; ServerLabel: TLabel; StreamFormatLabel: TLabel; StreamFormatComboBox: TComboBox; IdDataTypeComboBox: TComboBox; IdSizeEdit: TEdit; lblIdDataType: TLabel; lblIdSize: TLabel; procedure BrowseButtonClick(Sender: TObject); procedure ServerComboBoxSelect(Sender: TObject); procedure rgSelDbClick(Sender: TObject); procedure ServerComboBoxLoadAlias(Sender: TObject); procedure FormShow(Sender: TObject); procedure ServerComboBoxDropDown(Sender: TObject); procedure FormCreate(Sender: TObject); private FConnectionDef : TInstantNexusDbSQLConnectionDef; procedure UpdateControls; protected procedure LoadAliasNames; public procedure LoadData(ConnectionDef: TInstantNexusDbSQLConnectionDef); procedure SaveData(ConnectionDef: TInstantNexusDbSQLConnectionDef); end; implementation uses SysUtils, FileCtrl, InstantClasses, InstantPersistence, InstantConsts; {$R *.DFM} { TInstantNexusDbSQLConnectionDefEditForm } procedure TInstantNexusDbSQLConnectionDefEditForm.BrowseButtonClick(Sender: TObject); var Dir: string; begin if SelectDirectory('Database Directory', '', Dir) then ePath.Text := Dir; end; procedure TInstantNexusDbSQLConnectionDefEditForm.LoadAliasNames; var OldAliasName : string; begin Screen.Cursor := crHourGlass; if lbAlias.ItemIndex >= 0 then OldAliasName := lbAlias.Items.Strings[lbAlias.ItemIndex]; Try FConnectionDef.ServerName := ServerComboBox.Text; FConnectionDef.LoadAliasList(lbAlias.Items); Finally if OldAliasName <> '' then lbAlias.ItemIndex := lbAlias.Items.IndexOf(OldAliasName); Screen.Cursor := crDefault; End; end; procedure TInstantNexusDbSQLConnectionDefEditForm.LoadData( ConnectionDef: TInstantNexusDbSQLConnectionDef); begin /// CodeSite.SendMsg('FORM load data'); FConnectionDef := ConnectionDef; if ConnectionDef.AliasIsPath then begin rgSelDb.ItemIndex := 1; ePath.Text := ConnectionDef.AliasName; end else begin rgSelDb.ItemIndex := 0; ServerComboBox.Text := ConnectionDef.ServerName; LoadAliasNames; lbAlias.ItemIndex := lbAlias.Items.IndexOf(ConnectionDef.AliasName); end; StreamFormatComboBox.ItemIndex := Ord(ConnectionDef.BlobStreamFormat); //CB // Begin SRM - 02 Oct 2004 IdDataTypeComboBox.ItemIndex := Ord(ConnectionDef.IdDataType); IdSizeEdit.Text := IntToStr(ConnectionDef.IdSize); // End SRM - 02 Oct 2004 UpdateControls; end; procedure TInstantNexusDbSQLConnectionDefEditForm.SaveData( ConnectionDef: TInstantNexusDbSQLConnectionDef); begin /// CodeSite.SendMsg('FORM save data'); case rgSelDb.ItemIndex of 0: begin ConnectionDef.ServerName := ServerComboBox.Text; if lbAlias.ItemIndex >= 0 then ConnectionDef.AliasName := lbAlias.Items.Strings[lbAlias.ItemIndex] else ConnectionDef.AliasName := ''; ConnectionDef.AliasIsPath := False; // True Alias end; 1: begin ConnectionDef.AliasName := ePath.Text; ConnectionDef.AliasIsPath := True; // Path end; end; ConnectionDef.BlobStreamFormat := TInstantStreamFormat(StreamFormatComboBox.ItemIndex); //CB // Begin SRM - 02 Oct 2004 ConnectionDef.IdDataType := TInstantDataType(IdDataTypeComboBox.ItemIndex); ConnectionDef.IdSize := StrToInt(IdSizeEdit.Text); // End SRM - 02 Oct 2004 /// CodeSite.SendBoolean('Alias '+ConnectionDef.AliasName,ConnectionDef.AliasIsPath); end; procedure TInstantNexusDbSQLConnectionDefEditForm.ServerComboBoxSelect( Sender: TObject); begin LoadAliasNames; end; procedure TInstantNexusDbSQLConnectionDefEditForm.rgSelDbClick( Sender: TObject); begin UpdateControls; end; procedure TInstantNexusDbSQLConnectionDefEditForm.UpdateControls; begin PathLabel.Visible := rgSelDb.ItemIndex = 1; ePath.Visible := rgSelDb.ItemIndex = 1; BrowseButton.Visible := rgSelDb.ItemIndex = 1; AliasLabel.Visible := rgSelDb.ItemIndex = 0; lbAlias.Visible := rgSelDb.ItemIndex = 0; ServerComboBox.Visible := rgSelDb.ItemIndex = 0; ServerLabel.Visible := rgSelDb.ItemIndex = 0; end; procedure TInstantNexusDbSQLConnectionDefEditForm.ServerComboBoxLoadAlias( Sender: TObject); begin LoadAliasNames; end; procedure TInstantNexusDbSQLConnectionDefEditForm.FormShow(Sender: TObject); begin rgSelDb.SetFocus; end; procedure TInstantNexusDbSQLConnectionDefEditForm.ServerComboBoxDropDown( Sender: TObject); begin Screen.Cursor := crHourGlass; Try FConnectionDef.LoadServerList(ServerComboBox.Items); Finally Screen.Cursor := crDefault; End; end; procedure TInstantNexusDbSQLConnectionDefEditForm.FormCreate(Sender: TObject); begin AssignInstantStreamFormat(StreamFormatComboBox.Items); //CB AssignInstantDataTypeStrings(IdDataTypeComboBox.Items); // SRM - 02 Oct 2004 IdDataTypeComboBox.ItemIndex := Ord(dtString); // SRM - 02 Oct 2004 IdSizeEdit.Text := IntToStr(InstantDefaultFieldSize); // SRM - 02 Oct 2004 UpdateControls; // SRM - 02 Oct 2004 end; end. |