Drizzled Public API Documentation

select_send.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/plugin/client.h>
00024 #include <drizzled/plugin/query_cache.h>
00025 #include <drizzled/plugin/transactional_storage_engine.h>
00026 #include <drizzled/select_result.h>
00027 #include <drizzled/sql_lex.h>
00028 #include <drizzled/open_tables_state.h>
00029 
00030 namespace drizzled {
00031 
00032 class select_send : public select_result 
00033 {
00034 public:
00035   bool send_eof()
00036   {
00037     /*
00038       We may be passing the control from mysqld to the client: release the
00039       InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
00040       by session
00041     */
00042     plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
00043 
00044     /* Unlock tables before sending packet to gain some speed */
00045     if (session->open_tables.lock)
00046     {
00047       session->unlockTables(session->open_tables.lock);
00048       session->open_tables.lock= 0;
00049     }
00050     session->my_eof();
00051     return false;
00052   }
00053 
00054   void send_fields(List<Item>& list)
00055   {
00056     session->getClient()->sendFields(list);
00057   }
00058 
00059   /* Send data to client. Returns 0 if ok */
00060 
00061   bool send_data(List<Item>& items)
00062   {
00063     if (unit->offset_limit_cnt)
00064     {           // using limit offset,count
00065       unit->offset_limit_cnt--;
00066       return false;
00067     }
00068 
00069     /*
00070       We may be passing the control from mysqld to the client: release the
00071       InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
00072       by session
00073     */
00074     plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
00075 
00076     List<Item>::iterator li(items.begin());
00077     char buff[MAX_FIELD_WIDTH];
00078     String buffer(buff, sizeof(buff), &my_charset_bin);
00079 
00080     while (Item* item= li++)
00081     {
00082       item->send(session->getClient(), &buffer);
00083     }
00084     /* Insert this record to the Resultset into the cache */
00085     /*
00086     if (session->query_cache_key != "" && session->getResultsetMessage() != NULL)
00087       plugin::QueryCache::insertRecord(session, items);
00088     */
00089 
00090     session->sent_row_count++;
00091     if (session->is_error())
00092       return true;
00093     return session->getClient()->flush();
00094   }
00095 };
00096 
00097 } /* namespace drizzled */
00098