windows changes
[csql.git] / test / dbapi / TableDef / fieldname3.c
bloba0e09ae72421a083381a5cb67df5becc86d57283
1 //addField f1, dropField f1 and then addField f1 with notnull flag set,
2 //table creation should succeed and it should make the f1 field notnull
3 #include<CSql.h>
4 int main()
6 Connection conn;
7 DbRetVal rv = conn.open("root", "manager");
8 if (rv != OK) return 1;
9 DatabaseManager *dbMgr = conn.getDatabaseManager();
10 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
12 TableDef tabDef;
14 tabDef.addField("f1", typeInt);
15 tabDef.dropField("f1");
16 tabDef.addField("f1", typeInt, 0, NULL, true);
17 rv=dbMgr->createTable("t1", tabDef);
18 if(rv!=OK)
20 printf("Table creation failed\n");
21 printf("Test Failed\n");
22 dbMgr->dropTable("t1");
23 return 3;
25 printf("Table created\n");
27 Table *table = dbMgr->openTable("t1");
28 if (table == NULL)
30 printf("Unable to open table\n");
31 dbMgr->dropTable("t1");
32 conn.close();
33 return -1;
35 // int id;
36 // table->bindFld("f1",&id);
38 conn.startTransaction();
39 rv=table->insertTuple();
40 if(rv==OK)
42 printf("NULL value inserted in NOTNULL field\n");
43 printf("Test Failed\n");
44 conn.commit();
45 dbMgr->closeTable(table);
46 dbMgr->dropTable("t1");
47 return 4;
49 conn.commit();
50 printf("NULL value can not be stored\n");
51 printf("Test passed\n");
52 dbMgr->closeTable(table);
53 dbMgr->dropTable("t1");
54 conn.close();
55 return 0;