summaryrefslogtreecommitdiff
path: root/storage/ndb/src/old_files/client/odbc/handles/HandleEnv.cpp
blob: bc9d8b420a6659795d69a5f26258d9e9e3b00b03 (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
141
142
143
144
/* 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 <common/DiagArea.hpp>
#include "HandleRoot.hpp"
#include "HandleEnv.hpp"
#include "HandleDbc.hpp"

HandleEnv::HandleEnv(HandleRoot* pRoot) :
    m_root(pRoot),
    m_attrArea(m_attrSpec)
{
    m_attrArea.setHandle(this);
}

HandleEnv::~HandleEnv() {
}

void
HandleEnv::ctor(Ctx& ctx)
{
}

void
HandleEnv::dtor(Ctx& ctx)
{
    if (! m_listDbc.empty()) {
	ctx.pushStatus(Sqlstate::_HY010, Error::Gen, "cannot delete environment handle - has %u associated connection handles", (unsigned)m_listDbc.size());
	return;
    }
}

// allocate and free handles

void
HandleEnv::sqlAllocConnect(Ctx& ctx, HandleDbc** ppDbc)
{
    if (getOdbcVersion(ctx) == -1)
	return;
    if (ppDbc == 0) {
	ctx.pushStatus(Sqlstate::_HY009, Error::Gen, "cannot allocate connection handle - null return address");
	return;
    }
    HandleDbc* pDbc = new HandleDbc(this);
    pDbc->ctor(ctx);
    if (! ctx.ok()) {
	pDbc->dtor(ctx);
	delete pDbc;
	return;
    }
    m_listDbc.push_back(pDbc);
    getRoot()->record(SQL_HANDLE_DBC, pDbc, true);
    *ppDbc = pDbc;
}

void
HandleEnv::sqlAllocHandle(Ctx& ctx, SQLSMALLINT childType, HandleBase** ppChild)
{
    if (getOdbcVersion(ctx) == -1)
	return;
    switch (childType) {
    case SQL_HANDLE_DBC:
	sqlAllocConnect(ctx, (HandleDbc**)ppChild);
	return;
    }
    ctx.pushStatus(Sqlstate::_HY092, Error::Gen, "invalid child handle type %d", (int)childType);
}

void
HandleEnv::sqlFreeConnect(Ctx& ctx, HandleDbc* pDbc)
{
    if (getOdbcVersion(ctx) == -1)
	return;
    pDbc->dtor(ctx);
    if (! ctx.ok())
	return;
    m_listDbc.remove(pDbc);
    getRoot()->record(SQL_HANDLE_DBC, pDbc, false);
    delete pDbc;
}

void
HandleEnv::sqlFreeHandle(Ctx& ctx, SQLSMALLINT childType, HandleBase* pChild)
{
    if (getOdbcVersion(ctx) == -1)
	return;
    switch (childType) {
    case SQL_HANDLE_DBC:
	sqlFreeConnect(ctx, (HandleDbc*)pChild);
	return;
    }
    ctx.pushStatus(Sqlstate::_HY092, Error::Gen, "invalid child handle type %d", (int)childType);
}

// attributes

void
HandleEnv::sqlSetEnvAttr(Ctx& ctx, SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER stringLength)
{
    baseSetHandleAttr(ctx, m_attrArea, attribute, value, stringLength);
}

void
HandleEnv::sqlGetEnvAttr(Ctx& ctx, SQLINTEGER attribute, SQLPOINTER value, SQLINTEGER bufferLength, SQLINTEGER* stringLength)
{
    baseGetHandleAttr(ctx, m_attrArea, attribute, value, bufferLength, stringLength);
}

int
HandleEnv::getOdbcVersion(Ctx& ctx)
{
    OdbcData data;
    m_attrArea.getAttr(ctx, SQL_ATTR_ODBC_VERSION, data);
    if (! ctx.ok())
	return -1;
    return data.integer();
}

// transactions

void
HandleEnv::sqlEndTran(Ctx& ctx, SQLSMALLINT completionType)
{
    ctx_assert(false);	// XXX
}

void
HandleEnv::sqlTransact(Ctx& ctx, SQLUSMALLINT completionType)
{
    ctx_assert(false);	// XXX
}