📄 insertnulltest1.c
字号:
#include<CSql.h>int main(){ Connection conn; DbRetVal rv = conn.open("root", "manager"); if (rv != OK) return 1; DatabaseManager *dbMgr = conn.getDatabaseManager(); if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} TableDef tabDef; tabDef.addField("f1", typeInt, 0, NULL, true); tabDef.addField("f2", typeInt); tabDef.addField("f3", typeString, 20); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } printf("Table created\n"); Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); dbMgr->dropTable("t1"); conn.close(); return -1; } int id1 = 0, id2 = 5; char name[20] = "PRAVEEN"; table->bindFld("f1", &id1); table->bindFld("f2", &id2); table->bindFld("f3", name); int icount =0; for (int i = 0 ; i < 10 ; i++) { conn.startTransaction(); id1= i; if (i%2 == 0) table->markFldNull(2); rv = table->insertTuple(); if (rv != OK) break; if (i%2 == 0) table->clearFldNull(2); icount++; conn.commit(); } printf("Tuples inserted in 1/txn is %d\n", icount); table->setCondition(NULL); rv = table->execute(); if (rv != OK) { dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); } void *tuple = NULL; while(true) { tuple = (char*)table->fetch() ; if (tuple == NULL) {break;} if (table->isFldNull(1)) printf("Column 1 is null\n"); if (table->isFldNull(2)) printf("Column 2 is null\n"); if (table->isFldNull(3)) printf("Column 3 is null\n"); printf("Binded Tuple value is %d %d %s \n", id1, id2, name); } table->close(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -