~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/select_send.h

Merged in latest plugin-slot-reorg.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
24
#include <drizzled/plugin/client.h>
 
25
 
 
26
class select_send :public select_result {
 
27
  /**
 
28
    True if we have sent result set metadata to the client.
 
29
    In this case the client always expects us to end the result
 
30
    set with an eof or error packet
 
31
  */
 
32
  bool is_result_set_started;
 
33
public:
 
34
  select_send() :is_result_set_started(false) {}
 
35
  bool send_eof()
 
36
  {
 
37
    /*
 
38
      We may be passing the control from mysqld to the client: release the
 
39
      InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
 
40
      by session
 
41
    */
 
42
    ha_release_temporary_latches(session);
 
43
 
 
44
    /* Unlock tables before sending packet to gain some speed */
 
45
    if (session->lock)
 
46
    {
 
47
      mysql_unlock_tables(session, session->lock);
 
48
      session->lock= 0;
 
49
    }
 
50
    session->my_eof();
 
51
    is_result_set_started= 0;
 
52
    return false;
 
53
  }
 
54
 
 
55
  bool send_fields(List<Item> &list)
 
56
  {
 
57
    bool res;
 
58
    if (! (res= session->client->sendFields(&list)))
 
59
      is_result_set_started= 1;
 
60
    return res;
 
61
  }
 
62
 
 
63
  void abort()
 
64
  {
 
65
    return;
 
66
  }
 
67
 
 
68
 
 
69
  /**
 
70
    Cleanup an instance of this class for re-use
 
71
    at next execution of a prepared statement/
 
72
    stored procedure statement.
 
73
  */
 
74
 
 
75
  virtual void cleanup()
 
76
  {
 
77
    is_result_set_started= false;
 
78
  }
 
79
 
 
80
  /* Send data to client. Returns 0 if ok */
 
81
 
 
82
  bool send_data(List<Item> &items)
 
83
  {
 
84
    if (unit->offset_limit_cnt)
 
85
    {                                           // using limit offset,count
 
86
      unit->offset_limit_cnt--;
 
87
      return false;
 
88
    }
 
89
 
 
90
    /*
 
91
      We may be passing the control from mysqld to the client: release the
 
92
      InnoDB adaptive hash S-latch to avoid thread deadlocks if it was reserved
 
93
      by session
 
94
    */
 
95
    ha_release_temporary_latches(session);
 
96
 
 
97
    List_iterator_fast<Item> li(items);
 
98
    char buff[MAX_FIELD_WIDTH];
 
99
    String buffer(buff, sizeof(buff), &my_charset_bin);
 
100
 
 
101
    Item *item;
 
102
    while ((item=li++))
 
103
    {
 
104
      if (item->send(session->client, &buffer))
 
105
      {
 
106
        my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
 
107
        break;
 
108
      }
 
109
    }
 
110
    session->sent_row_count++;
 
111
    if (session->is_error())
 
112
      return true;
 
113
    return session->client->flush();
 
114
  }
 
115
};
 
116
 
 
117
#endif /* DRIZZLED_SELECT_SEND_H */