Drizzled Public API Documentation

select_dumpvar.cc
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 #include <config.h>
00021 
00022 #include <drizzled/select_dumpvar.h>
00023 #include <drizzled/sql_lex.h>
00024 #include <drizzled/session.h>
00025 
00026 namespace drizzled {
00027 
00028 bool select_dumpvar::send_data(List<Item> &items)
00029 {
00030   std::vector<var *>::const_iterator iter= var_list.begin();
00031 
00032   List<Item>::iterator it(items.begin());
00033   Item *item= NULL;
00034   var *current_var;
00035 
00036   if (unit->offset_limit_cnt)
00037   {           // using limit offset,count
00038     unit->offset_limit_cnt--;
00039     return(0);
00040   }
00041   if (row_count++)
00042   {
00043     my_message(ER_TOO_MANY_ROWS, ER(ER_TOO_MANY_ROWS), MYF(0));
00044     return(1);
00045   }
00046   while ((iter != var_list.end()) && (item= it++))
00047   {
00048     current_var= *iter;
00049     if (current_var->local == 0)
00050     {
00051       Item_func_set_user_var *suv= new Item_func_set_user_var(current_var->s, item);
00052       suv->fix_fields(session, 0);
00053       suv->check(0);
00054       suv->update();
00055     }
00056     ++iter;
00057   }
00058   return(session->is_error());
00059 }
00060 
00061 bool select_dumpvar::send_eof()
00062 {
00063   if (! row_count)
00064     push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
00065      ER_SP_FETCH_NO_DATA, ER(ER_SP_FETCH_NO_DATA));
00066   /*
00067     In order to remember the value of affected rows for ROW_COUNT()
00068     function, SELECT INTO has to have an own SQLCOM.
00069     @TODO split from SQLCOM_SELECT
00070   */
00071   session->my_ok(row_count);
00072   return 0;
00073 }
00074 
00075 int select_dumpvar::prepare(List<Item> &list, Select_Lex_Unit *u)
00076 {
00077   unit= u;
00078 
00079   if (var_list.size() != list.size())
00080   {
00081     my_message(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT,
00082          ER(ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT), MYF(0));
00083     return 1;
00084   }
00085   return 0;
00086 }
00087 
00088 } // namespace drizzled