#1 2025-12-19 16:08:03

larand54
Member
Registered: 2018-12-25
Posts: 120

Can not have a field with "Stored AS_UNIQUE" using the new OLEDB-drive

I get the following Error message:

Project TestExtDBConnection.exe raised exception class EOleDBException with message 'TSqlDBOleDBConnection: OleDB error [] (0x80040E14) -   (line 1): Could not create constraint or index. See previous errors.
  (line 1): Column 'CustomerID' in table 'Customer' is of a type that is invalid for use as a key column in an index.'.

The ORM-table:

  TOrmCustomer = class(TOrm)
  private
    fName: RawUTF8;
    fCustomerID: RawUTF8;
  published
    property Name: RawUTF8 read fName write fName;
    property CustomerID: RawUTF8 read fCustomerID write fCustomerID stored AS_UNIQUE;
  end;

Some code:

function CreateOSModel: TOrmModel;
begin
  result := TOrmModel.Create([TOrmCustomer]);
end;

var
  model: TOrmModel;
  props: TSQLDBConnectionProperties;
  RestServer: TRestServerDB;
begin
  model := CreateOSModel;
  Props := GetODBCDriverSpec.Create('MyServer', 'MyDB', '', '');

  VirtualTableExternalRegister(Model, TOrmCustomer, props, 'dbo.Customer');
  RestServer :=  TRestServerDB.Create(Model, ':memory:');
  RestServer.CreateMissingTables;             <<<---- Getting error here.

Last edited by larand54 (2025-12-19 23:47:21)


Delphi-11, WIN10 and Win11

Offline

#2 2025-12-19 18:06:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,346
Website

Re: Can not have a field with "Stored AS_UNIQUE" using the new OLEDB-drive

What is the table definition in the database? Check the CustomerID column type.
Which DB are you using?

Offline

#3 2025-12-19 20:34:11

larand54
Member
Registered: 2018-12-25
Posts: 120

Re: Can not have a field with "Stored AS_UNIQUE" using the new OLEDB-drive

I Use Microsofts sql server  and there is no table in the database it should have been created by "CreateMissingTables".


Delphi-11, WIN10 and Win11

Offline

#4 2025-12-20 09:21:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,346
Website

Re: Can not have a field with "Stored AS_UNIQUE" using the new OLEDB-drive

On MS SQL Server, you need to specify a length to the RawUtf8 field, so that it creates a VARCHAR field.
Currently, it creates a CBLOB which can't be indexed on MS SQL, by definition.
Look at the SQL generated to create the table and the index, and you will find it.

Offline

Board footer

Powered by FluxBB