Drizzled Public API Documentation

select_export.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 
00021 #pragma once
00022 
00023 #include <drizzled/select_to_file.h>
00024 
00025 /*
00026  List of all possible characters of a numeric value text representation.
00027 */
00028 #define NUMERIC_CHARS ".0123456789e+-"
00029 
00030 namespace drizzled
00031 {
00032 
00033 class select_export :
00034   public select_to_file
00035 {
00036   uint32_t field_term_length;
00037   int field_sep_char,escape_char,line_sep_char;
00038   int field_term_char; // first char of FIELDS TERMINATED BY or MAX_INT
00039   /*
00040     The is_ambiguous_field_sep field is true if a value of the field_sep_char
00041     field is one of the 'n', 't', 'r' etc characters
00042     (see the READ_INFO::unescape method and the ESCAPE_CHARS constant value).
00043   */
00044   bool is_ambiguous_field_sep;
00045   /*
00046      The is_ambiguous_field_term is true if field_sep_char contains the first
00047      char of the FIELDS TERMINATED BY (ENCLOSED BY is empty), and items can
00048      contain this character.
00049   */
00050   bool is_ambiguous_field_term;
00051   /*
00052     The is_unsafe_field_sep field is true if a value of the field_sep_char
00053     field is one of the '0'..'9', '+', '-', '.' and 'e' characters
00054     (see the NUMERIC_CHARS constant value).
00055   */
00056   bool is_unsafe_field_sep;
00057   bool fixed_row_size;
00058 public:
00059   select_export(file_exchange *ex) :
00060     select_to_file(ex),
00061     field_term_length(0),
00062     field_sep_char(0),
00063     escape_char(0),
00064     line_sep_char(0),
00065     field_term_char(0),
00066     is_ambiguous_field_sep(0),
00067     is_ambiguous_field_term(0),
00068     is_unsafe_field_sep(0),
00069     fixed_row_size(0)
00070   {}
00071   ~select_export();
00072   int prepare(List<Item> &list, Select_Lex_Unit *u);
00073   bool send_data(List<Item> &items);
00074 private:
00075   inline bool needs_escaping(char character, bool enclosed)
00076   {
00077     if ((character == escape_char) ||
00078         (enclosed ? character == field_sep_char : character == field_term_char) ||
00079         character == line_sep_char  ||
00080         (character == 0))
00081       return true;
00082 
00083     return false;
00084 
00085   }
00086 };
00087 
00088 } /* namespace drizzled */
00089