2
/**********************************************************
4
* AUTHOR(S): Radim Blazek (radim.blazek@gmail.com)
5
* PURPOSE: MySQL database driver
6
* COPYRIGHT: (C) 2001 by the GRASS Development Team
7
* This program is free software under the
8
* GNU General Public License (>=v2).
9
* Read the file COPYING that comes with GRASS
11
**********************************************************/
15
#include <grass/dbmi.h>
16
#include <grass/gis.h>
17
#include <grass/glocale.h>
22
int db__driver_open_database(dbHandle * handle)
25
dbConnection default_connection;
28
db_get_connection(&default_connection);
29
name = G_store(db_get_handle_dbname(handle));
31
/* if name is empty use default_connection.databaseName */
32
if (strlen(name) == 0)
33
name = default_connection.databaseName;
35
G_debug(3, "db_driver_open_database() mysql: database definition = '%s'",
38
/* Embedded version */
40
char *datadir, *database;
44
if (!replace_variables(name, &datadir, &database)) {
45
db_d_append_error(_("Unable parse MySQL embedded database name"));
46
db_d_append_error(mysql_error(connection));
51
server_args[0] = "mesql"; /* this string is not used */
52
G_asprintf(&buf, "--datadir=%s", datadir);
54
/* With InnoDB it is very slow to close the database */
55
server_args[2] = "--skip-innodb"; /* OK? */
56
/* Without --bootstrap it complains about missing
57
* mysql.time_zone_leap_second table */
58
server_args[3] = "--bootstrap"; /* OK? */
60
if (mysql_server_init(4, server_args, NULL)) {
61
db_d_append_error(_("Cannot initialize MySQL embedded server"));
62
db_d_append_error(mysql_error(connection));
69
connection = mysql_init(NULL);
70
mysql_options(connection, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
73
mysql_real_connect(connection, NULL, NULL, NULL, database, 0,
80
db_d_append_error(_("Unable to connect to MySQL embedded server: "));
81
db_d_append_error(mysql_error(connection));
90
int db__driver_close_database(void)
92
mysql_close(connection); /* this will also release connection */