drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
query_rewrite.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Padraig O'Sullivan
5 *
6 * Authors:
7 *
8 * Padraig O'Sullivan <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <config.h>
25#include <drizzled/plugin/query_rewrite.h>
26#include <drizzled/gettext.h>
27
28#include <algorithm>
29#include <vector>
30
31namespace drizzled
32{
33
34namespace plugin
35{
36
37std::vector<plugin::QueryRewriter *> all_rewriters;
38
39
40bool QueryRewriter::addPlugin(QueryRewriter &in_rewriter)
41{
42 all_rewriters.push_back(&in_rewriter);
43 return false;
44}
45
46
47void QueryRewriter::removePlugin(QueryRewriter &in_rewriter)
48{
49 all_rewriters.erase(std::find(all_rewriters.begin(),
50 all_rewriters.end(),
51 &in_rewriter));
52}
53
54
55/*
56 * This is the QueryRewriter::rewrite entry point.
57 * This gets called from within the Drizzle kernel.
58 */
59void QueryRewriter::rewriteQuery(const std::string &schema, std::string &to_rewrite)
60{
61 for (std::vector<plugin::QueryRewriter *>::iterator iter= all_rewriters.begin();
62 iter != all_rewriters.end();
63 ++iter)
64 {
65 (*iter)->rewrite(schema, to_rewrite);
66 }
67}
68
69} /* namespace plugin */
70
71} /* namespace drizzled */
static void rewriteQuery(const std::string &schema, std::string &to_rewrite)
TODO: Rename this file - func.h is stupid.