GnuCOBOL  2.0
A free COBOL compiler
iswrite.c File Reference
#include "isinternal.h"
Include dependency graph for iswrite.c:

Go to the source code of this file.

Functions

static int irowinsert (const int ihandle, char *pcrow_buffer, off_t trownumber)
 
int ivbwriterow (const int ihandle, char *pcrow, const off_t trownumber)
 
int iswrcurr (const int ihandle, char *pcrow)
 
int iswrite (const int ihandle, char *pcrow)
 

Function Documentation

static int irowinsert ( const int  ihandle,
char *  pcrow_buffer,
off_t  trownumber 
)
static

Definition at line 23 of file iswrite.c.

References VBKEY::ckey, DICTINFO::inkeys, iserrno, ivbkeyinsert(), ivbkeyload(), ivbkeysearch(), MAXSUBS, NULL, DICTINFO::pskeydesc, psvbfile, VBKEY::tdupnumber, and vvbmakekey().

Referenced by ivbwriterow().

24 {
25  struct VBKEY *pskey;
26  struct DICTINFO *psvbptr;
27  struct keydesc *pskptr;
28  off_t tdupnumber[MAXSUBS];
29  int ikeynumber, iresult;
30  unsigned char ckeyvalue[VB_MAX_KEYLEN];
31 
32  psvbptr = psvbfile[ihandle];
33  /*
34  * Step 1:
35  * Check each index for a potential ISNODUPS error (EDUPL)
36  * Also, calculate the duplicate number as needed
37  */
38  for (ikeynumber = 0; ikeynumber < psvbptr->inkeys; ikeynumber++) {
39  pskptr = psvbptr->pskeydesc[ikeynumber];
40  if (pskptr->k_nparts == 0) {
41  continue;
42  }
43  vvbmakekey (psvbptr->pskeydesc[ikeynumber], pcrow_buffer, ckeyvalue);
44  iresult = ivbkeysearch (ihandle, ISGREAT, ikeynumber, 0, ckeyvalue, (off_t)0);
45  tdupnumber[ikeynumber] = 0;
46  if (iresult >= 0 && !ivbkeyload (ihandle, ikeynumber, ISPREV, 0, &pskey)
47  && !memcmp (pskey->ckey, ckeyvalue, (size_t)pskptr->k_len)) {
48  iserrno = EDUPL;
49  if (pskptr->k_flags & ISDUPS) {
50  tdupnumber[ikeynumber] = pskey->tdupnumber + 1;
51  } else {
52  return -1;
53  }
54  }
55  iresult = ivbkeysearch (ihandle, ISGTEQ, ikeynumber, 0, ckeyvalue,
56  tdupnumber[ikeynumber]);
57  }
58 
59  /* Step 2: Perform the actual insertion into each index */
60  for (ikeynumber = 0; ikeynumber < psvbptr->inkeys; ikeynumber++) {
61  if (psvbptr->pskeydesc[ikeynumber]->k_nparts == 0) {
62  continue;
63  }
64  vvbmakekey (psvbptr->pskeydesc[ikeynumber], pcrow_buffer, ckeyvalue);
65  iresult = ivbkeyinsert (ihandle, NULL, ikeynumber, ckeyvalue,
66  trownumber, tdupnumber[ikeynumber], NULL);
67  if (iresult) {
68 /* BUG - do something SANE here */
69  /* Eeek, an error occured. Let's remove what we added */
70  /* while (ikeynumber >= 0) */
71  /* { */
72  /* ivbkeydelete (ihandle, ikeynumber); */
73  /* ikeynumber--; */
74  /* } */
75  return iresult;
76  }
77  }
78 
79  return 0;
80 }
int inkeys
Definition: isinternal.h:400
int ivbkeysearch(const int ihandle, const int imode, const int ikeynumber, int ilength, unsigned char *pckeyvalue, off_t tdupnumber)
Definition: vbkeysio.c:372
unsigned char ckey[1]
Definition: isinternal.h:334
int ivbkeyload(const int ihandle, const int ikeynumber, const int imode, const int isetcurr, struct VBKEY **ppskey)
Definition: vbkeysio.c:503
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void vvbmakekey(const struct keydesc *pskeydesc, char *pcrow_buffer, unsigned char *pckeyvalue)
Definition: vbkeysio.c:212
struct DICTINFO * psvbfile[128+1]
Definition: vblowlevel.c:23
off_t tdupnumber
Definition: isinternal.h:329
int ivbkeyinsert(const int ihandle, struct VBTREE *pstree, const int ikeynumber, unsigned char *pckeyvalue, off_t trownode, off_t tdupnumber, struct VBTREE *pschild)
Definition: vbkeysio.c:727
struct keydesc * pskeydesc[32]
Definition: isinternal.h:445
int iserrno
Definition: vbmemio.c:27
#define MAXSUBS
Definition: isinternal.h:119

