bool Schema::load() { string currentPath = ""; Directory::get_current_path(currentPath); string schema_abs_path = currentPath + schema_file; if (false == File::exist(schema_abs_path)) { Log::get_instance().log().error("load schema file, schema file not exist. file path:%s.", schema_abs_path.c_str()); return false; } TiXmlDocument doc_patterns(schema_abs_path.c_str()); if(false == doc_patterns.LoadFile()) { Log::get_instance().log().error("load schema file, load file failure. file:%s, error info:%s.", schema_abs_path.c_str(), doc_patterns.ErrorDesc()); return false; } TiXmlElement *root_element = doc_patterns.RootElement(); if(root_element == NULL) { Log::get_instance().log().error("get root element failure."); return false; } if(false == load_schema(root_element)) { Log::get_instance().log().error("load servers element failure."); return false; } return true; }
/** * main -- */ int main(int argc, char* argv[]) { int ret, ch, i; ret = 0; progname = argv[0]; while ((ch = getopt(argc, argv, "s:h:c:C:r:R:")) != EOF) switch (ch) { case 's': schema_dir = optarg; load_schema(optarg); break; case 'c': /*create <tablename> */ ret = create(optarg); break; case 'C': /*Create all*/ ret = create_all(); break; case 'r': /*recover <filename> */ ret = recover(optarg); break; case 'R': /*recover_all <MAXFILES> */ ret = sscanf(optarg,"%i", &i); if(ret != 1) return -1; ret = recover_all(i); break; case 'h': db_home = optarg; break; case '?': default: return(usage()); } argc -= optind; argv += optind; /*free mem; close open files.*/ cleanup(); return ret; }
/* lookup an attribute for a given type and attr value, auto-loading the schema if necessary */ char *vstream_schema_attrib(int type, int attr) { (void) vstream_schema_type(type); if (type >= MAX_TYPES) { vstream_error("Invalid type %d in vstream_schema_attrib\n", type); return "UNKNOWN"; } if (attr >= MAX_ATTRS) { vstream_error("Invalid attr %d in vstream_schema_attrib\n", attr); return "UNKNOWN"; } if (!attrs[type][attr].name) { load_schema(type); } if (!attrs[type][attr].name) { attrs[type][attr].name = malloc(18); snprintf(attrs[type][attr].name, 18, "UNKNOWN(%d,%d)", type, attr); } return attrs[type][attr].name; }