1
[csql.git] / test / dbapi / Table / insertnulltest4.c
blob7e07b521195bec5ad0953732cc7156b241019e8d
1 /* using markfieldnull without clearFieldNull.
2 * create table t1 with f1 and f2 field
3 * without clearFldNull() f2 field will be null always.
5 * Author : Jitendra Lenka.
6 */
9 #include<CSql.h>
10 int main()
12 Connection conn;
13 DbRetVal rv = conn.open("root", "manager");
14 if (rv != OK) return 1;
15 DatabaseManager *dbMgr = conn.getDatabaseManager();
16 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
18 TableDef tabDef;
19 tabDef.addField("f1", typeInt, 0, NULL, true);
20 tabDef.addField("f2", typeInt);
22 rv = dbMgr->createTable("t1", tabDef);
23 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
24 printf("Table created\n");
26 Table *table = dbMgr->openTable("t1");
27 if (table == NULL)
29 printf("Unable to open table\n");
30 dbMgr->dropTable("t1");
31 conn.close();
32 return -1;
34 int id1 = 0, id2 = 5;
35 char name[20] = "PRAVEEN";
36 table->bindFld("f1", &id1);
37 table->bindFld("f2", &id2);
39 int icount =0;
40 for (int i = 0 ; i < 10 ; i++)
42 conn.startTransaction();
43 id1= i;
44 if (i%2 == 0) table->markFldNull(2);
45 rv = table->insertTuple();
46 if (rv != OK) break;
47 //if (i%2 == 0) table->clearFldNull(2);
48 icount++;
49 conn.commit();
52 printf("Tuples inserted in 1/txn is %d\n", icount);
53 table->setCondition(NULL);
54 rv = table->execute();
55 if (rv != OK)
57 dbMgr->closeTable(table);
58 dbMgr->dropTable("t1");
59 conn.close();
61 void *tuple = NULL;
62 while(true)
64 tuple = (char*)table->fetch() ;
65 if (tuple == NULL) {break;}
66 if (table->isFldNull(1)) printf("Column 1 is null\n");
67 if (table->isFldNull(2)) printf("Column 2 is null\n");
69 printf("Binded Tuple value is %d %d \n", id1, id2);
72 table->closeScan();
73 dbMgr->closeTable(table);
74 dbMgr->dropTable("t1");
75 conn.close();
76 return 0;