Drizzled Public API Documentation

table_ident.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/lex_string.h>
00024 #include <drizzled/memory/sql_alloc.h>
00025 #include <drizzled/util/test.h>
00026 
00027 namespace drizzled
00028 {
00029 
00030 extern char empty_c_string[1];
00031 extern char internal_table_name[2];
00032 
00033 /* Structure for db & table in sql_yacc */
00034 class Table_ident :public memory::SqlAlloc
00035 {
00036 public:
00037   LEX_STRING db;
00038   LEX_STRING table;
00039   Select_Lex_Unit *sel;
00040   inline Table_ident(LEX_STRING db_arg, LEX_STRING table_arg)
00041     :table(table_arg), sel((Select_Lex_Unit *)0)
00042   {
00043     db= db_arg;
00044   }
00045   explicit Table_ident(LEX_STRING table_arg)
00046     :table(table_arg), sel((Select_Lex_Unit *)0)
00047   {
00048     db.str=0;
00049   }
00050   /*
00051     This constructor is used only for the case when we create a derived
00052     table. A derived table has no name and doesn't belong to any database.
00053     Later, if there was an alias specified for the table, it will be set
00054     by add_table_to_list.
00055   */
00056   explicit Table_ident(Select_Lex_Unit *s) : sel(s)
00057   {
00058     /* We must have a table name here as this is used with add_table_to_list */
00059     db.str= empty_c_string;                    /* a subject to casedn_str */
00060     db.length= 0;
00061     table.str= internal_table_name;
00062     table.length=1;
00063   }
00064   bool is_derived_table() const { return test(sel); }
00065   inline void change_db(char *db_name)
00066   {
00067     db.str= db_name; db.length= (uint32_t) strlen(db_name);
00068   }
00069 };
00070 
00071 } /* namespace drizzled */
00072