Here is the call graph for this function:

Here is the caller graph for this function:

int iswrcurr ( const int  ihandle,
char *  pcrow 
)

Definition at line 122 of file iswrite.c.

References DICTINFO::imaxrowlength, DICTINFO::iminrowlength, DICTINFO::iopenmode, iserrno, isreclen, ivbdatafree(), ivbenter(), ivbexit(), ivbwriterow(), psvbfile, DICTINFO::trownumber, and tvbdataallocate().

123 {
124  struct DICTINFO *psvbptr;
125  off_t trownumber;
126  int iresult;
127 
128  if (ivbenter (ihandle, 1, 0)) {
129  return -1;
130  }
131  psvbptr = psvbfile[ihandle];
132 
133  if ((psvbptr->iopenmode & ISVARLEN) && (isreclen > psvbptr->imaxrowlength
134  || isreclen < psvbptr->iminrowlength)) {
135  iserrno = EBADARG;
136  return -1;
137  }
138 
139  trownumber = tvbdataallocate (ihandle);
140  if (trownumber == -1) {
141  return -1;
142  }
143 
144  iresult = ivbwriterow (ihandle, pcrow, trownumber);
145  if (!iresult) {
146  psvbptr->trownumber = trownumber;
147  } else {
148  ivbdatafree (ihandle, trownumber);
149  }
150 
151  ivbexit (ihandle);
152  return iresult;
153 }
int imaxrowlength
Definition: isinternal.h:404
int ivbdatafree(const int ihandle, const off_t trownumber)
Definition: vbindexio.c:150
int isreclen
Definition: vbmemio.c:29
int ivbenter(const int ihandle, const unsigned int imodifying, const unsigned int ispecial)
Definition: vblocking.c:178
int ivbwriterow(const int ihandle, char *pcrow, const off_t trownumber)
Definition: iswrite.c:85
int iminrowlength
Definition: isinternal.h:403
off_t tvbdataallocate(const int ihandle)
Definition: vbindexio.c:284
struct DICTINFO * psvbfile[128+1]
Definition: vblowlevel.c:23
int ivbexit(const int ihandle)
Definition: vblocking.c:290
int iopenmode
Definition: isinternal.h:412
off_t trownumber
Definition: isinternal.h:416
int iserrno
Definition: vbmemio.c:27

Here is the call graph for this function:

int iswrite ( const int  ihandle,
char *  pcrow 
)

Definition at line 156 of file iswrite.c.

References DICTINFO::imaxrowlength, DICTINFO::iminrowlength, DICTINFO::iopenmode, iserrno, isreclen, ivbdatafree(), ivbenter(), ivbexit(), ivbwriterow(), psvbfile, DICTINFO::trownumber, and tvbdataallocate().

Referenced by indexed_write().

