#1 2014-09-30 14:02:42

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

UniDAC/MySQL CreateDefaultTables Problem

Given : 1 MySQL Server with 2 Databases (Base1, Base2)

1. I connected my mORMot EXE  to Base1 and called CreateMissingTables - Everything works fine
2. I connected my mORMot EXE  to Base2 and called CreateMissingTables - Get Error Message: Table not found. This is correct, the Table is not in Base2 but in Base1.

After Some Debugging i found the Error:
You Call Metadata for 'columns' in UniDAC without giving the Schema name In my Case Base1 or Base2
The Result is that you retrieve the Columns from Base1
The Second Metadata you select is Indexes and here the Error comes with Table not found.

Can you fix this please.

Place of error (SynDBUniDAC):

  meta := (MainConnection as TSQLDBUniDACConnection).fDatabase.CreateMetaData;
  try
    FA.Init(TypeInfo(TSQLDBColumnDefineDynArray),Fields,@n);
    FA.Compare := SortDynArrayAnsiStringI; // FA.Find() case insensitive
    FillChar(F,sizeof(F),0);
    meta.MetaDataKind := 'Columns';
    Split(aTableName,'.',Owner,Table);
    if Table='' then begin
      Table := Owner;
      Owner := '';
    end;
    if Owner<>'' then
      meta.Restrictions.Values['TABLE_SCHEMA'] := UTF8ToString(UpperCase(Owner));
    meta.Restrictions.Values['TABLE_NAME'] := UTF8ToString(UpperCase(Table));
    meta.Open;
    hasSubType := meta.FindField('DATA_SUBTYPE')<>nil;
    while not meta.Eof do begin

Owner is not set (I don't know where i can set Owner ?). For MySQL the Owner is the databasename which i set to base1/base2

Last edited by itSDS (2014-09-30 14:07:16)


Rad Studio 12.1 Santorini

Offline

#2 2014-09-30 16:33:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: UniDAC/MySQL CreateDefaultTables Problem

AFAIK you can force the owner.

Offline

#3 2014-09-30 21:32:39

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Re: UniDAC/MySQL CreateDefaultTables Problem

ATM i found a solution:

procedure TSQLDBUniDACConnectionProperties.GetFields(
  const aTableName: RawUTF8; var Fields: TSQLDBColumnDefineDynArray);

...

    if Table='' then begin
      Table := Owner;
      Owner := '';
    end;
//    if Owner = '' then
//      Owner := MainConnection.Properties.DatabaseName;
    meta.Restrictions.Values['SCOPE'] := 'LOCAL';
    if Owner<>'' then
      meta.Restrictions.Values['TABLE_SCHEMA'] := UTF8ToString(UpperCase(Owner));
    meta.Restrictions.Values['TABLE_NAME'] := UTF8ToString(UpperCase(Table));

...

Setting SCOPE to LOCAL forces UniDAC to set SCHEMA to DATABASE() (for MySQL - didn't test yet for other DB-Server)

The other Alternative is to set:
      Owner := MainConnection.Properties.DatabaseName;

What do you think about it


Rad Studio 12.1 Santorini

Offline

Board footer

Powered by FluxBB