changes for 2.5
[csql.git] / test / dbapi / Table / insertnulltest6.c
blob5c0c8951826181252630fb8bb6ce0af44fdeda39
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->dropTable("t1");
33 printf("table dropped\n");
34 conn.close();
35 return 0;
37 rv = table->insertTuple();
38 if(rv==OK)
40 printf("Error\n");
41 dbMgr->dropTable("t1");
42 conn.close();
43 return -1;
45 table->clearFldNull(1);
46 conn.commit();
48 table->setCondition(NULL);
49 rv = table->execute();
50 if (rv != OK)
52 dbMgr->closeTable(table);
53 dbMgr->dropTable("t1");
54 conn.close();
56 table->bindFld("f2", &id2);
57 void *tuple = NULL;
58 while(true)
60 tuple = (char*)table->fetch() ;
61 if (tuple == NULL) {break;}
62 if (table->isFldNull(1)) printf("Column 1 is null\n");
63 if (table->isFldNull(2)) printf("Column 2 is null\n");
64 printf("Binded Tuple value is %d %d \n", id1, id2);
67 table->closeScan();
68 dbMgr->closeTable(table);
69 dbMgr->dropTable("t1");
70 conn.close();
71 return 0;