-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_modularized.c
71 lines (48 loc) · 1.81 KB
/
sample_modularized.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
#include <cassandra.h>
#include <stdio.h>
CassCluster* cluster;
CassSession* session;
CassFuture* connect_future;
CassError rc;
CassFuture* query_future;
char* cassandra_serv_ip = "155.230.91.212"; // contact points
/* Setup and Connect Cassandra*/
void setup_cassandra_driver() {
/* Setup and connect to cluster */
cluster = cass_cluster_new();
session = cass_session_new();
/* Add contact points */
cass_cluster_set_contact_points(cluster, cassandra_serv_ip);
/* Provide the cluster object as configuration to connect the session */
connect_future = cass_session_connect(session, cluster);
/* This operation will block until the result is ready */
rc = cass_future_error_code(connect_future);
printf("Connect result: %s\n", cass_error_desc(rc));
}
/* Run queries...insert */
void execute_cassandra_insert(char* query_string) {
/* Create a statement with zero parameters */
CassStatement* statement = cass_statement_new(query_string, 0);
query_future = cass_session_execute(session, statement);
/* Statement objects can be freed immediately after being executed */
cass_statement_free(statement);
/* This will block until the query has finished */
rc = cass_future_error_code(query_future);
printf("Query result: %s\n", cass_error_desc(rc));
}
/* Terminate Cassandra Driver */
void terminate_cassandra_driver() {
cass_future_free(query_future);
cass_future_free(connect_future);
cass_session_free(session);
cass_cluster_free(cluster);
}
int main() {
/* Setup and Connect Cassandra*/
setup_cassandra_driver();
/* Run queries... */
execute_cassandra_insert("insert into university.student(rollno, name, dept) values(3, 'third', 'Math' )");
/* Terminate Cassandra Driver */
terminate_cassandra_driver();
return 0;
}