~drizzle-trunk/drizzle/development

837 by Brian Aker
Reworked some classes out of session.h
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
837 by Brian Aker
Reworked some classes out of session.h
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
21
#ifndef DRIZZLED_SELECT_SEND_H
22
#define DRIZZLED_SELECT_SEND_H
23
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
24
#include <drizzled/plugin/client.h>
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
25
#include <drizzled/plugin/query_cache.h>
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
26
#include <drizzled/plugin/transactional_storage_engine.h>
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
27
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
28
namespace drizzled
29
{
30
837 by Brian Aker
Reworked some classes out of session.h
31
class select_send :public select_result {
32
  /**
33
    True if we have sent result set metadata to the client.
34
    In this case the client always expects us to end the result
35
    set with an eof or error packet
36
  */
37
  bool is_result_set_started;
38
public:
39
  select_send() :is_result_set_started(false) {}
40
  bool send_eof()
41
  {
42
    /*
43
      We may be passing the control from mysqld to the client: release the
44
      InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
45
      by session
46
    */
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
47
    plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
837 by Brian Aker
Reworked some classes out of session.h
48
49
    /* Unlock tables before sending packet to gain some speed */
50
    if (session->lock)
51
    {
1910.2.7 by Brian Aker
Rename lock methods to be style + well make sense.
52
      session->unlockTables(session->lock);
837 by Brian Aker
Reworked some classes out of session.h
53
      session->lock= 0;
54
    }
55
    session->my_eof();
56
    is_result_set_started= 0;
57
    return false;
58
  }
59
971.3.63 by Eric Day
Removed protocol field flags.
60
  bool send_fields(List<Item> &list)
837 by Brian Aker
Reworked some classes out of session.h
61
  {
62
    bool res;
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
63
    if (! (res= session->getClient()->sendFields(&list)))
837 by Brian Aker
Reworked some classes out of session.h
64
      is_result_set_started= 1;
65
    return res;
66
  }
67
68
  void abort()
69
  {
70
    return;
71
  }
72
73
74
  /**
75
    Cleanup an instance of this class for re-use
76
    at next execution of a prepared statement/
77
    stored procedure statement.
78
  */
79
80
  virtual void cleanup()
81
  {
82
    is_result_set_started= false;
83
  }
84
85
  /* Send data to client. Returns 0 if ok */
86
87
  bool send_data(List<Item> &items)
88
  {
89
    if (unit->offset_limit_cnt)
90
    {						// using limit offset,count
91
      unit->offset_limit_cnt--;
92
      return false;
93
    }
94
95
    /*
96
      We may be passing the control from mysqld to the client: release the
97
      InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
98
      by session
99
    */
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
100
    plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
837 by Brian Aker
Reworked some classes out of session.h
101
102
    List_iterator_fast<Item> li(items);
103
    char buff[MAX_FIELD_WIDTH];
104
    String buffer(buff, sizeof(buff), &my_charset_bin);
105
106
    Item *item;
107
    while ((item=li++))
108
    {
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
109
      if (item->send(session->getClient(), &buffer))
837 by Brian Aker
Reworked some classes out of session.h
110
      {
111
        my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
112
        break;
113
      }
114
    }
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
115
    /* Insert this record to the Resultset into the cache */
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
116
    if (session->query_cache_key != "" && session->getResultsetMessage() != NULL)
117
      plugin::QueryCache::insertRecord(session, items);
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
118
837 by Brian Aker
Reworked some classes out of session.h
119
    session->sent_row_count++;
120
    if (session->is_error())
121
      return true;
2015.3.1 by Brian Aker
Encapsulate client call. Also remove the need to call current_session when
122
    return session->getClient()->flush();
837 by Brian Aker
Reworked some classes out of session.h
123
  }
124
};
125
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
126
} /* namespace drizzled */
127
837 by Brian Aker
Reworked some classes out of session.h
128
#endif /* DRIZZLED_SELECT_SEND_H */