code reorg for Transactionw!
[csql.git] / test / dbapi / Table / insertnulltest5.c
blobcf5dd600e8d92e99780e2682277cc0958b4ace29
1 #include<CSql.h>
2 int main()
4 Connection conn;
5 DbRetVal rv = conn.open("root", "manager");
6 if (rv != OK) return 1;
7 DatabaseManager *dbMgr = conn.getDatabaseManager();
8 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
10 TableDef tabDef;
11 tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL
12 tabDef.addField("f2", typeInt, 0, NULL, false);
13 tabDef.addField("f3", typeString, 20);//Bydefault 'NOT NULL' is false
14 rv = dbMgr->createTable("t1", tabDef);
15 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
16 printf("Table created\n");
18 Table *table = dbMgr->openTable("t1");
19 if (table == NULL)
21 printf("Unable to open table\n");
22 dbMgr->dropTable("t1");
23 conn.close();
24 return -1;
26 int id1 = 0, id2 = 5;
27 char name[20] = "PRAVEEN";
28 table->bindFld("f1", &id1);
29 table->bindFld("f2", &id2);
30 table->bindFld("f3", name);
31 int icount =0;
32 for (int i = 0 ; i < 5 ; i++)
34 conn.startTransaction();
35 id1= i;
36 if (i%2 == 0) table->markFldNull("f3");
37 rv = table->insertTuple();
38 if (rv != OK) break;
39 if (i%2 == 0) table->clearFldNull("f3");
40 icount++;
41 conn.commit();
44 printf("Tuples inserted in 1/txn is %d\n", icount);
45 table->setCondition(NULL);
46 rv = table->execute();
47 if (rv != OK)
49 dbMgr->closeTable(table);
50 dbMgr->dropTable("t1");
51 conn.close();
53 table->bindFld("f2", &id2);
54 void *tuple = NULL;
55 while(true)
57 tuple = (char*)table->fetch() ;
58 if (tuple == NULL) {break;}
59 if (table->isFldNull(1)) printf("Column 1 is null\n");
60 if (table->isFldNull(2)) printf("Column 2 is null\n");
61 if (table->isFldNull(3)) printf("Column 3 is null\n");
62 printf("Binded Tuple value is %d %d %s \n", id1, id2, name);
65 table->closeScan();
66 dbMgr->closeTable(table);
67 dbMgr->dropTable("t1");
68 conn.close();
69 return 0;