printf ("\n============ Update Rows ============\n");
printf (" Update single route 192.168.1.0/24 by Primary Key: set flags ->1\n");
route.prefix = IP4ADDR(192,168,1,0);
route.mask = 24;
route.flags = 1;
if (!optimize) {
ret = cross_dbUpdRowByPK (hRtTbl, &route, "flags", &route, 0);
} else {
ret = cross_dbUpdRowByPK (hRtTbl, &route, hFlagsFlds, &route, 0);
}
CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key");
// verify
route.flags = 0;
ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0);
EXPECT (route.flags, 1, " Update flags");
DUMP_ROUTE (" Get single route: ", route);
printf (" Update single route 192.168.1.0/24 by Primary Key: update whole row\n");
route.prefix = IP4ADDR(192,168,1,0);
route.mask = 24;
ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0);
CHECK (ret, "Failed to get route 192.168.1.0/24 by PrimaryKey");
route.flags = 2;
route.metric = 2;
ret = cross_dbUpdRowByPK (hRtTbl, &route, NULL, &route, 0);
CHECK (ret, "Failed to update route 192.168.1.0/24 by Primary Key");
// verify
route.flags = 0;
ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0);
EXPECT (route.flags, 2, " Update flags");
EXPECT (route.metric, 2, " Update metric");
DUMP_ROUTE (" Get single route: ", route);
printf (" Use Replace to Update single route 192.168.1.0/24 by Primary Key: set flags ->3\n");
route.prefix = IP4ADDR(192,168,1,0);
route.mask = 24;
route.flags = 3;
ret = cross_dbReplaceRow (hRtTbl, &route, 0);
CHECK (ret, "Failed to replace route 192.168.1.0/24");
// verify
route.flags = 0;
ret = cross_dbGetRowByPK (hRtTbl, &route, &route, 0);
EXPECT (route.flags, 3, " Update flags");
DUMP_ROUTE (" Get single route: ", route);
// Update routes where nexthop=10.1.2.254: set flags 0->4
route.nexthop = IP4ADDR(10,1,2,254);
route.flags = 4;
if (!optimize) {
count = cross_dbUpdateRows (hRtTbl, "nexthop", &route, "flags", &route, 0);
} else {
count = cross_dbUpdateRows (hRtTbl, hNexthopMat, &route, hFlagsFlds, &route, 0);
}
EXPECT (count, 2, " Update nexthop=10.1.2.254 set flags=4 rows");
// Update All routes set flags 0->5
route.flags = 5;
if (!optimize) {
count = cross_dbUpdateRows (hRtTbl, NULL, NULL, "flags", &route, 0);
} else {
count = cross_dbUpdateRows (hRtTbl, NULL, NULL, hFlagsFlds, &route, 0);
}
EXPECT (count, 3, " Update all routes set flags=4 rows");