summaryrefslogtreecommitdiff
path: root/storage/ndb/src/old_files/client/odbc/common/DataRow.cpp
blob: 509f2673e0d66c455ced4d229ab4ec14a29882cb (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright (C) 2003 MySQL AB

   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; either version 2 of the License, or
   (at your option) any later version.

   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "DataRow.hpp"

// SqlSpecs

SqlSpecs::SqlSpecs(unsigned count) :
    m_count(count)
{
    m_sqlSpec = new SqlSpec[1 + count];
}

SqlSpecs::SqlSpecs(const SqlSpecs& sqlSpecs) :
    m_count(sqlSpecs.m_count)
{
    m_sqlSpec = new SqlSpec[1 + m_count];
    for (unsigned i = 1; i <= m_count; i++) {
	void* place = static_cast<void*>(&m_sqlSpec[i]);
	new (place) SqlSpec(sqlSpecs.m_sqlSpec[i]);
    }
}

SqlSpecs::~SqlSpecs()
{
    delete[] m_sqlSpec;
}

// ExtSpecs

ExtSpecs::ExtSpecs(unsigned count) :
    m_count(count)
{
    m_extSpec = new ExtSpec[1 + count];
}

ExtSpecs::ExtSpecs(const ExtSpecs& extSpecs) :
    m_count(extSpecs.m_count)
{
    m_extSpec = new ExtSpec[1 + m_count];
    for (unsigned i = 1; i <= m_count; i++) {
	void* place = static_cast<void*>(&m_extSpec[i]);
	new (place) ExtSpec(extSpecs.m_extSpec[i]);
    }
}

ExtSpecs::~ExtSpecs()
{
    delete[] m_extSpec;
}

// SqlRow

SqlRow::SqlRow(const SqlSpecs& sqlSpecs) :
    m_sqlSpecs(sqlSpecs)
{
    m_sqlField = new SqlField[1 + count()];
    for (unsigned i = 1; i <= count(); i++) {
	SqlField sqlField(m_sqlSpecs.getEntry(i));
	setEntry(i, sqlField);
    }
}

SqlRow::SqlRow(const SqlRow& sqlRow) :
    m_sqlSpecs(sqlRow.m_sqlSpecs)
{
    m_sqlField = new SqlField[1 + count()];
    for (unsigned i = 1; i <= count(); i++) {
	void* place = static_cast<void*>(&m_sqlField[i]);
	new (place) SqlField(sqlRow.getEntry(i));
    }
}

SqlRow::~SqlRow()
{
    for (unsigned i = 1; i <= count(); i++) {
	m_sqlField[i].~SqlField();
    }
    delete[] m_sqlField;
}

SqlRow*
SqlRow::copy() const
{
    SqlRow* copyRow = new SqlRow(m_sqlSpecs);
    for (unsigned i = 1; i <= count(); i++) {
	const SqlField* sqlField = &m_sqlField[i];
	while (sqlField->sqlSpec().store() == SqlSpec::Reference) {
	    sqlField = sqlField->u_data.m_sqlField;
	}
	copyRow->setEntry(i, *sqlField);
    }
    return copyRow;
}

void
SqlRow::copyout(Ctx& ctx, class ExtRow& extRow) const
{
    for (unsigned i = 1; i <= count(); i++) {
	const SqlField& sqlField = getEntry(i);
	ExtField& extField = extRow.getEntry(i);
	sqlField.copyout(ctx, extField);
    }
}

// ExtRow

ExtRow::ExtRow(const ExtSpecs& extSpecs) :
    m_extSpecs(extSpecs)
{
    m_extField = new ExtField[1 + count()];
}

ExtRow::ExtRow(const ExtRow& extRow) :
    m_extSpecs(extRow.m_extSpecs)
{
    m_extField = new ExtField[1 + count()];
    for (unsigned i = 1; i <= count(); i++) {
	void* place = static_cast<void*>(&m_extField[i]);
	new (place) ExtField(extRow.getEntry(i));
    }
}

ExtRow::~ExtRow()
{
    delete[] m_extField;
}