2 messages in com.mysql.lists.plusplusRe: Null values do not compile...
FromSent OnAttachments
Maarten Schrijvers02 Oct 2007 08:00 
Maarten Schrijvers03 Oct 2007 08:20 
Subject:Re: Null values do not compile...
From:Maarten Schrijvers (maar@gmail.com)
Date:10/03/2007 08:20:24 AM
List:com.mysql.lists.plusplus

OK. I Google'd and saw many people had similar problems with ambiguity in VS2005. However, I didn't find how they resolved their problems (if at all). So I decided to create a work-around which I would like to share: Passing a "(NULL)" string to my database where a trigger sets that value to a proper SQL null.

Quite simple actually, just a pain in the butt to maintain it in two places, but hey can't have it all ;)

I have some fields which can be (SQL) NULL. If they are filled they are varchar, but they're not necessary, so they could be NULL. Compiling gives me an error though:

c:\mysql++\include\null.h(206) : error C2593: 'operator =' is ambiguous

1> E:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(923): could be 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)'

1> with

1> [

1> _Elem=char,

1> _Traits=std::char_traits<char>,

1> _Ax=std::allocator<char>

1> ]

1> E:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(918): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)'

1> with

1> [

1> _Elem=char,

1> _Traits=std::char_traits<char>,

1> _Ax=std::allocator<char>

1> ]

1> E:\Program Files\Microsoft Visual Studio 8\VC\include\xstring(913): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const std::basic_string<_Elem,_Traits,_Ax> &)'

1> with

1> [

1> _Elem=char,

1> _Traits=std::char_traits<char>,

1> _Ax=std::allocator<char>

1> ]

1> while trying to match the argument list '(mysqlpp::sql_varchar, mysqlpp::null_type)'

1> c:\mysql++\include\null.h(204) : while compiling class template member function 'mysqlpp::Null<Type>::operator Type(void)'

1> with

1> [

1> Type=mysqlpp::sql_varchar

1> ]

1> e:\visual studio 2005\projects\t_1\urenregistratie\Relatieonderhoud.h(25) : see reference to class template instantiation 'mysqlpp::Null<Type>' being compiled

1> with

1> [

1> Type=mysqlpp::sql_varchar

1> ]

I have declared the following:

typedef mysqlpp::Null<mysqlpp::sql_varchar> Nullstr;

static Nullstr vVoornamen = mysqlpp::null; //gave the variable a value trying to avoid the error

What am I doing wrong?