Drizzled Public API Documentation

hp_open.cc

00001 /* Copyright (C) 2000-2004, 2006 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /* open a heap-database */
00017 
00018 #include "heap_priv.h"
00019 
00020 #include <string.h>
00021 #include <cstdlib>
00022 
00023 using namespace std;
00024 
00025 /*
00026   Open heap table based on HP_SHARE structure
00027 
00028   NOTE
00029     This doesn't register the table in the open table list.
00030 */
00031 
00032 HP_INFO *heap_open_from_share(HP_SHARE *share, int mode)
00033 {
00034   HP_INFO *info= new HP_INFO;
00035 
00036   share->open_count++;
00037   info->setShare(share);
00038   info->lastkey.resize(share->max_key_length);
00039   info->mode= mode;
00040   info->current_record= UINT32_MAX;   /* No current record */
00041   info->lastinx= info->errkey= -1;
00042   return info;
00043 }
00044 
00045 
00046 /*
00047   Open heap table based on HP_SHARE structure and register it
00048 */
00049 
00050 HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode)
00051 {
00052   HP_INFO *info;
00053 
00054   THR_LOCK_heap.lock();
00055   if ((info= heap_open_from_share(share, mode)))
00056   {
00057     heap_open_list.push_front(info);
00058   }
00059   THR_LOCK_heap.unlock();
00060   return(info);
00061 }
00062 
00063 
00064 /*
00065   Open heap table based on name
00066 
00067   NOTE
00068     This register the table in the open table list. so that it can be
00069     found by future heap_open() calls.
00070 */
00071 
00072 HP_INFO *heap_open(const char *name, int mode)
00073 {
00074   HP_INFO *info;
00075   HP_SHARE *share;
00076 
00077   THR_LOCK_heap.lock();
00078   if (!(share= hp_find_named_heap(name)))
00079   {
00080     errno= ENOENT;
00081     THR_LOCK_heap.unlock();
00082     return(0);
00083   }
00084   if ((info= heap_open_from_share(share, mode)))
00085   {
00086     heap_open_list.push_front(info);
00087   }
00088   THR_LOCK_heap.unlock();
00089   return(info);
00090 }
00091 
00092 
00093 /* map name to a heap-nr. If name isn't found return 0 */
00094 
00095 HP_SHARE *hp_find_named_heap(const char *name)
00096 {
00097   list<HP_SHARE *>::iterator it= heap_share_list.begin();
00098   while (it != heap_share_list.end())
00099   {
00100     if (not (*it)->name.compare(name))
00101     {
00102       return (*it);
00103     }
00104     ++it;
00105   }
00106   return((HP_SHARE *) 0);
00107 }
00108 
00109