Addding test cases for connection and datatype module.
[csql.git] / test / performance / DMLTest.c
blobc9f37e4702a5a694b9dd503a0364b5a9a211e10b
1 #include<CSql.h>
2 #include<NanoTimer.h>
3 int main()
6 Connection conn;
7 DbRetVal rv = conn.open("praba", "manager");
8 if (rv != OK)
10 printf("Error during connection %d\n", rv);
11 return -1;
15 DatabaseManager *dbMgr = conn.getDatabaseManager();
16 if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
17 TableDef tabDef;
18 tabDef.addField("f1", typeInt, 0, NULL, true, true );
19 tabDef.addField("f2", typeString, 196);
20 rv = dbMgr->createTable("t1", tabDef);
21 if (rv != OK) { printf("Table creation failed\n"); return -1; }
22 printf("Table created\n");
23 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
24 strcpy(idxInfo->tableName, "t1");
25 idxInfo->list.append("f1");
26 idxInfo->indType = hashIndex;
27 rv = dbMgr->createIndex("indx1", idxInfo);
28 if (rv != OK) { printf("Index creation failed\n"); return -1; }
29 printf("Index created\n");
30 Table *table = dbMgr->openTable("t1");
31 if (table == NULL) { printf("Unable to open table\n"); return -1; }
32 int id = 0;
33 char name[196] = "PRABAKARAN";
34 table->bindFld("f1", &id);
35 table->bindFld("f2", name);
36 char *tuple;
37 int ret;
38 int i;
39 int icount =0;
40 NanoTimer timer;
41 for(i = 0; i< 100; i++)
43 timer.start();
44 rv = conn.startTransaction();
45 if (rv != OK) exit(1);
46 id= i;
47 strcpy(name, "PRABAKARAN0123456750590");
48 //printf("%d\n ", i);
49 ret = table->insertTuple();
50 if (ret != 0) break;
51 icount++;
52 conn.commit();
53 timer.stop();
55 char msgBuf[1024];
56 sprintf(msgBuf,"Total rows inserted %d %lld %lld %lld\n",icount, timer.min(), timer.max(), timer.avg());
57 os::write(1,msgBuf,strlen(msgBuf));
59 int offset1= os::align(sizeof(int));
60 Condition p1;
61 int val1 = 0;
62 p1.setTerm("f1", OpEquals, &val1);
63 table->setCondition(&p1);
64 icount=0;
65 timer.reset();
66 for(i = 0; i< 100; i++)
68 timer.start();
69 rv =conn.startTransaction();
70 if (rv != OK) exit(1);
71 val1 = i;
72 table->execute();
73 tuple = (char*)table->fetch() ;
74 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
75 //printf("tuple value is %d %s \n", *((int*)tuple), tuple+offset1);
76 table->close();
77 icount++;
78 conn.commit();
79 timer.stop();
81 sprintf(msgBuf,"%d rows selected %lld %lld %lld\n", icount, timer.min(), timer.max(), timer.avg());
82 os::write(1,msgBuf,strlen(msgBuf));
83 timer.reset();
84 for(i = 0; i< 100; i++)
86 timer.start();
87 rv = conn.startTransaction();
88 if (rv != OK) exit (1);
89 val1 = i;
90 table->execute();
91 tuple = (char*)table->fetch() ;
92 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
93 strcpy(name, "PRABAKARAN0950576543210");
94 table->updateTuple();
95 table->close();
96 conn.commit();
97 timer.stop();
99 sprintf(msgBuf,"%d rows updated %lld %lld %lld\n", i, timer.min(), timer.max(), timer.avg());
100 os::write(1,msgBuf,strlen(msgBuf));
101 icount=0;
102 for(i = 0; i< 100; i++)
104 timer.start();
105 rv = conn.startTransaction();
106 if (rv != OK) exit (1);
107 val1 = i;
108 table->execute();
109 tuple = (char*)table->fetch() ;
110 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
111 table->deleteTuple();
112 icount++;
113 table->close();
114 conn.commit();
115 timer.stop();
117 printf("%d rows deleted %lld %lld %lld\n", icount, timer.min(), timer.max(), timer.avg());
119 int count =0;
120 timer.reset();
121 for(i = 0; i< 100; i++)
123 rv = conn.startTransaction();
124 if (rv != OK) exit (1);
125 val1 = i;
126 table->execute();
127 tuple = (char*)table->fetch() ;
128 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
129 //printf("tuple value is %d %s \n", *((int*)tuple), tuple+offset1);
130 count++;
131 table->close();
132 conn.commit();
134 printf("Total rows selected %d\n", count);
135 dbMgr->closeTable(table);
136 dbMgr->dropTable("t1");
138 conn.close();
139 return 0;