# Database Schemas - How To View On Server At RunTime

**URL:** https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911
**Category:** Data Abstract
**Tags:** delphi
**Created:** [October 17, 2024, 4:54pm UTC](https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911 "2024-10-17T16:54:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![is2software](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/i/b5ac83/32.png) [@is2software](https://talk.remobjects.com/u/is2software)
#### Post date: [October 17, 2024, 4:54pm UTC](https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911/1 "2024-10-17T16:54:40Z")

</div>

Using a custom Delphi DataAbstract Server, how could we view the Schema tables and fields during runtime to make sure we are using current loaded schema? How do we call the Schema and then list the tables and fields from the server.

We are sometimes loading a new schema in the OnCreate of the DataService\_Impl. We would like to check that schema loaded against the current database on that specific machine. Just to make sure we have everything in sync.

Thanks ahead of time.  
Bill Brittain

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [October 17, 2024, 5:35pm UTC](https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911/2 "2024-10-17T17:35:58Z")

</div>

Hi,

You can use [Local Data Adapter](https://docs.dataabstract.com/Concepts/DataAdapters/LocalDataAdapter/) on server-side or [Remote Data Adapters](https://docs.dataabstract.com/Concepts/DataAdapters/RemoteDataAdapter/) on client-side.

this component has [Schema](https://docs.dataabstract.com/API/Delphi/Classes/TDALocalDataAdapter/#Schema) property.

---

<div class="post-metadata">

### Author: ![is2software](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/i/b5ac83/32.png) [@is2software](https://talk.remobjects.com/u/is2software)
#### Post date: [October 18, 2024, 4:27pm UTC](https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911/3 "2024-10-18T16:27:22Z")

</div>

Thank you. We have been able to pull the schema tables and fields and get the information that we needed. Below is the code if anyone wishes to use it. Just use whatever you wish for the in memory datatables.

 ![2024-10-18_11-23-46](https://talk.remobjects.com/uploads/default/original/3X/6/1/615c1c674f31b2ca0e5b1fcb66d3bf7ed80e7449.png)

```auto
procedure TServerForm.bn_LoadServerSchemaClick(Sender: TObject);
var
  xDataSets : TDADataSetCollection;
  xFields : TDAFieldCollection;
  xField : TDAField;
  i : Integer;
  j : Integer;

  xTable_Name : string;

  xField_Name : string;
  xField_Type : string;
  xField_Size : integer;
  xField_DecimalPrecision : integer;
  xField_DecimalScale : integer;
  xField_PrimaryKey : boolean;
  xField_LogChanges : boolean;
  xField_DisplayFormat : string;
  xField_Alignment : string;
begin

  try

    ta_ServerSchema_Tables.DisableControls;
    ta_ServerSchema_Tables.Open;

    ta_ServerSchema_Fields.DisableControls;
    ta_ServerSchema_Fields.Open;
    ta_ServerSchema_Fields.Filtered := true;

    xDataSets := da_LocalDataAdapter.Schema.Datasets;

    for i := 0 to xDataSets.Count-1 do
    begin

      xTable_Name := xDataSets[i].Name;

      with ta_ServerSchema_Tables do
      begin
        Append;
        FieldByName( 'Table_Name' ).AsString := xTable_Name;
        Post;
      end;

      xFields := xDataSets[i].Fields;

      for j := 0 to xFields.Count-1 do
      begin

        xField := xFields[j];

        xField_Name := xFields[j].Name;
        xField_Type := GetFieldType( xFields[j].DataType );
        xField_Size := xFields[j].Size;
        xField_DecimalPrecision := xFields[j].DecimalPrecision;
        xField_DecimalScale := xFields[j].DecimalScale;
        xField_PrimaryKey := xFields[j].InPrimaryKey;
        xField_LogChanges := xFields[j].LogChanges;
        xField_DisplayFormat := xFields[j].DisplayFormat;
        xField_Alignment := GetFieldAlignment( xFields[j].Alignment );

        with ta_ServerSchema_Fields do
        begin
          Append;
          FieldByName( 'Table_Name' ).AsString := xTable_Name;
          FieldByName( 'Field_Name' ).AsString := xField_Name;
          FieldByName( 'Field_Type' ).AsString := xField_Type;
          FieldByName( 'Field_Size' ).AsInteger := xField_Size;
          FieldByName( 'Field_DecimalPrecision' ).AsInteger := xField_DecimalPrecision;
          FieldByName( 'Field_DecimalScale' ).AsInteger := xField_DecimalScale;
          FieldByName( 'Field_PrimaryKey' ).AsBoolean := xField_PrimaryKey;
          FieldByName( 'Field_LogChanges' ).AsBoolean := xField_LogChanges;
          FieldByName( 'Field_DisplayFormat' ).AsString := xField_DisplayFormat;
          FieldByName( 'Field_Alignment' ).AsString := xField_Alignment;
          Post;
        end;

      end;

    end;

  finally
    ta_ServerSchema_Tables.EnableControls;
    ta_ServerSchema_Fields.EnableControls;
  end;

end;

```

---

<div class="post-metadata">

### Author: ![is2software](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/i/b5ac83/32.png) [@is2software](https://talk.remobjects.com/u/is2software)
#### Post date: [October 18, 2024, 4:38pm UTC](https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911/4 "2024-10-18T16:38:34Z")

</div>

The next thing we are working on is updating the schema on the working server.  
How do we add, edit, and delete fields from the schema while the server is in operation?

We would like to sometimes add a new field to an existing table, or maybe alter the Display Format.

We can certainly do this by altering and loading a completely new schema but we would like to modify on the existing schema just maybe one field. Can that be done? We have been able to pull an example of one field by finding the TDADataSet and then getting the TDAField. Then we have assigned the DisplayFormat to that Field on the Schema.

How do we make the change persist on the Schema? Are these values read only?

```auto
procedure TServerForm.bn_UpdateServerSchemaFieldClick(Sender: TObject);
var
  xDataSet : TDADataSet;
  xField : TDAField;

  xTable_Name : string;
  xField_Name : string;

  xField_DisplayFormat : string;

begin
  xTable_Name := ta_ServerSchema_Fields.FieldByName( 'Table_Name' ).AsString;
  xField_Name := ta_ServerSchema_Fields.FieldByName( 'Field_Name' ).AsString;

  xDataSet := da_LocalDataAdapter.Schema.FindDataset( xTable_Name );
  xField := xDataSet.FieldByName( xField_Name );

  xField.DisplayFormat := 'mm/dd/yyyy'; // xField_DisplayFormat;

end;

```

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [October 28, 2024, 6:45am UTC](https://talk.remobjects.com/t/database-schemas-how-to-view-on-server-at-runtime/30911/5 "2024-10-28T06:45:25Z")

</div>

Hi,

> [@is2software](#):
>
> How do we add, edit, and delete fields from the schema while the server is in operation?

You can do this in [DataService.OnActivate](https://docs.remotingsdk.com/API/Delphi/Classes/TRORemoteDataModule/#OnActivate) event.

if you want to change server-side schema, you should save changed schema and load in this event.

I can suggest to put TDASchema to server’s data module and copy it’s content like

```auto
procedure TDataService.DataAbstractServiceActivate(const aClientID: TGUID;
  aSession: TROSession; const aMessage: IROMessage);
begin  
  Self.ServiceSchema.Assign(ServerDataModule.DASchema1);
end;

```

You can update this schema (`ServerDataModule.DASchema1`) and updated schema will be available for all next calls.

in general, implementation may depend on used [Class Factories (.NET & Delphi)](https://docs.remotingsdk.com/Servers/Concepts/ClassFactories/) and other factors.
