-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.h
83 lines (74 loc) · 1.85 KB
/
api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define STRING_SIZE 255
#define MIN_SIZE 10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "StructureFile.h"
void getData(int id){
Rows *tempNode = rowHead;
int flag = 1;
while (tempNode != NULL){
if (tempNode->rowId == id){
printDetails(tempNode);
flag = 0;
break;
}
tempNode = tempNode->next;
}
if (flag)
printf("\nMember with ID %d not found\n", id);
}
int putData(char **columnNames, char **values, int index, int id){
Rows *tempRowNode = rowHead;
while (tempRowNode != NULL){
if (tempRowNode->rowId == id){
for (int i = 0; i < index; ++i)
tempRowNode->columns = getColumnHead(tempRowNode->columns, columnNames[i], values[i]);
tempRowNode->commitVersion += 1;
return id;
}
tempRowNode = tempRowNode->next;
}
tempRowNode = rowHead;
Rows *newRowNode = createRowNode();
for (int i = 0; i < index; ++i){
newRowNode->columns = getColumnHead(newRowNode->columns, columnNames[i], values[i]);
}
if (rowHead == NULL){
newRowNode->rowId = 1;
newRowNode->commitVersion = 1;
rowHead = newRowNode;
}
else{
while (tempRowNode->next != NULL){
tempRowNode = tempRowNode->next;
}
newRowNode->rowId = tempRowNode->rowId + 1;
newRowNode->commitVersion = getCommitVersion(newRowNode);
tempRowNode->next = newRowNode;
}
return newRowNode->rowId;
}
void deleteData(int id){
Rows *tempNode = rowHead, *prevNode = NULL;
int flag = 1;
if (rowHead != NULL && rowHead->next == NULL){
if (tempNode->rowId == id)
rowHead = NULL;
free(tempNode);
return;
}
while (tempNode != NULL){
if (tempNode->rowId == id){
prevNode->next = tempNode->next;
free(tempNode);
flag = 0;
break;
}
prevNode = tempNode;
tempNode = tempNode->next;
}
if (flag)
printf("\nMember ID not found\n");
}