Hi Frederick and Oliver,
If you downloaded embedded.zip to test the embedded mysql server, you might
want to add the following modified code to the test_dll.cpp file. Originally
the programme had to be run with the following parameters for main():
test.exe c++ -datadir:c:\mysql\data <--or whatever directory your "data"
directory (that contains the mysql,test,paro and other databases you create
with mysql) is in.
I added some code that passes where this data directory is and other
arguments in form of the array "arg" to mysql_server_init(). But this code
is based on the *WORKING DIRECTORY* (getcwd() function) instead of the
directory where test.exe lies (windows API GetModuleFileName() function ).
It is better to part from the directory where test.exe resides instead of
the working directory, to define where the data directory is located... I
use now the windows API GetModuleFileName() function instead of getcwd()
function. You might one to replace this code too...
Attached to this email is the newest test_dll.cpp file, and below the new
code that passes the directory where "data" resides to the
mysql_server_init() function.
Regards,
Josep
P.S. >Per, maybe you want to take alook at this code and produce a more
elegant version ;-)
#include <windows.h> //win32 API: see GetModuleFileName()
int main(int argc, char* argv[])
{
//CODE ADDED BY JOSEP TO AVOID HAVING TO PASS PARAMETERS TO main(). 9-3-04
// builds something like --datadir=E:\dev-c++_projects\myproject\data
//it's presupossed that the mysql "data" directory will be always located
in the same directory as the .exe executable
long size = 2000L;
char flag[size];
char *buf;
strcpy(flag,"--datadir=");
GetModuleFileName(NULL, buf, size);
char *basename;
basename = strrchr(buf, '\\') + 1; //last ocurrence of '\' --> name of
the exe file (=basename)
strncat(flag, buf, strlen(buf)-strlen(basename));
if (strlen(flag) < size-4) //check for too small buffer.
strcat(flag,"data");
int argn = 3;
char *arg[] = {
argv[0], "c++", flag //argv[0] is the name of the executable and on
ocassions also the path.
};
//--- END OF ADDED CODE ---
MYSQL *one, *two;
mysql_server_init(argn, arg, (char **)server_groups);
|