|
-
August 25th, 2004, 12:07 PM
#1
Empty string stored as NULL by MFC for MS SQL 2K
Trying to following other SQL recommendations, many of my table columns do not allow NULLs.
However, when I have code like this:
recordSet.Edit();
recordSet.m_MyColumn = '';
recordSet.Update();
With "MyColumn" not allowing NULLs, I get the exception "Cannot insert NULL values into column..."
This is because of this code in MFC during DoFieldExchange RFX_Text (DBRFX.cpp)
case CFieldExchange::MarkForUpdate:
if (value.IsEmpty())
pFX->m_prs->SetNullFieldStatus(nField - 1); else
pFX->m_prs->ClearNullFieldStatus(nField - 1);
value.IsEmpty is TRUE, so the field (column) is marked as NULL.
Any suggestions how to get the empty string into MyColumn?
Thanks for reading this far.
Jim O'Leary
-
March 3rd, 2005, 02:17 PM
#2
Re: Empty string stored as NULL by MFC for MS SQL 2K
Jim,
Did you ever get a fix for this? I have the same issue and am now inserting a space into the fields. I don't like it but it works. I would like to find a better solution if you do have one could you share it.
Thanks,
Darstan
-
March 3rd, 2005, 02:27 PM
#3
Re: Empty string stored as NULL by MFC for MS SQL 2K
Darstan-
Unfortunately, I do not have a fix or a better workaround to recommend.
Ulitmately, I decided to take my chances and allow NULLs.
I wish I had better news.
jim
-
March 4th, 2005, 06:06 AM
#4
Re: Empty string stored as NULL by MFC for MS SQL 2K
What RDBMS is that?
If SQL Server 2000+ or Oracle 9i+ than (for sure) U can use "instead of" triggers to do that.
U can also try to override class (and IsEmpty() function) that stands behind "value" so in case of empty string "value.IsEmpty()" will return FALSE.
But IMHO it is better to insert nulls (in case of empty strings).
Best regards,
Krzemo.
-
March 4th, 2005, 09:38 AM
#5
Re: Empty string stored as NULL by MFC for MS SQL 2K
Krzemo-
Thank you for your response. It neven occurred to me to consider an "instead of" trigger.
Nor would I have thought to try an override for IsEmpty.
I appreciate your consideration of my problem
jim
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|