/* * Copyright (c) 1995, 1996 Gunther Schadow. All rights reserved. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "pg_config.h" IDENT("@(#) odbm-store.cc (Gunther Schadow) 12/19/96"); #include "odbm.h" #include #include #include #include /****************************************************************** * storage methods * */ /* * store key if not yet present */ void odbm::insert() const { update_key(); build_data(); if(gdbm_store(*dbfp, key, data, GDBM_INSERT) != SUCCESS) ERROS("gdbm_store `%s': %s", *keyp, gdbm_strerror(gdbm_errno)); insert_indices(); } /* * store under key found in structure * this does not yet work with indices since these indices become invalid. * One aproach is to find any associated index values and remove them. * However, this is costly since it requires all index entries with the * same value to be checked for the appropriate reference. */ void odbm::update() const { if(!indices.empty()) ERROR("not implemented with indices"); update_key(); build_data(); if(gdbm_store(*dbfp, key, data, GDBM_REPLACE) != SUCCESS) ERROS("gdbm_store `%s': %s", *keyp, gdbm_strerror(gdbm_errno)); } /***************************************************************** * removing methods * * When a record is removed which is referenced by some indices, these * index entries become orphaned but are not removed here. This saves * time. */ /* * remove the supplied key */ void odbm::remove(const char *k) const { datum new_key = build_key(k); if(gdbm_delete(*dbfp, new_key) != SUCCESS) if(gdbm_errno != GDBM_ITEM_NOT_FOUND) ERROS("gdbm_delete `%s': %s", *keyp, gdbm_strerror(gdbm_errno)); } /* * remove the key found in structure */ void odbm::remove() const { update_key(); if(gdbm_delete(*dbfp, key) != SUCCESS) if(gdbm_errno != GDBM_ITEM_NOT_FOUND) ERROS("gdbm_delete: `%s': %s", *keyp, gdbm_strerror(gdbm_errno)); }