1
[csql.git] / test / dbapi / Table / insertnulltest6.c
blob6bd9c237e4bf60d882bce88266908cf248d046c6
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 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 conn.startTransaction();
29 rv = table->markFldNull(1);
30 if (rv != OK) {
31 printf("test passed\n");
32 dbMgr->closeTable(table);
33 dbMgr->dropTable("t1");
34 printf("table dropped\n");
35 conn.close();
36 return 0;
38 rv = table->insertTuple();
39 if(rv==OK)
41 printf("Error\n");
42 dbMgr->dropTable("t1");
43 conn.close();
44 return -1;
46 table->clearFldNull(1);
47 conn.commit();
49 table->setCondition(NULL);
50 rv = table->execute();
51 if (rv != OK)
53 dbMgr->closeTable(table);
54 dbMgr->dropTable("t1");
55 conn.close();
57 table->bindFld("f2", &id2);
58 void *tuple = NULL;
59 while(true)
61 tuple = (char*)table->fetch() ;
62 if (tuple == NULL) {break;}
63 if (table->isFldNull(1)) printf("Column 1 is null\n");
64 if (table->isFldNull(2)) printf("Column 2 is null\n");
65 printf("Binded Tuple value is %d %d \n", id1, id2);
68 table->closeScan();
69 dbMgr->closeTable(table);
70 dbMgr->dropTable("t1");
71 conn.close();
72 return 0;