15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Updating a database field to a null value

Martin Bell -- Martin.Bell@BTInternet.com
Thursday, February 27, 1997

Environment: NT 3.51 MSVC 4.2b 
ODBC (Oracle 32 bit Driver 1.16.0301)

I am trying to set null a date/time field in a recordset 
using the Edit/Update methods of updating the record set.
If I set the outputColumn field to null I get the base date
(1/1/1970 or whatever). Using the recordset function 
SetFieldNull(&m_DTCol,TRUE) I get an assertion failure 
because it is not a parameter. To get round this  I have ended 
up doing the following:

Copy all current values of recordset member variables into 
local variables except m_DTCol.

Edit()

SetFieldNull(NULL);

Copy back local variables into recordset member variables

Update()

This works but I would like to know if I was doing something 
wrong with the first attempt to use SetFieldNull or if anyone
has a better method.


Martin Bell





GoroKhM1 -- gorokhm1@SMTP.ATG-NET.COM
Thursday, February 27, 1997

[Mini-digest: 3 responses]

I had similar problem with DAO date/time field. The field with NULL
value (without value!) never returns status COleDateTime::null. 
I solved the problem with explicit init the date/time field.


COleDateTime F_GetNullDate()
{
  return COleDateTime(1899, 12, 30, 0, 0, 0);
}


// This is extacted .. and not tested.
void SomeRecordset::SetNullDate(LPCTSTR lpszDateField)
{
  COleDateTime odt = F_GetNullDate();
  try
  {
    Edit();
    SetFieldValue(lpszDateField, odt);
    Update();
  }
  catch
  {
    ..
  }
}

MarkG@usa.net

-----From: "Yoskowitz, David" 

Martin,

