~drizzle-trunk/drizzle/development

1848.5.1 by Vijay Samuel
Merge pushed classes of drizzleslap out into separate classes.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Vijay Samuel
1848.5.2 by Vijay Samuel
Merge corrections to licensing information.
5
 *  Copyright (C) 2008 MySQL
1848.5.1 by Vijay Samuel
Merge pushed classes of drizzleslap out into separate classes.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
21
2371.1.1 by Brian Aker
Fedora fix/use fwd header for iostream.
22
#pragma once
1848.5.4 by Vijay Samuel
Merge added #ifndef tags
23
1848.5.1 by Vijay Samuel
Merge pushed classes of drizzleslap out into separate classes.
24
#include "client_priv.h"
25
#include <string>
2371.1.1 by Brian Aker
Fedora fix/use fwd header for iostream.
26
#include <iosfwd>
1848.5.1 by Vijay Samuel
Merge pushed classes of drizzleslap out into separate classes.
27
#include <cstdlib>
28
29
30
/* Types */
31
enum slap_query_t {
32
  SELECT_TYPE= 0,
33
  UPDATE_TYPE= 1,
34
  INSERT_TYPE= 2,
35
  UPDATE_TYPE_REQUIRES_PREFIX= 3,
36
  CREATE_TABLE_TYPE= 4,
37
  SELECT_TYPE_REQUIRES_PREFIX= 5,
38
  DELETE_TYPE_REQUIRES_PREFIX= 6
39
};
40
41
42
class Statement 
43
{
44
public:
45
  Statement(char *in_string,
46
            size_t in_length,
47
            slap_query_t in_type,
48
            Statement *in_next) :
49
    string(in_string),
50
    length(in_length),
51
    type(in_type),
52
    next(in_next)
53
  { }
54
55
  Statement() :
56
    string(NULL),
57
    length(0),
58
    type(),
59
    next(NULL)
60
  { }
61
62
  ~Statement()
63
  {
2353.3.1 by Mark Atwood
fix cppcheck redundantIfDelete0 warnings. It is safe to deallocate a NULL pointer
64
    free(string);
1848.5.1 by Vijay Samuel
Merge pushed classes of drizzleslap out into separate classes.
65
  }
66
   
67
  char *getString() const
68
  {
69
    return string;
70
  }
71
72
  size_t getLength() const
73
  {
74
    return length;
75
  }
76
77
  slap_query_t getType() const
78
  {
79
    return type;
80
  }
81
82
  Statement *getNext() const
83
  {
84
    return next;
85
  }
86
87
  void setString(char *in_string)
88
  {
89
    string= in_string;
90
  }
91
92
  void setString(size_t length_arg)
93
  {
94
    string= (char *)calloc(length_arg + 1, sizeof(char));
95
    length= length_arg;
96
  }
97
98
  void setString(size_t in_length, char in_char)
99
  {
100
    string[in_length]= in_char;
101
  }
102
103
  void setLength(size_t in_length)
104
  {
105
    length= in_length;
106
  }
107
108
  void setType(slap_query_t in_type)
109
  {
110
    type= in_type;
111
  }
112
113
  void setNext(Statement *in_next)
114
  {
115
    next= in_next;
116
  }
117
118
private:
119
  char *string;
120
  size_t length;
121
  slap_query_t type;
122
  Statement *next;
123
};