~drizzle-trunk/drizzle/development

661 by Brian Aker
First major pass through new replication.
1
/* Copyright (C) 2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
16
#define DRIZZLE_SERVER 1 /* for session variable max_allowed_packet */
17
#include <drizzled/server_includes.h>
18
#include <drizzled/session.h>
19
#include <drizzled/error.h>
20
#include <drizzled/item/strfunc.h>
667 by Brian Aker
Partial fix (more of replication flushed out)
21
#include <drizzled/plugin_replicator.h>
22
23
static char anchor[100];
24
25
static bool statement(Session *, const char *query, size_t query_length)
26
{
27
  fprintf(stderr, "STATEMENT: %.*s\n", (uint32_t)query_length, query);
28
29
  return false;
30
}
31
32
static bool session_init(Session *session)
33
{
34
  fprintf(stderr, "Starting Session\n");
35
  session->setReplicationData(anchor);
36
37
  return false;
38
}
39
40
static bool row_insert(Session *session, Table *)
41
{
42
  fprintf(stderr, "INSERT: %.*s\n", (uint32_t)session->query_length, session->query);
43
44
  return false;
45
}
46
47
static bool row_update(Session *session, Table *, 
48
                          const unsigned char *, 
49
                          const unsigned char *)
50
{
51
  fprintf(stderr, "UPDATE: %.*s\n", (uint32_t)session->query_length, session->query);
52
53
  return false;
54
}
55
56
static bool row_delete(Session *session, Table *)
57
{
58
  fprintf(stderr, "DELETE: %.*s\n", (uint32_t)session->query_length, session->query);
59
60
  return false;
61
}
62
63
static bool end_transaction(Session *session, bool autocommit, bool commit)
64
{
65
  if (commit)
66
  {
67
    if (autocommit)
68
      fprintf(stderr, "COMMIT\n");
69
    else
70
      fprintf(stderr, "AUTOCOMMIT\n");
71
  }
72
  else
73
    fprintf(stderr, "ROLLBACK\n");
74
75
  session->setReplicationData(NULL);
76
77
  return false;
78
}
79
80
static int init(void *p)
81
{
82
  replicator_t *repl = (replicator_t *)p;
83
84
  repl->statement= statement;
85
  repl->session_init= session_init;
86
  repl->row_insert= row_insert;
87
  repl->row_delete= row_delete;
88
  repl->row_update= row_update;
89
  repl->end_transaction= end_transaction;
90
91
  return 0;
92
}
661 by Brian Aker
First major pass through new replication.
93
94
mysql_declare_plugin(replicator)
95
{
96
  DRIZZLE_REPLICATOR_PLUGIN,
97
  "replicator",
98
  "0.1",
99
  "Brian Aker",
100
  "Basic replication module",
101
  PLUGIN_LICENSE_GPL,
667 by Brian Aker
Partial fix (more of replication flushed out)
102
  init, /* Plugin Init */
661 by Brian Aker
First major pass through new replication.
103
  NULL, /* Plugin Deinit */
104
  NULL,   /* status variables */
105
  NULL,   /* system variables */
106
  NULL    /* config options */
107
}
108
mysql_declare_plugin_end;