157 {
158  struct DICTINFO *psvbptr;
159  off_t trownumber;
160  int iresult, isaveerror;
161 
162  if (ivbenter (ihandle, 1, 0)) {
163  return -1;
164  }
165  psvbptr = psvbfile[ihandle];
166 
167  if ((psvbptr->iopenmode & ISVARLEN) && (isreclen > psvbptr->imaxrowlength
168  || isreclen < psvbptr->iminrowlength)) {
169  iserrno = EBADARG;
170  return -1;
171  }
172 
173  trownumber = tvbdataallocate (ihandle);
174  if (trownumber == -1) {
175  return -1;
176  }
177 
178  iresult = ivbwriterow (ihandle, pcrow, trownumber);
179  if (iresult) {
180  isaveerror = iserrno;
181  ivbdatafree (ihandle, trownumber);
182  iserrno = isaveerror;
183  }
184 
185  ivbexit (ihandle);
186  return iresult;
187 }
int imaxrowlength
Definition: isinternal.h:404
int ivbdatafree(const int ihandle, const off_t trownumber)
Definition: vbindexio.c:150
int isreclen
Definition: vbmemio.c:29
int ivbenter(const int ihandle, const unsigned int imodifying, const unsigned int ispecial)
Definition: vblocking.c:178
int ivbwriterow(const int ihandle, char *pcrow, const off_t trownumber)
Definition: iswrite.c:85
int iminrowlength
Definition: isinternal.h:403
off_t tvbdataallocate(const int ihandle)
Definition: vbindexio.c:284
struct DICTINFO * psvbfile[128+1]
Definition: vblowlevel.c:23
int ivbexit(const int ihandle)
Definition: vblocking.c:290
int iopenmode
Definition: isinternal.h:412
off_t trownumber
Definition: isinternal.h:416
int iserrno
Definition: vbmemio.c:27

Here is the call graph for this function:

Here is the caller graph for this function:

int ivbwriterow ( const int  ihandle,
char *  pcrow,
const off_t  trownumber 
)

Definition at line 85 of file iswrite.c.

References DICTINFO::iminrowlength, DICTINFO::iopenmode, irowinsert(), iserrno, isreclen, isrecnum, ivbdatalock(), ivbdatawrite(), ivbtransinsert(), psvbfile, DICTINFO::trownumber, DICTINFO::tvarlennode, VBUNLOCK, and VBWRLOCK.

Referenced by ircvinsert(), iswrcurr(), iswrite(), and ivbrollmeback().

86 {
87  struct DICTINFO *psvbptr;
88  int iresult = 0;
89 
90  psvbptr = psvbfile[ihandle];
92  if (psvbptr->iopenmode & ISTRANS) {
93  iserrno = ivbdatalock (ihandle, VBWRLOCK, trownumber);
94  if (iserrno) {
95  return -1;
96  }
97  }
98  iresult = irowinsert (ihandle, pcrow, trownumber);
99  if (!iresult) {
100  iserrno = 0;
101  psvbptr->tvarlennode = 0; /* Stop it from removing */
102  iresult = ivbdatawrite (ihandle, (void *)pcrow, 0, trownumber);
103  if (iresult) {
104  iserrno = iresult;
105  if (psvbptr->iopenmode & ISTRANS) {
106  ivbdatalock (ihandle, VBUNLOCK, trownumber);
107  }
108  return -1;
109  }
110  if (psvbptr->iopenmode & ISVARLEN) {
111  iresult = ivbtransinsert (ihandle, trownumber,
112  isreclen, pcrow);
113  } else {
114  iresult = ivbtransinsert (ihandle, trownumber,
115  psvbptr->iminrowlength, pcrow);
116  }
117  }
118  return iresult;
119 }
int isreclen
Definition: vbmemio.c:29
int ivbdatawrite(const int ihandle, char *pcbuffer, int ideletedrow, const off_t trownumber)
Definition: vbdataio.c:611
int ivbtransinsert(const int ihandle, const off_t trownumber, int irowlength, char *pcrow)
Definition: istrans.c:878
int iminrowlength
Definition: isinternal.h:403
off_t tvarlennode
Definition: isinternal.h:421
int ivbdatalock(const int ihandle, const int imode, const off_t trownumber)
Definition: vblocking.c:432
#define VBWRLOCK
Definition: isinternal.h:297
struct DICTINFO * psvbfile[128+1]
Definition: vblowlevel.c:23
int iopenmode
Definition: isinternal.h:412
static int irowinsert(const int ihandle, char *pcrow_buffer, off_t trownumber)
Definition: iswrite.c:23
#define VBUNLOCK
Definition: isinternal.h:294
off_t trownumber
Definition: isinternal.h:416
int iserrno
Definition: vbmemio.c:27
int isrecnum
Definition: vbmemio.c:30

Here is the call graph for this function:

Here is the caller graph for this function: