===============================================
Bug report -- MySQL v4.04b, source distribution
===============================================

----------------------------------------------------------------
Machine specs (build machine and test machine are same machine):
----------------------------------------------------------------
Compaq Presario desktop
Windows XP Professional SP1
.NET Framework SP2

------------------
Build description:
------------------
libmysqld.dll was built using Microsoft Visual C++ 6.0 SP5 and Microsoft
Visual C++ Processor Pack SP5 (used for ASM files).  We build our own
version because we need to make a change so that the DLL will work with
C# clients (see below for more info).

--------------------
Problem description:
--------------------
A C# client was built using Microsoft Visual Studio.NET.  The client
calls mysql_server_init(), passing in the command-line argument
"--datadir=<path>", then attempts to open a connection using
mysql_init() and mysql_real_connect().  A database that is known to
exist is passed in to the mysql_real_connect() function.  The function
call fails and mysql_error() returns "Unknown database '<name>'."

Behavior is identical using debug and release builds of libmysqld.dll.

The problem does not occur using a C++ client.

---------------
Possible cause:
---------------
Stepping into MySQL, I find that the variable "mysql_data_home" is set
to the correct value when mysql_server_init() returns.  However, when
mysql_init() is entered, the value has become corrupted.

--------
C# code:
--------

/**************************************************************/
/* you will need to customize the datadir and database name   */
/**************************************************************/

using System;
using System.Security;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
  class Test
  {
    [STAThread]
    static void Main(string[] args)
    {
      TestDirectToDLL();
    }

    private static void TestDirectToDLL()
    {
      string[] args = new string[] {"thisappname",
"--datadir=c:/iter/source/ADCData"};
      MySqlAPI.ServerInit(args.Length, args, null);
      IntPtr cnn = MySqlAPI.Init(IntPtr.Zero);
      IntPtr result = MySqlAPI.Connect(cnn, null, null, null,
"iteration", 0, null, 0);
      if (result == IntPtr.Zero)
        throw new Exception(MySqlAPI.Error(cnn));
      MySqlAPI.Close(cnn);
      MySqlAPI.ServerEnd();
    }
  }

  class MySqlAPI
  {
    [SuppressUnmanagedCodeSecurity]
    [DllImport("libmysqld.dll",
       CharSet=System.Runtime.InteropServices.CharSet.Ansi,
       EntryPoint="mysql_server_init", ExactSpelling=true)]
    public static extern int ServerInit(int icArgs, string [] strArgs,
string [] strGroups);

    [DllImport("libmysqld.dll",
       EntryPoint="mysql_server_end", ExactSpelling=true)]
    public static extern void ServerEnd();

    [SuppressUnmanagedCodeSecurity]
    [DllImport("libmysqld.dll", EntryPoint="mysql_init",
ExactSpelling=true)]
    public static extern IntPtr Init(IntPtr ihConnection);

    [SuppressUnmanagedCodeSecurity]
    [DllImport("libmysqld.dll",
       CharSet=System.Runtime.InteropServices.CharSet.Ansi,
       EntryPoint="mysql_real_connect", ExactSpelling=true)]
    public static extern IntPtr Connect(IntPtr ihConnection,
      [In] string strHost, [In] string strUser, [In] string strPassword,
      [In] string strDatabaseName,
      uint iPort, [In] string strSocketName, uint iFlags
      );

    [SuppressUnmanagedCodeSecurity]
    [DllImport("libmysqld.dll", EntryPoint="mysql_close",
ExactSpelling=true)]
    public static extern void Close(IntPtr ihConnection);

    [DllImport("libmysqld.dll",
       EntryPoint="mysql_errno", ExactSpelling=true)]
    public static extern uint ErrNo(IntPtr ihConnection);

    [DllImport("libmysqld.dll",
       CharSet=System.Runtime.InteropServices.CharSet.Ansi,
       EntryPoint="mysql_error", ExactSpelling=true)]
    public static extern string Error(IntPtr ihConnection);
  }
}

---------
C++ code:
---------

/**************************************************************/
/* plug this into the file test_dll.cpp that ships with MySQL */
/**************************************************************/

/**************************************************************/
/* you will need to customize the datadir and database name   */
/**************************************************************/

int main(int argc, char* argv[])
{
  MYSQL *one;

  const char *simulatedArgs[] = {"thisappname",
"--datadir=c:/iter/source/ADCData"};
  const int simulatedArgCount = 2;

  mysql_server_init(simulatedArgCount, (char**)simulatedArgs, NULL);

  one = db_connect("iteration");
  db_do_query(one, "show tables");
  mysql_close(one);

  mysql_server_end();
  return 0;
}

---------------
MySQL binaries:
---------------
Upon request, I can supply our debug and release builds of
libmysqld.dll.

-------------------------------
Source code change description:
-------------------------------
There is only one change we make to the MySQL 4.04b source distribution.
We define USE_TLS for the "mysys" project.  The reason is that it's
required for clients that use LoadLibrary(), which includes all C#
clients.  More information can be found in the VC++ documentation
article "Rules and Limitations for TLS".

-----------------------
My contact information:
-----------------------
Matt Solnit <[EMAIL PROTECTED]>


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to