isdel1key.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $XConsortium: isdel1key.c /main/3 1995/10/23 11:37:24 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isdel1key.c
  33. *
  34. * Description:
  35. * Delete a key entry from index
  36. *
  37. *
  38. */
  39. #include "isam_impl.h"
  40. void
  41. _del1key(Fcb *fcb, Keydesc2 *pkeydesc2, char *record, Recno recnum)
  42. {
  43. char keybuf[MAXKEYSIZE];
  44. Btree *btree;
  45. char *pkey;
  46. /*
  47. * Special case when there is no primary key.
  48. */
  49. if (pkeydesc2->k2_nparts == 0)
  50. return;
  51. memset((char *)keybuf, 0,pkeydesc2->k2_len);
  52. _iskey_extract(pkeydesc2,record,keybuf);
  53. strecno(recnum, keybuf);
  54. btree = _isbtree_create(fcb, pkeydesc2);
  55. _isbtree_search(btree, keybuf);
  56. if (ALLOWS_DUPS2(pkeydesc2)) {
  57. /*
  58. * We must now scan all the duplicates till we found one with
  59. * matching recno. We are positioned just before the first duplicate.
  60. * Remember that the duplicates are ordered by their serial number.
  61. *
  62. * If too many duplicate entries exists, the performance will be
  63. * poor.
  64. */
  65. while ((pkey = _isbtree_next(btree)) != NULL) {
  66. if (ldrecno(pkey + KEY_RECNO_OFF) == recnum)
  67. break; /* We found the entry */
  68. }
  69. if (pkey == NULL)
  70. _isfatal_error("_del1key() cannot find entry in B tree");
  71. _isbtree_remove(btree);
  72. }
  73. else {
  74. if ((pkey = _isbtree_current(btree)) == NULL ||
  75. ldrecno(pkey + KEY_RECNO_OFF) != recnum)
  76. _isfatal_error("_del1key() cannot find entry in B tree");
  77. _isbtree_remove(btree);
  78. }
  79. _isbtree_destroy(btree);
  80. }