drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
json_server/sql_executor.cc
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
*
4
* Copyright (C) 2012 Mohit Srivastava
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
23
24
25
#include <config.h>
26
#include <plugin/json_server/sql_executor.h>
27
#include <drizzled/plugin/listen.h>
28
#include <drizzled/plugin/client.h>
29
#include <drizzled/catalog/local.h>
30
#include <drizzled/execute.h>
31
#include <drizzled/sql/result_set.h>
32
#include <drizzled/errmsg_print.h>
33
#include <drizzled/plugin.h>
34
35
using namespace
std
;
36
using namespace
drizzled
;
37
38
namespace
drizzle_plugin
39
{
40
namespace
json_server
41
{
42
SQLExecutor::SQLExecutor
(
const
string
&schema)
43
:
_in_error_state
(false),
_err
(EE_OK)
44
{
45
/* setup a Session object */
46
_session
= Session::make_shared(
plugin::Listen::getNullClient
(), catalog::local());
47
identifier::user::mptr user_id= identifier::User::make_shared();
48
user_id->setUser(
""
);
49
_session
->setUser(user_id);
50
_session
->set_schema(schema);
51
_sql
=
""
;
52
_result_set
=NULL;
53
}
54
55
bool
SQLExecutor::executeSQL
(
string
&sql)
56
{
57
_sql
=sql;
58
if
(
_result_set
)
59
{
60
delete
(
_result_set
);
61
}
62
_result_set
=
new
sql::ResultSet
(1);
63
Execute
execute(*(
_session
.get()),
true
);
64
/*wraps the SQL to run within a transaction */
65
execute.run(
_sql
, *
_result_set
);
66
67
_exception
=
_result_set
->getException();
68
69
_err
=
_exception
.getErrorCode();
70
71
if
((
_err
!= EE_OK) && (
_err
!= ER_EMPTY_QUERY))
72
{
73
/* avoid recursive errors */
74
if
(
_in_error_state
)
75
{
76
return
true
;
77
}
78
79
return
false
;
80
}
81
82
return
true
;
83
}
84
}
/* namespace json_server*/
85
}
drizzle_plugin::json_server::SQLExecutor::_exception
sql::Exception _exception
Definition
json_server/sql_executor.h:139
drizzle_plugin::json_server::SQLExecutor::_result_set
sql::ResultSet * _result_set
Definition
json_server/sql_executor.h:147
drizzle_plugin::json_server::SQLExecutor::_in_error_state
bool _in_error_state
Definition
json_server/sql_executor.h:135
drizzle_plugin::json_server::SQLExecutor::_session
drizzled::Session::shared_ptr _session
Definition
json_server/sql_executor.h:129
drizzle_plugin::json_server::SQLExecutor::executeSQL
bool executeSQL(string &sql)
Definition
json_server/sql_executor.cc:55
drizzle_plugin::json_server::SQLExecutor::_sql
string _sql
Definition
json_server/sql_executor.h:151
drizzle_plugin::json_server::SQLExecutor::_err
drizzled::error_t _err
Definition
json_server/sql_executor.h:143
drizzle_plugin::json_server::SQLExecutor::SQLExecutor
SQLExecutor(const string &schema)
Definition
json_server/sql_executor.cc:42
drizzled::Execute
Definition
drizzled/execute.h:28
drizzled::plugin::Listen::getNullClient
static plugin::Client * getNullClient()
Definition
listen.cc:184
drizzled::sql::ResultSet
Definition
result_set.h:45
drizzle_plugin::json_server
Definition
db_access.cc:29
drizzle_plugin
Definition
auth_schema.cc:31
drizzled
TODO: Rename this file - func.h is stupid.
Definition
abort_exception.h:27
std
STL namespace.
← Back to Drizzle docs
plugin
json_server
sql_executor.cc
Generated by
1.15.0