#include "mr_server.h"
EXEC SQL INCLUDE sqlca;
+
extern char *whoami, *strsave();
extern int ingres_errno, mr_errcode;
int id;
struct item *next;
struct item *prev;
+ struct item *trans; /* keep track of transactions */
};
static struct item cachehead;
if (cachehead.prev != &cachehead)
free(cachehead.prev);
cachehead.next = cachehead.prev = &cachehead;
+ cachehead.trans = (struct item *)NULL;
}
char *type;
int *id;
{
- register struct item *i;
+ register struct item *i, *t;
EXEC SQL BEGIN DECLARE SECTION;
char *iname;
int j, rowcount;
break;
case 'M':
case 'm':
- uppercase(iname);
- EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=:iname;
+ EXEC SQL SELECT mach_id INTO :j FROM machine WHERE name=uppercase(:iname);
break;
case 'C':
case 'c':
i->prev = &cachehead;
cachehead.next->prev = i;
cachehead.next = i;
+ /* find the end of the transaction chain & add this item */
+ for (t = &cachehead; t->trans && t != i; t = t->trans);
+ if (t != i) {
+ t->trans = i;
+ i->trans = (struct item *)NULL;
+ }
return(MR_SUCCESS);
}
i->prev = &cachehead;
cachehead.next->prev = i;
cachehead.next = i;
+ /* find the end of the transaction chain & add this item */
+ for (t = &cachehead; t->trans && t != i; t = t->trans);
+ if (t != i) {
+ t->trans = i;
+ i->trans = (struct item *)NULL;
+ }
return(MR_SUCCESS);
}
char *type;
int id;
{
- register struct item *i;
+ register struct item *i, *t;
for (i = cachehead.next; i != &cachehead; i = i->next)
- if (i->id == id && !strcmp(i->type, type))
- return(MR_SUCCESS);
+ if (i->id == id && !strcmp(i->type, type)) {
+ if (strcmp(i->name, name)) {
+ strcpy(i->name, name);
+ i->nhash = hashname(name, type);
+ }
+ return(MR_SUCCESS);
+ }
if (cachesize < CACHESIZE) {
i = (struct item *) malloc(sizeof(struct item));
cachesize++;
i->prev = &cachehead;
cachehead.next->prev = i;
cachehead.next = i;
+ /* find the end of the transaction chain & add this item */
+ for (t = &cachehead; t->trans && t != i; t = t->trans);
+ if (t != i) {
+ t->trans = i;
+ i->trans = (struct item *)NULL;
+ }
return(MR_SUCCESS);
}
}
}
}
+
+
+/* Called when a transaction is committed to also commit any cache changes.
+ * Just throws away the list of cache changes for this transaction.
+ */
+
+cache_commit()
+{
+ cachehead.trans = (struct item *)NULL;
+}
+
+
+/* Called whan a transaction is aborted to throw away any cache changes
+ * from that transaction.
+ */
+
+cache_abort()
+{
+ register struct item *i, *t;
+
+ for (i = cachehead.trans; i; i = t) {
+ t = i->trans;
+ flush_name(i->name, i->type);
+ }
+ cachehead.trans = (struct item *)NULL;
+}