uint32_t sdbtGetRecordCount(db_descriptor * db) { uint32_t recordCnt = 0; char * rec; uint32_t context; rec = SDB_GET_FIRST_RECORD(db, &context); while (rec != NULL) { recordCnt++; rec = SDB_GET_NEXT_RECORD(db, &context); } return recordCnt; }
groupRecord_t * groupListGetNextGroup(uint32_t *context) { char * rec; groupRecord_t *group; do { rec = SDB_GET_NEXT_RECORD(db,context); if (rec == NULL) { return NULL; } group = groupListParseRecord(rec); } while (group == NULL); //in case of a bad-format record - skip it and read the next one return group; }
bool sdb_consolidate_db(db_descriptor ** _db) { _db_descriptor * db = *_db; _db_descriptor * tempDb; void * rec; uint32_t context; int rc; char tempfilename[MAX_SUPPORTED_FILENAME + TEMP_FILENAME_EXTENTION_LENGTH + 1]; strcpy(tempfilename, db->name); strcat(tempfilename, ".tmp"); rc = remove(tempfilename); if ((rc != 0) && (errno != ENOENT)) { return FALSE; } tempDb = sdb_init_db(tempfilename, db->get_record_size, db->check_deleted, db->check_ignore, db->mark_deleted, db->consolidation_processing, db->type, db->bin_header_size); if (tempDb == NULL) { return FALSE; } db->check_ignore = NULL; //only deleted lines should be removed. Ignored lines should stay. rec = SDB_GET_FIRST_RECORD(db, &context); rc = TRUE; while ((rec != NULL) && (rc == TRUE)) { if (db->consolidation_processing != NULL) { rc = db->consolidation_processing(tempDb, rec); // devListErrorComment(tempDb, rec); } else { rc = sdb_add_record(tempDb, rec); } rec = SDB_GET_NEXT_RECORD(db, &context); } strcpy(tempfilename, db->name); sdb_release_db(_db); (*_db) = tempDb; rc = remove(tempfilename); if (rc != 0) { return FALSE; } rc = sdb_rename_db(*_db, tempfilename); return rc; }