~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
 *
4
 *  Copyright (C) 2008 Sun Microsystems
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>
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
25
#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.
26
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
27
namespace drizzled
28
{
29
837 by Brian Aker
Reworked some classes out of session.h
30
class select_send :public select_result {
31
  /**
32
    True if we have sent result set metadata to the client.
33
    In this case the client always expects us to end the result
34
    set with an eof or error packet
35
  */
36
  bool is_result_set_started;
37
public:
38
  select_send() :is_result_set_started(false) {}
39
  bool send_eof()
40
  {
41
    /*
42
      We may be passing the control from mysqld to the client: release the
43
      InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
44
      by session
45
    */
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
46
    plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
837 by Brian Aker
Reworked some classes out of session.h
47
48
    /* Unlock tables before sending packet to gain some speed */
49
    if (session->lock)
50
    {
51
      mysql_unlock_tables(session, session->lock);
52
      session->lock= 0;
53
    }
54
    session->my_eof();
55
    is_result_set_started= 0;
56
    return false;
57
  }
58
971.3.63 by Eric Day
Removed protocol field flags.
59
  bool send_fields(List<Item> &list)
837 by Brian Aker
Reworked some classes out of session.h
60
  {
61
    bool res;
971.6.4 by Eric Day
Merged cleanup from my merge branch.
62
    if (! (res= session->client->sendFields(&list)))
837 by Brian Aker
Reworked some classes out of session.h
63
      is_result_set_started= 1;
64
    return res;
65
  }
66
67
  void abort()
68
  {
69
    return;
70
  }
71
72
73
  /**
74
    Cleanup an instance of this class for re-use
75
    at next execution of a prepared statement/
76
    stored procedure statement.
77
  */
78
79
  virtual void cleanup()
80
  {
81
    is_result_set_started= false;
82
  }
83
84
  /* Send data to client. Returns 0 if ok */
85
86
  bool send_data(List<Item> &items)
87
  {
88
    if (unit->offset_limit_cnt)
89
    {						// using limit offset,count
90
      unit->offset_limit_cnt--;
91
      return false;
92
    }
93
94
    /*
95
      We may be passing the control from mysqld to the client: release the
96
      InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
97
      by session
98
    */
1273.1.15 by Jay Pipes
This patch completes the first step in the splitting of
99
    plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
837 by Brian Aker
Reworked some classes out of session.h
100
101
    List_iterator_fast<Item> li(items);
102
    char buff[MAX_FIELD_WIDTH];
103
    String buffer(buff, sizeof(buff), &my_charset_bin);
104
105
    Item *item;
106
    while ((item=li++))
107
    {
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
108
      if (item->send(session->client, &buffer))
837 by Brian Aker
Reworked some classes out of session.h
109
      {
110
        my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
111
        break;
112
      }
113
    }
114
    session->sent_row_count++;
115
    if (session->is_error())
116
      return true;
971.6.1 by Eric Day
Renamed Protocol to Client, cleaned up some unnecessary methods along the way.
117
    return session->client->flush();
837 by Brian Aker
Reworked some classes out of session.h
118
  }
119
};
120
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
121
} /* namespace drizzled */
122
837 by Brian Aker
Reworked some classes out of session.h
123
#endif /* DRIZZLED_SELECT_SEND_H */