~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/select_send.h

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

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