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