~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/select_send.h

Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.

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