-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathreturnedrows.cpp
More file actions
112 lines (87 loc) · 2.59 KB
/
returnedrows.cpp
File metadata and controls
112 lines (87 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Copyright (C) 2013 Calpont Corp.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#include <unistd.h>
#include <iostream>
#include <string>
#include <cerrno>
using namespace std;
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
using namespace boost;
#ifndef _MSC_VER
#include "config.h"
#endif
#include "socktype.h"
#include "exceptclasses.h"
#include "socketio.h"
#include "bytestream.h"
#include "messagequeue.h"
using namespace messageqcpp;
#include "rowgroup.h"
using namespace rowgroup;
namespace qfe
{
void processReturnedRows(MessageQueueClient* mqc, SockType fd)
{
scoped_ptr<MessageQueueClient> cleaner(mqc);
SBS sbs;
sbs = mqc->read();
//cerr << "got a bs of " << sbs->length() << " bytes" << endl;
RowGroup rg;
rg.deserialize(*sbs);
//cerr << "got a base rowgroup with rows of " << rg.getRowSize() << " bytes" << endl;
//cerr << rg.toString() << endl;
ByteStream bs;
ByteStream::quadbyte tableOID=100;
bs.reset();
bs << tableOID;
mqc->write(bs);
sbs = mqc->read();
//cerr << "got a bs of " << sbs->length() << " bytes" << endl;
RGData rgd;
rgd.deserialize(*sbs, true);
rg.setData(&rgd);
//cerr << "got a rowgroup with: " << rg.getRowCount() << " rows" << endl;
socketio::writeString(fd, "OK");
Row r;
while (rg.getRowCount() > 0)
{
rg.initRow(&r);
rg.getRow(0, &r);
string csv;
bs.reset();
for (unsigned i = 0; i < rg.getRowCount(); i++)
{
csv = r.toCSV();
bs << csv;
r.nextRow();
}
//cerr << "writing " << bs.length() << " bytes back to client" << endl;
SockWriteFcn(fd, bs.buf(), bs.length());
bs.reset();
bs << tableOID;
mqc->write(bs);
sbs = mqc->read();
//cerr << "got a bs of " << sbs->length() << " bytes" << endl;
rgd.deserialize(*sbs, true);
rg.setData(&rgd);
//cerr << "got a rowgroup with: " << rg.getRowCount() << " rows" << endl;
}
tableOID=0;
bs.reset();
bs << tableOID;
mqc->write(bs);
//sync with the client on end-of-results
SockWriteFcn(fd, &tableOID, 4);
SockReadFcn(fd, &tableOID, 4);
}
}