* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)rec_put.c 5.6 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
* __REC_PUT -- Add a recno item to the tree.
* dbp: pointer to access method
* flag: R_CURSORLOG, R_CURSOR, R_IAFTER, R_IBEFORE, R_NOOVERWRITE
* RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is already in the
* tree and R_NOOVERWRITE specified.
__rec_put(dbp
, key
, data
, flags
)
if (!ISSET(t
, BTF_SEQINIT
))
nrec
= t
->bt_rcursor
+ 1;
if ((nrec
= *(recno_t
*)key
->data
) == 0)
if ((nrec
= *(recno_t
*)key
->data
) == 0) {
if ((nrec
= *(recno_t
*)key
->data
) == 0)
if ((nrec
= *(recno_t
*)key
->data
) == 0)
* Make sure that records up to and including the put record are
* already in the database. If skipping records, create empty ones.
if (nrec
> t
->bt_nrecs
) {
if (!ISSET(t
, BTF_RINMEM
) && t
->bt_irec(t
, nrec
) == RET_ERROR
)
if (nrec
> t
->bt_nrecs
+ 1) {
while (nrec
> t
->bt_nrecs
+ 1)
t
->bt_nrecs
, &tdata
, 0) != RET_SUCCESS
)
if ((status
= __rec_iput(t
, nrec
- 1, data
, flags
)) != RET_SUCCESS
)
return (__rec_ret(t
, NULL
, nrec
, key
, NULL
));
* __REC_IPUT -- Add a recno item to the tree.
__rec_iput(t
, nrec
, data
, flags
)
char *dest
, db
[NOVFLSIZE
];
* If the data won't fit on a page, store it on indirect pages.
* If the insert fails later on, these pages aren't recovered.
if (data
->size
> t
->bt_ovflsize
) {
if (__ovfl_put(t
, data
, &pg
) == RET_ERROR
)
*(size_t *)(db
+ sizeof(pgno_t
)) = data
->size
;
/* __rec_search pins the returned page. */
if ((e
= __rec_search(t
, nrec
,
nrec
> t
->bt_nrecs
|| flags
== R_IAFTER
|| flags
== R_IBEFORE
?
SINSERT
: SEARCH
)) == NULL
)
* Add the specified key/data pair to the tree. The R_IAFTER and
* R_IBEFORE flags insert the key after/before the specified key.
* Pages are split as required.
if (nrec
< t
->bt_nrecs
&&
__rec_dleaf(t
, h
, index
) == RET_ERROR
) {
mpool_put(t
->bt_mp
, h
, 0);
* If not enough room, split the page. The split code will insert
* the key and data and unpin the current page. If inserting into
* the offset array, shift the pointers up.
nbytes
= NRLEAFDBT(data
->size
);
if (h
->upper
- h
->lower
< nbytes
+ sizeof(index_t
)) {
status
= __bt_split(t
, h
, NULL
, data
, dflags
, nbytes
, index
);
if (status
== RET_SUCCESS
)
if (index
< (nxtindex
= NEXTINDEX(h
)))
bcopy(h
->linp
+ index
, h
->linp
+ index
+ 1,
(nxtindex
- index
) * sizeof(index_t
));
h
->lower
+= sizeof(index_t
);
h
->linp
[index
] = h
->upper
-= nbytes
;
dest
= (char *)h
+ h
->upper
;
WR_RLEAF(dest
, data
, dflags
);
mpool_put(t
->bt_mp
, h
, MPOOL_DIRTY
);