Testing NOT NULL in DBAPI
[csql.git] / test / dbapi / Table / insertnulltest7.c
blob66109c9992b29004f56935e6b623185d90141ee2
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);
12 tabDef.addField("f2", typeInt);
13 rv = dbMgr->createTable("t1", tabDef);
14 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
15 printf("Table created\n");
17 Table *table = dbMgr->openTable("t1");
18 if (table == NULL)
20 printf("Unable to open table\n");
21 dbMgr->dropTable("t1");
22 conn.close();
23 return -1;
25 int id1 = 0, id2 = 5;
26 table->bindFld("f1", &id1);
27 table->bindFld("f2", &id2);
28 int icount =0;
29 for (int i = 0 ; i < 10 ; i++)
31 conn.startTransaction();
32 id1= i;id2=id2+i;
33 if (i%2 == 0){ table->markFldNull(1);table->markFldNull(2);}
34 rv = table->insertTuple();
35 if (rv != OK) break;
36 if (i%2 == 0) {table->clearFldNull(1);table->clearFldNull(2);}
37 icount++;
38 conn.commit();
40 printf("Tuples inserted in 1/txn is %d\n", icount);
41 table->setCondition(NULL);
42 rv = table->execute();
43 if (rv != OK)
45 dbMgr->closeTable(table);
46 dbMgr->dropTable("t1");
47 conn.close();
49 void *tuple = NULL;
50 while(true)
52 tuple = (char*)table->fetch() ;
53 if (tuple == NULL) {break;}
54 if (table->isFldNull(1)) printf("Column 1 is null\n");
55 if (table->isFldNull(2)) printf("Column 2 is null\n");
56 printf("Binded Tuple value is %d %d \n", id1, id2);
58 table->close();
59 dbMgr->closeTable(table);
60 dbMgr->dropTable("t1");
61 conn.close();
62 return 0;