exp changes
[csql.git] / test / dbapi / Table / insertnulltest3.c
blobfe2ce450920f6f0386127c8235b80d7edb9131a9
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 tabDef.addField("f3", typeString, 20);
14 rv = dbMgr->createTable("t1", tabDef);
15 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
16 printf("Table created\n");
18 Table *table = dbMgr->openTable("t1");
19 if (table == NULL)
21 printf("Unable to open table\n");
22 dbMgr->dropTable("t1");
23 conn.close();
24 return -1;
26 int id1 = 0, id2 = 5;
27 char name[20] = "unchangedvalue";
28 table->bindFld("f1", &id1);
29 table->bindFld("f2", &id2);
30 //table->bindFld("f3", name);
31 int icount =0;
32 for (int i = 0 ; i < 5 ; i++)
34 conn.startTransaction();
35 id1= i;
36 rv = table->insertTuple();
37 if (rv != OK) break;
38 icount++;
39 conn.commit();
42 printf("Tuples inserted in 1/txn is %d\n", icount);
43 table->setCondition(NULL);
44 rv = table->execute();
45 if (rv != OK)
47 dbMgr->closeTable(table);
48 dbMgr->dropTable("t1");
49 conn.close();
51 table->bindFld("f2", &id2);
52 void *tuple = NULL;
53 while(true)
55 tuple = (char*)table->fetch() ;
56 if (tuple == NULL) {break;}
57 if (table->isFldNull(1)) printf("Column 1 is null\n");
58 if (table->isFldNull(2)) printf("Column 2 is null\n");
59 if (table->isFldNull(3)) printf("Column 3 is null\n");
60 printf("Binded Tuple value is %d %d %s \n", id1, id2, name);
62 table->closeScan();
63 dbMgr->closeTable(table);
64 dbMgr->dropTable("t1");
65 conn.close();
66 return 0;