Hi,
D2010 > UniDAC > SQL Server 2008
Is there any way I can globally (in TUniConnection or TUniQuery) set it to force empty TWideString fields to nulls for posting to SQL Server (or other DBs).
I know I can set these at the field level before posting but I wanted to do it generally across the application.
If it's not possible, where should I look to amend the UniDAC source to achieve this effect please?
Regards, Paul.
Setting empty string to null automatically
Hi,
The problem there is, even with DEFAULT NULL on the DB fields, UniDAC sets the param value to '' (an empty string).
This is OK from the DB point of view since it's NOT NULL but also it doesn't cause the server to set it to NULL because it actually has a value.
What I was after was a way to set the param value used in an update command to NULL if it had a zero length string (after trimming, etc).
This is to stop users entering a few spaces or alternatively, deleting all characters from an existing field and posting '' to the DB.
I know the differences between NULL and '' but in this case, having a zero length string in the DB doesn't make sense.
I suppose I ought to add a CHECK contraint to ensure LEN(TRIM(field)) > 0
Regards, Paul.
The problem there is, even with DEFAULT NULL on the DB fields, UniDAC sets the param value to '' (an empty string).
This is OK from the DB point of view since it's NOT NULL but also it doesn't cause the server to set it to NULL because it actually has a value.
What I was after was a way to set the param value used in an update command to NULL if it had a zero length string (after trimming, etc).
This is to stop users entering a few spaces or alternatively, deleting all characters from an existing field and posting '' to the DB.
I know the differences between NULL and '' but in this case, having a zero length string in the DB doesn't make sense.
I suppose I ought to add a CHECK contraint to ensure LEN(TRIM(field)) > 0
Regards, Paul.
Please find the following line in SQLServerUniProvider.pas:
and replace True with False.
Code: Select all
TOLEDBREcordSet(Obj).SetProp(prEnableEmptyStrings, True);