The SetFieldNull method (in MFC's DBCORE.cpp), first checks to see if
the given field is a parameter, in which case it calls
SetNullParamStatus.  Is it possible that you're passing a param to
SetFieldNull?  SetNullFieldStatus is only called by the record field
exchange functions if it is not the "param" case (maybe MFC should have
provided both SetFieldNull and SetParamNull methods).  By the way, where
is the ASSERT happening?

Dave Yoskowitz

>----------
>From: 	Martin Bell[SMTP:Martin.Bell@BTInternet.com]
>Sent: 	Thursday, February 27, 1997 6:18 AM
>To: 	mfc-l@netcom.com
>Subject: 	Updating a database field to a null value
>
>Environment: NT 3.51 MSVC 4.2b 
>ODBC (Oracle 32 bit Driver 1.16.0301)
>
>I am trying to set null a date/time field in a recordset 
>using the Edit/Update methods of updating the record set.
>If I set the outputColumn field to null I get the base date
>(1/1/1970 or whatever). Using the recordset function 
>SetFieldNull(&m_DTCol,TRUE) I get an assertion failure 
>because it is not a parameter. To get round this  I have ended 
>up doing the following:
>
>Copy all current values of recordset member variables into 
>local variables except m_DTCol.
>
>Edit()
>
>SetFieldNull(NULL);
>
>Copy back local variables into recordset member variables
>
>Update()
>
>This works but I would like to know if I was doing something 
>wrong with the first attempt to use SetFieldNull or if anyone
>has a better method.
>
>
>Martin Bell
>
>
>
-----From: "Doug Brubacher" 

     I am surprised your original attempt did not work, what do you mean 
     by:
     
     "Using the recordset function SetFieldNull(&m_DTCol,TRUE) I get an 
     assertion failure 
     BECAUSE IT IS NOT A PARAMETER"?
     
     is m_DTCol your recordset variable? You could try to call 
     IsFieldNullable( &m_DTCol ) and check the results.
     
     Regards,
     
     Doug Brubacher
     Doug_Brubacher@compuware.com




Martin Bell -- Martin.Bell@BTInternet.com
Tuesday, March 04, 1997

Hi, 

Synopsis:

Environment: NT 3.51 MSVC 4.2b ODBC (Oracle 32 bit Driver 1.16.0301)

SetFieldNull(&m_DTCol,TRUE) fails on assert, where m_DTCol is an output
column.

The additional information requested by those who replied to my question
is :

The error message is

Debug Assertion Failed!

Program: My.exe
File: dbcore.cpp
Line 4055


void CRecordset::SetNullParamStatus(DWORD nParam)
{
	ASSERT(nParam < m_nParams);

	m_pbParamFlags[nParam] |= AFX_SQL_FIELD_FLAG_NULL;
}

As I don't have any parameters m_nParams is zero. nParams is the
selected output columns position (10)

This occurs if I have the second argument to SetFieldNull or not. I
don't see why it calls CRecordset::SetNullParamStatus() for a non
parameter. 

The database definition allows null values (otherwise I would not expect
by workaround to work), but I have not checked IsFieldNullable() to see
what it gives.

Martin Bell





Mike Blaszczak -- mikeblas@nwlink.com
Sunday, March 09, 1997

At 22:50 3/4/97 +0000, Martin Bell wrote:

>Synopsis:
>Environment: NT 3.51 MSVC 4.2b ODBC (Oracle 32 bit Driver 1.16.0301)

>SetFieldNull(&m_DTCol,TRUE) fails on assert, where m_DTCol is an output
>column. The additional information requested by those who replied to my
>question is :

>The error message is
>Debug Assertion Failed!
>Program: My.exe
>File: dbcore.cpp
>Line 4055

The problem you're suffering from is documented in the knowledge base, and
a complete workaround is provided. Unfortunately, I heard about the problem
too late to get it fixed for Visual C++ 5.0, so we'll have to live with it
for a while.

See the related KB articles on the web at:

	http://www.microsoft.com/kb/articles/q157/8/76.htm
	http://www.microsoft.com/kb/articles/q130/9/56.htm

It took only a couple of seconds to find the articles; I searched for
"NULL and field" with Product set to "Visual C++".


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.




David Little -- dlittle@equinoxcorp.com
Tuesday, March 11, 1997

[Mini-digest: 2 responses]

Or, you could try m_DTCol = CTime(NULL);

----------
From: 	Mike Blaszczak[SMTP:mikeblas@nwlink.com]
Sent: 	Sunday, March 09, 1997 10:57 AM
To: 	mfc-l@netcom.com
Subject: 	Re: Updating a database field to a null value

At 22:50 3/4/97 +0000, Martin Bell wrote:

>Synopsis:
>Environment: NT 3.51 MSVC 4.2b ODBC (Oracle 32 bit Driver 1.16.0301)

>SetFieldNull(&m_DTCol,TRUE) fails on assert, where m_DTCol is an output
>column. The additional information requested by those who replied to my
>question is :

>The error message is
>Debug Assertion Failed!
>Program: My.exe
>File: dbcore.cpp
>Line 4055

The problem you're suffering from is documented in the knowledge base, and
a complete workaround is provided. Unfortunately, I heard about the problem
too late to get it fixed for Visual C++ 5.0, so we'll have to live with it
for a while.

See the related KB articles on the web at:

	http://www.microsoft.com/kb/articles/q157/8/76.htm
	http://www.microsoft.com/kb/articles/q130/9/56.htm

It took only a couple of seconds to find the articles; I searched for
"NULL and field" with Product set to "Visual C++".


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
           This performance was not lip-synched.


-----From: Martin Bell 

Mike Blaszczak wrote:
> 
> At 22:50 3/4/97 +0000, Martin Bell wrote:
> 
> >Synopsis:
> >Environment: NT 3.51 MSVC 4.2b ODBC (Oracle 32 bit Driver 1.16.0301)
> 
> >SetFieldNull(&m_DTCol,TRUE) fails on assert, where m_DTCol is an output
> >column.

>         http://www.microsoft.com/kb/articles/q157/8/76.htm

> It took only a couple of seconds to find the articles; I searched for
> "NULL and field" with Product set to "Visual C++".
> 
The above KB article is exactly the error I was chasing. I did look at
the KB but under different search conditions and didn't spot anything of
use.

Thanks to all who contributed.

Martin Bell






Become an MFC-L member | Вернуться в корень Архива |