~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to db/drivers/mysql/dbe.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/**********************************************************
 
3
 * MODULE:    mysql
 
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
 
10
 *            for details.
 
11
 **********************************************************/
 
12
#include <stdlib.h>
 
13
#include <string.h>
 
14
 
 
15
#include <grass/dbmi.h>
 
16
#include <grass/gis.h>
 
17
#include <grass/glocale.h>
 
18
 
 
19
#include "globals.h"
 
20
#include "proto.h"
 
21
 
 
22
int db__driver_open_database(dbHandle * handle)
 
23
{
 
24
    char *name;
 
25
    dbConnection default_connection;
 
26
    MYSQL *res;
 
27
 
 
28
    db_get_connection(&default_connection);
 
29
    name = G_store(db_get_handle_dbname(handle));
 
30
 
 
31
    /* if name is empty use default_connection.databaseName */
 
32
    if (strlen(name) == 0)
 
33
        name = default_connection.databaseName;
 
34
 
 
35
    G_debug(3, "db_driver_open_database() mysql: database definition = '%s'",
 
36
            name);
 
37
 
 
38
    /* Embedded version */
 
39
    {
 
40
        char *datadir, *database;
 
41
        char *server_args[4];
 
42
        char *buf;
 
43
 
 
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));
 
47
            db_d_report_error();
 
48
            return DB_FAILED;
 
49
        }
 
50
 
 
51
        server_args[0] = "mesql";       /* this string is not used */
 
52
        G_asprintf(&buf, "--datadir=%s", datadir);
 
53
        server_args[1] = buf;
 
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? */
 
59
 
 
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));
 
63
            db_d_report_error();
 
64
            free(datadir);
 
65
            free(database);
 
66
            return DB_FAILED;
 
67
        }
 
68
 
 
69
        connection = mysql_init(NULL);
 
70
        mysql_options(connection, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
 
71
 
 
72
        res =
 
73
            mysql_real_connect(connection, NULL, NULL, NULL, database, 0,
 
74
                               NULL, 0);
 
75
 
 
76
        free(datadir);
 
77
        free(database);
 
78
 
 
79
        if (res == NULL) {
 
80
            db_d_append_error(_("Unable to connect to MySQL embedded server: "));
 
81
            db_d_append_error(mysql_error(connection));
 
82
            db_d_report_error();
 
83
            return DB_FAILED;
 
84
        }
 
85
    }
 
86
 
 
87
    return DB_OK;
 
88
}
 
89
 
 
90
int db__driver_close_database(void)
 
91
{
 
92
    mysql_close(connection);    /* this will also release connection */
 
93
 
 
94
    mysql_server_end();
 
95
 
 
96
    return DB_OK;
 
97
}