Bug #50842 variables not passed across module boundaries in VC++ 2010
Submitted: 2 Feb 2010 17:42 Modified: 1 Jul 2010 15:07
Reporter: M Mou Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / C++ Severity:S2 (Serious)
Version:1.0.5 OS:Windows (Windows 7 RTM)
Assigned to: Lawrenty Novitsky CPU Architecture:Any
Tags: c++0x, visual c++ 2010, visual studio 2010

[2 Feb 2010 17:42] M Mou
Description:
When running the tutorial samples, specifically calls such as 
    con.reset( driver->connect( url, user, pass ) );
or 
    std::string const& driver_name = driver->getName();

The function parameters/return arguments are not being passed correctly, garbage/uninitialized variables (0xcccccccc) are passed for url/user/pass/driver_name instead.

How to repeat:
Visual Studio 2010 Beta 2, running on Windows 7 RTM
MySQL Connector/C++ version 1.0.5, dynamic linkage

In the tutorial framework, add this code:
    sql::Driver* const driver = get_driver_instance();
    ASSERT( driver );
    std::string const& driver_name = driver->getName();
    std::string name_copy( driver_name );

The value of driver_name will be garbage.

Suggested fix:
At the top of driver\mysql_driver.cpp, move all the static variables used in the file to the top, like so:

namespace {
    static bool module_already_loaded = 0;
    static sql::mysql::MySQL_Driver d;
    static const std::string name("MySQL Connector C++ (libmysql)");
}

Recompile, the driver set up functions seem to work okay now.
[9 Feb 2010 14:12] Tonci Grgin
Hi and thanks for your report.

This is a known problem which happens when application and driver use different crt's.
That's why we deliver binaries built both w/ vs2005 and vs2008.
So, the binary wasn't compiled with VS2010 or you use debug and our binaries are not debug, you get the point.
Marking this as "verified as described".

You need to compile the connector yourself with VC2010.

The problem should have already been addressed in new release but I'll leave for Lawrin to close.