Addding test cases for connection and datatype module.
[csql.git] / test / performance / DMLTestChar.c
blob07a660bcfcc136fe2790f18c850282806d4fd467
1 #include<CSql.h>
2 #include<NanoTimer.h>
3 #define ITERATIONS 100
4 int main()
7 Connection conn;
8 DbRetVal rv = conn.open("praba", "manager");
9 if (rv != OK)
11 printf("Error during connection %d\n", rv);
12 return -1;
14 DatabaseManager *dbMgr = conn.getDatabaseManager();
15 if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
16 TableDef tabDef;
17 tabDef.addField("f1", typeString, 50, NULL, true, true);
18 tabDef.addField("f2", typeString, 950);
19 rv = dbMgr->createTable("t1", tabDef);
20 if (rv != OK) { printf("Table creation failed\n"); return -1; }
21 printf("Table created\n");
22 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
23 strcpy(idxInfo->tableName, "t1");
24 idxInfo->list.append("f1");
25 idxInfo->indType = hashIndex;
26 rv = dbMgr->createIndex("indx1", idxInfo);
27 if (rv != OK) { printf("Index creation failed\n"); return -1; }
28 printf("Index created\n");
29 Table *table = dbMgr->openTable("t1");
30 if (table == NULL) { printf("Unable to open table\n"); return -1; }
31 int id = 0;
32 char f1[50] = "PRABAKARAN";
33 char f2[950] = "Static Data is stored here";
34 table->bindFld("f1", f1);
35 table->bindFld("f2", f2);
36 char *tuple;
37 int ret;
38 int i;
39 int icount =0;
40 NanoTimer timer;
41 for(i = 0; i< ITERATIONS; i++)
43 sprintf(f1, "PRABAKARAN%d", i);
44 timer.start();
45 rv = conn.startTransaction();
46 if (rv != OK) exit(1);
47 //printf("%d\n ", i);
48 ret = table->insertTuple();
49 if (ret != 0) break;
50 icount++;
51 conn.commit();
52 timer.stop();
54 char msgBuf[1024];
55 sprintf(msgBuf,"Total rows inserted %d %lld %lld %lld\n",icount, timer.min(), timer.max(), timer.avg());
56 os::write(1,msgBuf,strlen(msgBuf));
58 int offset= os::align(50);
59 Condition p1;
60 char val1[50];
61 p1.setTerm("f1", OpEquals, &val1);
62 table->setCondition(&p1);
63 icount=0;
64 timer.reset();
65 for(i = 0; i< ITERATIONS; i++)
67 sprintf(val1, "PRABAKARAN%d", i);
68 timer.start();
69 rv =conn.startTransaction();
70 if (rv != OK) exit(1);
71 table->execute();
72 tuple = (char*)table->fetch();
73 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
74 //printf("Select f1 = %s, f2=%s\n", tuple, tuple + offset);
75 table->close();
76 icount++;
77 conn.commit();
78 timer.stop();
80 sprintf(msgBuf,"%d rows selected %lld %lld %lld\n", icount, timer.min(), timer.max(), timer.avg());
81 os::write(1,msgBuf,strlen(msgBuf));
82 timer.reset();
83 for(i = 0; i< ITERATIONS; i++)
85 sprintf(val1, "PRABAKARAN%d", i);
86 timer.start();
87 rv = conn.startTransaction();
88 if (rv != OK) exit (1);
89 table->execute();
90 tuple = (char*)table->fetch() ;
91 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
92 strcpy(f2, "PRABAKARAN0950576543210");
93 table->updateTuple();
94 table->close();
95 conn.commit();
96 timer.stop();
98 sprintf(msgBuf,"%d rows updated %lld %lld %lld\n", i, timer.min(), timer.max(), timer.avg());
99 os::write(1,msgBuf,strlen(msgBuf));
100 icount=0;
101 for(i = 0; i< ITERATIONS; i++)
103 sprintf(val1, "PRABAKARAN%d", i);
104 timer.start();
105 rv = conn.startTransaction();
106 if (rv != OK) exit (1);
107 table->execute();
108 tuple = (char*)table->fetch() ;
109 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
110 //printf("Before delete f1 = %s, f2=%s\n", tuple, tuple + offset);
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());
118 int count =0;
119 timer.reset();
120 for(i = 0; i< ITERATIONS; i++)
122 sprintf(val1, "PRABAKARAN%d", i);
123 rv = conn.startTransaction();
124 if (rv != OK) exit (1);
125 table->execute();
126 tuple = (char*)table->fetch() ;
127 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
128 //printf("tuple value is %d %s \n", *((int*)tuple), tuple+offset);
129 count++;
130 table->close();
131 conn.commit();
133 printf("Total rows selected %d\n", count);
136 dbMgr->closeTable(table);
137 dbMgr->dropTable("t1");
139 conn.close();
140 return 0;