Delphi dad driver problem

Hi,

I’m changing the uniDAC dad driver to change the names of the table fields in pascalcase. I’m connet to oracle DB and all filed names are in upper case. I changed the method Oracle_DoGetTableFields of the unit uDAOracleInterfaces. I changed this:

original:

While not Query.Eof do begin
  fld := Fields.Add;
  fld.Name:=Query.Fields[0].AsString;
 ldt:=OracleTypeToDADataType.....

with this:

While not Query.Eof do begin
  fld := Fields.Add;
  fld.Name:=PascalCaseString(Query.Fields[0].AsString); //Query.Fields[0].AsString;
  fld.TableField := Query.Fields[0].AsString;
  fld.SQLOrigin := Query.Fields[0].AsString;

The function PascalCaseString return a new string in pascal case format and remove the undescore char.

The problem is in the DASchemaModeler. Despite having set the TableField and SQLOrigin properties these are not read correctly. It seems that DASchemaModeler always takes the field name as reference for these settings.

Is it a problem of the DASchemeModeler? I tried to check in the code but the change I made seems the only possible one.

I’m creating a new application on a database that I don’t handle and I heavily use the strongly-typed access unit.

It would be an interesting feature to be able to integrate the management of the name of the field directly into DASchemaModeler but at the moment since there is no solution I have to automatically find the way to manage the name case without having to do it manually for all the datasets … which are really many.

Any Help?

Best regards

Hi,

everything work correctly. you have changed low level API function that retrieves table metadata so DASM thinks that your table has ONLY these fields.

it’s the same as you have updated Oracle_DoGetTableFields like

fld.Name:='!!!!'+ Query.Fields[0].AsString;

all fields will be started with !!!!.

This won’t work in this way.

Suggested way: to not change such lower level API but create SELECTs like

SELECT
   FIELD1 as Field1,
   FIELD2 as Field2

etc.

in this case mapping will be like

    Field1 | FIELD1 | field1

you can edit schema and change all mapping.TableField to upper case at starting your server.

Hi EvgenyK

many thanks for you answer. Your suggestion is not praticable for me because in many case I use AutoSQL option and not customize the SQL. In many case I use a dedicated view in AutoSQL and customize only the insert/update and delete statment.

So the only solution I see is to modify low-level APIs.

you can edit schema and change all mapping.TableField to upper case at starting your server.

Sorry, I do not understand what you mean

Hi,

Why you can’t just change field names then?
mapping will be looks like

 Field1 | FIELD1 | FIELD1

it works with AutoSQL mode too


at starting server (or service), you can update service schema like:

  for i:=0 to DASchema1.Datasets.Count -1 do
    for j :=0 to DASchema1.Datasets[i].Statements.Count -1 do
      for k := 0 to DASchema1.Datasets[i].Statements[j].ColumnMappings.Count -1 do
        DASchema1.Datasets[i].Statements[j].ColumnMappings[k].TableField := 
UpperCase(DASchema1.Datasets[i].Statements[j].ColumnMappings[k].TableField);

Hi EvgenyK

Why you can’t just change field names then?
mapping will be looks like

Yes, but in this case I must made this manually. I need to menaged many datasets (about 1000).
I would like an automatic way that is managed inside of the DASchemaModeler.

at starting server (or service), you can update service schema like:

The problem is not only the case of the names but the result name of the field name is different of the real field name. For example

Original table field:

TIPO_INTERVENTO_FK

This is what I would like to get (automatically)

Schema Table field: TipoInterventoFk
Table field: TIPO_INTERVENTO_FK
SQL Alias: TIPO_INTERVENTO_FK

As you can see the name of the field in the schema is different from the name of the physical field on the database.

Hi,

you can create a simple Delphi program that will modify Field and mapping.DatasetField in the same way as my code above.
so it won’t be a problem.
for processed tables, you can add a custom attribute so table won’t be processed twice.

just launch it after updating schema or update Delphi IDE package so your utility will be launched automatically after updating schema.

Hi EvgenyK

so from what I understand the only way is to modify the dfm afterwards (I use the schema internally in the DFM and not external).

I don’t understand why this cannot be managed directly by the DAD driver inasmuch internally use a TDAField object that supports the TableField and SQLAlias properties.

just launch it after updating schema or update Delphi IDE package so your utility will be launched automatically after updating schema.

How?

Thank you

Claudio

not yet.
schema from .dfm is written to .daSchema and this .daSchema is passed to DASM, later .daSchema is read again into .dfm

check uDADataAbstractServerEditors.pas code:

procedure TDASchemaEditor.ExecuteVerb(Index: Integer);
..
    case Index of
      COMMAND_INDEX_EDIT: begin
...
        try
          lf := CreatePleaseWaitForm('Running the Schema Modeler...');
          try
            lf.Show();
            ExecuteAndWait(GetSchemaModelerPath, '/ns /platform:Delphi /projectname:"'+GetComponent().Name+'" /autosave /schemafile:"'+sfname+'"');
//<<< add here call of your utility and pass `sfname` to it
            lf.Hide();
          finally
            lf.Free();
          end;
1 Like

Hi EvgenyK

many thanks! I made a console utility and I changed the IDE package with your suggestion. This work fine and I managed to get what I want.

Only one thing I don’t like is that to see the final result I have to close and reopen the DASchemaModeler…but this is a relative problem :wink:

Best Regards

1 Like