Drizzled Public API Documentation

statement.h

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Vijay Samuel
00005  *  Copyright (C) 2008 MySQL
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef CLIENT_STATEMENT_H
00023 #define CLIENT_STATEMENT_H
00024 
00025 #include "client_priv.h"
00026 #include <string>
00027 #include <iostream>
00028 #include <cstdlib>
00029 
00030 
00031 /* Types */
00032 enum slap_query_t {
00033   SELECT_TYPE= 0,
00034   UPDATE_TYPE= 1,
00035   INSERT_TYPE= 2,
00036   UPDATE_TYPE_REQUIRES_PREFIX= 3,
00037   CREATE_TABLE_TYPE= 4,
00038   SELECT_TYPE_REQUIRES_PREFIX= 5,
00039   DELETE_TYPE_REQUIRES_PREFIX= 6
00040 };
00041 
00042 
00043 class Statement 
00044 {
00045 public:
00046   Statement(char *in_string,
00047             size_t in_length,
00048             slap_query_t in_type,
00049             Statement *in_next) :
00050     string(in_string),
00051     length(in_length),
00052     type(in_type),
00053     next(in_next)
00054   { }
00055 
00056   Statement() :
00057     string(NULL),
00058     length(0),
00059     type(),
00060     next(NULL)
00061   { }
00062 
00063   ~Statement()
00064   {
00065     if (string)
00066       free(string);
00067   }
00068    
00069   char *getString() const
00070   {
00071     return string;
00072   }
00073 
00074   size_t getLength() const
00075   {
00076     return length;
00077   }
00078 
00079   slap_query_t getType() const
00080   {
00081     return type;
00082   }
00083 
00084   Statement *getNext() const
00085   {
00086     return next;
00087   }
00088 
00089   void setString(char *in_string)
00090   {
00091     string= in_string;
00092   }
00093 
00094   void setString(size_t length_arg)
00095   {
00096     string= (char *)calloc(length_arg + 1, sizeof(char));
00097     length= length_arg;
00098   }
00099 
00100   void setString(size_t in_length, char in_char)
00101   {
00102     string[in_length]= in_char;
00103   }
00104 
00105   void setLength(size_t in_length)
00106   {
00107     length= in_length;
00108   }
00109 
00110   void setType(slap_query_t in_type)
00111   {
00112     type= in_type;
00113   }
00114 
00115   void setNext(Statement *in_next)
00116   {
00117     next= in_next;
00118   }
00119 
00120 private:
00121   char *string;
00122   size_t length;
00123   slap_query_t type;
00124   Statement *next;
00125 };
00126 
00127 #endif /* CLIENT_STATEMENT_H */