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 
00029 namespace drizzled
00030 {
00031 
00032 class select_send :public select_result {
00038   bool is_result_set_started;
00039 public:
00040   select_send() :is_result_set_started(false) {}
00041   bool send_eof()
00042   {
00043     /*
00044       We may be passing the control from mysqld to the client: release the
00045       InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
00046       by session
00047     */
00048     plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
00049 
00050     /* Unlock tables before sending packet to gain some speed */
00051     if (session->lock)
00052     {
00053       session->unlockTables(session->lock);
00054       session->lock= 0;
00055     }
00056     session->my_eof();
00057     is_result_set_started= 0;
00058     return false;
00059   }
00060 
00061   bool send_fields(List<Item> &list)
00062   {
00063     bool res;
00064     if (! (res= session->getClient()->sendFields(&list)))
00065       is_result_set_started= 1;
00066     return res;
00067   }
00068 
00069   void abort()
00070   {
00071     return;
00072   }
00073 
00074 
00081   virtual void cleanup()
00082   {
00083     is_result_set_started= false;
00084   }
00085 
00086   /* Send data to client. Returns 0 if ok */
00087 
00088   bool send_data(List<Item> &items)
00089   {
00090     if (unit->offset_limit_cnt)
00091     {           // using limit offset,count
00092       unit->offset_limit_cnt--;
00093       return false;
00094     }
00095 
00096     /*
00097       We may be passing the control from mysqld to the client: release the
00098       InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
00099       by session
00100     */
00101     plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
00102 
00103     List<Item>::iterator li(items.begin());
00104     char buff[MAX_FIELD_WIDTH];
00105     String buffer(buff, sizeof(buff), &my_charset_bin);
00106 
00107     Item *item;
00108     while ((item=li++))
00109     {
00110       if (item->send(session->getClient(), &buffer))
00111       {
00112         my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
00113         break;
00114       }
00115     }
00116     /* Insert this record to the Resultset into the cache */
00117     if (session->query_cache_key != "" && session->getResultsetMessage() != NULL)
00118       plugin::QueryCache::insertRecord(session, items);
00119 
00120     session->sent_row_count++;
00121     if (session->is_error())
00122       return true;
00123     return session->getClient()->flush();
00124   }
00125 };
00126 
00127 } /* namespace drizzled */
00128