~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 *
 * PrimeBase Media Stream for MySQL
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * Original author: Paul McCullagh
 * Continued development: Barry Leslie
 *
 * 2007-05-25
 *
 * H&G2JCtL
 *
 * MySQL interface.
 *
 */


#ifdef DRIZZLED
#include <config.h>
#include <drizzled/common.h>
#include <drizzled/data_home.h>
#include <drizzled/current_session.h>
#include <drizzled/plugin.h>
#include <drizzled/session.h>
#else
#include "cslib/CSConfig.h"
#endif

#include "cslib/CSGlobal.h"
#include "cslib/CSException.h"
#include "defs_ms.h"
#include "mysql_ms.h"

/* Note: 'new' used here is NOT CSObject::new which is a DEBUG define*/
#ifdef new
#undef new
#endif

void *ms_my_get_thread()
{
	THD *thd = current_thd;

	return (void *) thd;
}

#ifdef DRIZZLED
const char *ms_my_get_mysql_home_path()
{
	return drizzled::getDataHomeCatalog().file_string().c_str();
}

bool ms_is_autocommit()
{
	return (session_test_options(current_thd, (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) == 0;
}

#else
const char *ms_my_get_mysql_home_path()
{
	return mysql_real_data_home;
}

bool ms_is_autocommit()
{
	return (thd_test_options(current_thd, (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) == 0;
}
#endif

/* YYYYMMDDHHMMSS */
uint64_t	ms_my_1970_to_mysql_time(time_t t)
{
	struct tm	details;
	uint64_t		sec;
	uint64_t		min;
	uint64_t		hour;
	uint64_t		day;
	uint64_t		mon;
	uint64_t		year;

	gmtime_r(&t, &details);
	sec = (uint64_t) details.tm_sec;
	min = (uint64_t) details.tm_min * 100LL;
	hour = (uint64_t) details.tm_hour * 10000LL;
	day = (uint64_t) details.tm_mday * 1000000LL;
	mon = (uint64_t) (details.tm_mon+1) * 100000000LL;
	year = (uint64_t) (details.tm_year+1900) * 10000000000LL;
	
	return year + mon + day + hour + min + sec;
}