-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestingdynamoDB.c
96 lines (81 loc) · 2.47 KB
/
testingdynamoDB.c
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
84
85
86
87
88
89
90
91
92
93
94
95
#include "stdio.h"
#include <string.h>
#include "Python.h"
#include "dynamoDBc.h"
PyObject *make_dictionary(int length, char* name, char* lastname, char* city)
{
PyObject *pDict = PyDict_New();
PyDict_SetItem(pDict, Py_BuildValue("s", "length"), Py_BuildValue("i", length));
PyDict_SetItem(pDict, Py_BuildValue("s", "name"), Py_BuildValue("s", name));
PyDict_SetItem(pDict, Py_BuildValue("s", "lastname"), Py_BuildValue("s", lastname));
PyDict_SetItem(pDict, Py_BuildValue("s", "city"), Py_BuildValue("s", city));
return pDict;
}
int main(int argc, char *argv[])
{
PyObject *pModule, *pConn, *pTable, *pItem = NULL;
init_python("/home/jasper/dynamoDBc");
pModule = get_module("dynamodb");
if( pModule == NULL)
{
printf("Not able find dynamodb.py module");
exit(1);
}
pConn = get_conn(pModule, "eu-west-1");
if( pConn == NULL)
{
printf("Not to make a dynamoDB connection");
exit(1);
}
pTable = get_table(pModule, pConn, "testingc");
if(pTable == NULL)
{
printf("Not to get table");
exit(1);
}
// get an item
pItem = get_item(pModule, pTable, 5);
if( pItem != NULL)
{
printf("We got the item: %s\n", PyString_AsString(pItem));
Py_DECREF(pItem);
}
Py_DECREF(pTable);
// get an item
pTable = get_table(pModule, pConn, "testingc");
pItem = get_item(pModule, pTable, 100);
if( pItem != NULL)
{
printf("We got the item: %s\n", PyString_AsString(pItem));
Py_DECREF(pItem);
}
Py_DECREF(pTable);
// and add an item
pTable = get_table(pModule, pConn, "testingc");
PyObject *pDict = make_dictionary(110, "Jan", "Klaas", "Hoorn");
set_item(pModule, pTable, 7, pDict);
Py_DECREF(pDict);
Py_DECREF(pTable);
// and add an item
pTable = get_table(pModule, pConn, "testingc");
PyObject *pDictTwo = make_dictionary(120, "Piet", "Klaas", "Enkhuizen");
set_item(pModule, pTable, 8, pDictTwo);
Py_DECREF(pDictTwo);
Py_DECREF(pTable);
// and add an other one
pTable = get_table(pModule, pConn, "testingc");
PyObject *pDictThree = make_dictionary(130, "Kees", "Klaas", "Medeblik");
set_item(pModule, pTable, 9, pDictThree);
Py_DECREF(pDictThree);
Py_DECREF(pTable);
// and add an other one
pTable = get_table(pModule, pConn, "testingc");
PyObject *pDictFour = make_dictionary(140, "Joost", "Klaas", "Hem");
set_item(pModule, pTable, 10, pDictFour);
Py_DECREF(pDictFour);
Py_DECREF(pTable);
// cleanup objects
Py_DECREF(pModule);
Py_DECREF(pConn);
Py_Finalize();
}