SQL Server fixed binary column

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 25-Apr-2019 11:07:08   

LLBLGen v4.2

I am trying to define a fixed-length binary column for SQL server.

In the Designer:- The Field is byte[] with Max Length 20. The Field mapping is 'binary' with Max Length 20.

But the generated code doesn't include the Length! What am I missing?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 25-Apr-2019 11:41:45   

'Generated code doesn't include the length', you mean: it doesn't define a byte[20] array? That's correct, it validates the value when it's set. We don't use defined member variables so there's no private byte[] _foo = new byte[20]; possible, hence we do it when the value is set and validate the length. You do that and it doesn't validate/report an error and accepts a longer array?

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 25-Apr-2019 11:48:59   

No, I mean the SQL Creation script doesn't contain the length:

[Hash] [binary] NOT NULL 

Should be

[Hash] [binary] (20) NOT NULL 
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 25-Apr-2019 12:34:01   

Looks like a bug indeed. Also present in 5.5.3. Looking into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39760
Joined: 17-Aug-2003
# Posted on: 25-Apr-2019 12:44:27   

To fix it in 4.2, open Template Viewer and select the 'DDL SQL' framework. Then select SQL Server -> then select SQL Server specific template bindings. Open the FieldCreationInclude template (it's almost at the bottom).

In the switch statement in the CreateFieldDefinitionString() method, add:


            case SqlDbTypes.Binary:
                toReturn.AppendFormat("({0})", field.TypeDefinition.Length);
                break;

to make sure it appends a length.

Frans Bouma | Lead developer LLBLGen Pro
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 25-Apr-2019 14:42:53   

Found it and all working now. Thanks!