drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
hp_open.cc
1/* Copyright (C) 2000-2004, 2006 MySQL AB
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16/* open a heap-database */
17
18#include "heap_priv.h"
19
20#include <string.h>
21#include <cstdlib>
22
23using namespace std;
24
25/*
26 Open heap table based on HP_SHARE structure
27
28 NOTE
29 This doesn't register the table in the open table list.
30*/
31
32HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
33{
34 HP_INFO *info= new HP_INFO;
35
36 share->open_count++;
37 info->setShare(share);
38 info->lastkey.resize(share->max_key_length);
39 info->mode= mode;
40 info->current_record= UINT32_MAX; /* No current record */
41 info->lastinx= info->errkey= -1;
42 return info;
43}
44
45
46/*
47 Open heap table based on HP_SHARE structure and register it
48*/
49
50HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
51{
52 HP_INFO *info;
53
54 THR_LOCK_heap.lock();
55 if ((info= heap_open_from_share(share, mode)))
56 {
57 heap_open_list.push_front(info);
58 }
59 THR_LOCK_heap.unlock();
60 return(info);
61}
62
63
64/*
65 Open heap table based on name
66
67 NOTE
68 This register the table in the open table list. so that it can be
69 found by future heap_open() calls.
70*/
71
72HP_INFO *heap_open(const char *name, int mode)
73{
74 HP_INFO *info;
75 HP_SHARE *share;
76
77 THR_LOCK_heap.lock();
78 if (!(share= hp_find_named_heap(name)))
79 {
80 errno= ENOENT;
81 THR_LOCK_heap.unlock();
82 return(0);
83 }
84 if ((info= heap_open_from_share(share, mode)))
85 {
86 heap_open_list.push_front(info);
87 }
88 THR_LOCK_heap.unlock();
89 return(info);
90}
91
92
93/* map name to a heap-nr. If name isn't found return 0 */
94
95HP_SHARE *hp_find_named_heap(const char *name)
96{
97 list<HP_SHARE *>::iterator it= heap_share_list.begin();
98 while (it != heap_share_list.end())
99 {
100 if (not (*it)->name.compare(name))
101 {
102 return (*it);
103 }
104 ++it;
105 }
106 return((HP_SHARE *) 0);
107}
108
109
STL namespace.