static PyObject * make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind) { switch (kind) { case iter_items: { gdbpy_ref<> key (field_name (type, i)); if (key == NULL) return NULL; gdbpy_ref<> value (convert_field (type, i)); if (value == NULL) return NULL; gdbpy_ref<> item (PyTuple_New (2)); if (item == NULL) return NULL; PyTuple_SET_ITEM (item.get (), 0, key.release ()); PyTuple_SET_ITEM (item.get (), 1, value.release ()); return item.release (); } case iter_keys: return field_name (type, i); case iter_values: return convert_field (type, i); } gdb_assert_not_reached ("invalid gdbpy_iter_kind"); }
// saving data to DS bool Fl_Combo_Box::save_data(Fl_Data_Source *ds) { if (field_name().empty()) return false; Fl_Variant fld_value; fld_value.set_int(value()); return ds->write_field(field_name().c_str(), fld_value); }
// Data source support // loading data from DS bool Fl_Combo_Box::load_data(Fl_Data_Source *ds) { if (field_name().empty()) return false; Fl_Variant fld_value; if (ds->read_field(field_name().c_str(), fld_value)) { value(fld_value.as_int()); return true; } return false; }
int tLuaObject::generic_index(lua_State *L) { tLuaObject* lua_obj = tLuaObject::getObject(L, index_table_param); // gets the field name tStringBuffer field_name(lua_tostring(L, index_index_param)); // finds in the method table tMethodType method_type; tLuaObjectMethod method; bool found = lua_obj->method_table.FindMethod(field_name, &method, &method_type); if(!found) return lua_obj->index(L); // calls method switch(method_type) { case FUNC: lua_pushlightuserdata(L, (void *) method); lua_pushcclosure(L, closure, 1); return 1; break; default: return method(lua_obj, L); break; } }
int main (int argc, char ** argv) { if (pcl::console::find_argument (argc, argv, "-h") != -1) usage (argv); float min_v = 0.0f, max_v = 5.0f; pcl::console::parse_2x_arguments (argc, argv, "-minmax", min_v, max_v); std::string field_name ("z"); pcl::console::parse_argument (argc, argv, "-field", field_name); PCL_INFO ("Filtering data on %s between %f -> %f.\n", field_name.c_str (), min_v, max_v); float leaf_x = 0.01f, leaf_y = 0.01f, leaf_z = 0.01f; pcl::console::parse_3x_arguments (argc, argv, "-leaf", leaf_x, leaf_y, leaf_z); PCL_INFO ("Using %f, %f, %f as a leaf size for VoxelGrid.\n", leaf_x, leaf_y, leaf_z); pcl::OpenNIGrabber grabber (""); if (grabber.providesCallback<pcl::OpenNIGrabber::sig_cb_openni_point_cloud_rgba> ()) { OpenNIVoxelGrid<pcl::PointXYZRGBA> v ("", field_name, min_v, max_v, leaf_x, leaf_y, leaf_z); v.run (); } else { OpenNIVoxelGrid<pcl::PointXYZ> v ("", field_name, min_v, max_v, leaf_x, leaf_y, leaf_z); v.run (); } return (0); }
BOOST_FOREACH(const CMap::value_type &vt, keep_columns) { string field_name(vt.first.substr(2)); string output_field_xml; if (prefixequal(vt.first, "a.") && a_name_to_val_pos.exists(field_name)) { // case 1 TINVARIANT(a_series.getTypePtr()->hasColumn(field_name)); output_field_xml = renameField(a_series.getTypePtr(), field_name, vt.second); extractors.push_back (ExtractorValue::make(vt.second, a_name_to_val_pos[field_name])); } else if (prefixequal(vt.first, "a.") && eq_columns.find(field_name) != eq_columns.end()) { // case 2a const string b_field_name(eq_columns.find(field_name)->second); TINVARIANT(b_series.getTypePtr()->hasColumn(b_field_name)); output_field_xml = renameField(a_series.getTypePtr(), field_name, vt.second); GeneralField::Ptr b_field(GeneralField::make(b_series, b_field_name)); extractors.push_back(ExtractorField::make(vt.second, b_field)); } else if (prefixequal(vt.first, "b.") && b_series.getTypePtr()->hasColumn(field_name)) { // case 2b output_field_xml = renameField(b_series.getTypePtr(), field_name, vt.second); GeneralField::Ptr b_field(GeneralField::make(b_series, field_name)); extractors.push_back(ExtractorField::make(vt.second, b_field)); } else { requestError("invalid extraction"); } output_xml.append(output_field_xml); }
Handle<Value> FieldDefn::New(const Arguments& args) { HandleScope scope; if (!args.IsConstructCall()) { return NODE_THROW("Cannot call constructor as function, you need to use 'new' keyword"); } if (args[0]->IsExternal()) { Local<External> ext = Local<External>::Cast(args[0]); void* ptr = ext->Value(); FieldDefn *f = static_cast<FieldDefn *>(ptr); f->Wrap(args.This()); return args.This(); } else { std::string field_name(""); std::string type_name("string"); NODE_ARG_STR(0, "field name", field_name); NODE_ARG_STR(1, "field type", type_name); int field_type = getFieldTypeByName(type_name); if (field_type < 0) { return NODE_THROW("Unrecognized field type"); } FieldDefn* def = new FieldDefn(new OGRFieldDefn(field_name.c_str(), static_cast<OGRFieldType>(field_type))); def->owned_ = true; def->Wrap(args.This()); } return args.This(); }
/* Return field string */ static inline const char *field_str(unsigned int index) { /* count(id) for special COUNT attribute */ if (index == ATTR_INDEX_FLG_COUNT) return "id"; else return field_name(index); }
BOOST_FOREACH(const CMap::value_type &vt, keep_columns) { if (prefixequal(vt.first, "a.")) { string field_name(vt.first.substr(2)); if (!known_a_eq_fields.exists(field_name)) { // don't store eq fields we will // access from the b eq fields a_name_to_val_pos[field_name] = a_val_fields.size(); a_val_fields.push_back(GeneralField::make(a_series, field_name)); } } }
virtual void firstExtent(const Extent &e) { series.setType(e.getTypePtr()); const ExtentType::Ptr extent_type(e.getTypePtr()); fields.reserve(extent_type->getNFields()); for (uint32_t i = 0; i < extent_type->getNFields(); ++i) { string field_name(extent_type->getFieldName(i)); fields.push_back(GeneralField::make(series, field_name)); into.columns.push_back(TableColumn(field_name, extent_type->getFieldTypeStr(field_name))); } into.__isset.columns = true; }
static PyObject * make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind) { PyObject *item = NULL, *key = NULL, *value = NULL; switch (kind) { case iter_items: key = field_name (type, i); if (key == NULL) goto fail; value = convert_field (type, i); if (value == NULL) goto fail; item = PyTuple_New (2); if (item == NULL) goto fail; PyTuple_SET_ITEM (item, 0, key); PyTuple_SET_ITEM (item, 1, value); break; case iter_keys: item = field_name (type, i); break; case iter_values: item = convert_field (type, i); break; default: gdb_assert_not_reached ("invalid gdbpy_iter_kind"); } return item; fail: Py_XDECREF (key); Py_XDECREF (value); Py_XDECREF (item); return NULL; }
static Datum bson_get(PG_FUNCTION_ARGS) { bytea* arg = GETARG_BSON(0); mongo::BSONObj object(VARDATA_ANY(arg)); text* arg2 = PG_GETARG_TEXT_P(1); std::string field_name(VARDATA(arg2), VARSIZE(arg2)-VARHDRSZ); PGBSON_LOG << "bson_get: field: " << field_name << PGBSON_ENDL; mongo::BSONElement e = object.getFieldDotted(field_name); if (e.eoo()) { PGBSON_LOG << "bson_get: no such field" << PGBSON_ENDL; // no such element PG_RETURN_NULL(); } else { try { return convert_element<FieldType>(fcinfo, e); } catch(const convertion_error& ex) { ereport( ERROR, ( errcode(ERRCODE_INTERNAL_ERROR), errmsg("Field %s is of type %s and can not be converted to %s", field_name.c_str(), bson_type_name(e), ex.target_type) ) ); } catch(const std::exception& ex) { ereport( ERROR, ( errcode(ERRCODE_INTERNAL_ERROR), errmsg("Error converting filed %s of type %s: %s", field_name.c_str(), bson_type_name(e), ex.what()) ) ); } } }
bool cProject::load_infoFile() { QFile infoFile(m_infoFile); if(!infoFile.open(QIODevice::ReadOnly)) return false; QFileInfo finfo(infoFile); m_rootDir = finfo.absoluteDir(); QString raw_data(infoFile.readAll()); QStringList data_lines(raw_data.split("\n")); if(data_lines.count() < 3) return false; QStringList field_id(data_lines[0].split(":")); QStringList field_name(data_lines[1].split(":")); QStringList field_maintainer(data_lines[2].split(":")); if((field_id.count() != 2) || (field_name.count()!= 2) || (field_maintainer.count() != 2) ) return false; if(field_id[0]!="PROJECT-ID") return false; m_id = field_id[1]; m_name = field_name[1]; m_maintainer = field_maintainer[1]; return true; }
static rapidjson::Value* parse_msg(const Message *msg, rapidjson::Value::AllocatorType& allocator) { const Descriptor *d = msg->GetDescriptor(); if (!d) return NULL; size_t count = d->field_count(); rapidjson::Value* root = new rapidjson::Value(rapidjson::kObjectType); if (!root) return NULL; for (size_t i = 0; i != count; ++i) { const FieldDescriptor *field = d->field(i); if (!field){ delete root; return NULL; } const Reflection *ref = msg->GetReflection(); if (!ref) { delete root; return NULL; } if (field->is_optional() && !ref->HasField(*msg, field)) { //do nothing } else { rapidjson::Value* field_json = field2json(msg, field, allocator); rapidjson::Value field_name(field->name().c_str(), field->name().size()); root->AddMember(field_name, *field_json, allocator); delete field_json; } } return root; }
int scalar_derefs1 ( FILE * fp , node_t * node, int direction ) { node_t * p ; int tag ; char fname[NAMELEN] ; if ( node == NULL ) return(1) ; for ( p = node->fields ; p != NULL ; p = p->next ) { if ( p->node_kind & I1 ) continue ; /* short circuit any field that is not state */ /* short circuit DERIVED types */ if ( p->type->type_type == DERIVED ) continue ; /* short circuit non-scalars */ if ( p->ndims > 0 ) continue ; if ( ( (p->node_kind & FIELD ) /* it is not a derived type -ajb */ || (p->node_kind & FIELD && (p->type->type_type != DERIVED) ) ) ) { for ( tag = 1 ; tag <= p->ntl ; tag++ ) { strcpy(fname,field_name(t4,p,(p->ntl>1)?tag:0)) ; /* generate deref */ if ( direction == DIR_COPY_OUT ) { fprintf(fp, " grid%%%s = %s\n",fname,fname ) ; } else { fprintf(fp, " %s = grid%%%s\n",fname,fname ) ; } } } } return(0) ; }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Gets a tag field using a delimited block.field path. </summary> /// /// <param name="source_definition"> [in] The tag definition to search in. </param> /// <param name="field_type"> Type of the field to get. </param> /// <param name="field_path"> Full path of the field. </param> /// /// <returns> The found tag field. </returns> static tag_field& GetTagField(tag_block_definition& source_definition, Enums::field_type field_type, const std::string& field_path) { // Split the field path into block names // The last name is the field name so is not added to the list std::vector<std::string> block_names; std::string field_name(field_path); int seperator_index = 0; while(field_name.length() != 0) { int seperator_index = field_name.find(":"); if(seperator_index == std::string::npos) { break; } block_names.push_back(field_name.substr(0, seperator_index)); field_name.replace(0, seperator_index + 1, ""); } // Navigate through the block definitions auto* current_block = &source_definition; for(auto& block_field_name : block_names) { int found_block_field = current_block->FindFieldIndex(Enums::_field_block, block_field_name.c_str()); assert(found_block_field != NONE); current_block = current_block->fields[found_block_field].Definition<tag_block_definition>(); } // Get the targeted field int found_field_index = current_block->FindFieldIndex(field_type, field_name.c_str()); assert(found_field_index != NONE); return current_block->fields[found_field_index]; }
bool SuifPrinterModule::parse_and_print(ostream& output, const ObjectWrapper &obj, const LString &name, const String &str, int _indent, int deref = 0) { const Address what = obj.get_address(); const MetaClass *type = obj.get_meta_class(); // ObjectWrapper obj(what, type); //output << "str:deref = " << deref << endl; int l_sep = list_separator; if (str.length() == 0) { return false; } if (deref) _indent -= istep; int str_length = str.length(); bool need_indent = false; bool first_field = true; for (int i = 0; i < str_length; ++i) { if (str[i] != '%') { // If there are less than 2 extra stars don't print anything but the // fields. if (deref < 2) { // Need to check for \n and take care of indentation here switch(str[i]) { case '\n': output << str[i]; if (str[i+1]) { need_indent = true; indent(output, _indent); } break; case '\t': indent(output, istep); break; case '\b': _indent -= istep; break; default: output << str[i]; } } } else { ++i; if (str[i] == '%') { // Double % means print out a '%' output << '%'; } else { // This has to be cleaned up a bit ... //int field_deref = deref?deref-1:0; int field_deref = 0; char buff[256]; int j = 0; char c = str[i++]; if (c == '*') { ++field_deref; while ((c = str[i++]) == '*') ++ field_deref; } while (isalnum(c) || c == '_') { buff[j++] = c; c = str[i++]; } i -= 2; buff[j] = 0; // Now retrieve the particular field and print it. if (!strcmp(buff, "Cl")) { output << type->get_instance_name() << '(' << type->get_meta_class_id() << ") "; } else if (!strcmp(buff, "ii")) { // Deal with printing IInteger IInteger *ii = (IInteger *)what; output << ii->to_String().c_str(); } else if (!strcmp(buff, "i")) { // Deal with printing int output << *(int*)what; } else if (!strcmp(buff, "f")) { // float output << *(float*)what; } else if (!strcmp(buff, "d")) { // double output << *(double*)what; } else if (!strcmp(buff, "c")) { // char output << *(char*)what; } else if (!strcmp(buff, "b")) { // byte output << (int)*(char*)what; } else if (!strcmp(buff, "B")) { // bool output << *(bool*)what; } else if (!strcmp(buff, "ls")) { // Deal with printing LStrings LString str = *(LString*) what; output << str; } else if (!strcmp(buff, "s")) { // Deal with printing Strings String str = *(String*) what; output << str; } else if (!strcmp(buff, "n")) { // Deal with name of field if (!deref) output << name; } else if (!strcmp(buff, "P")) { if (obj.is_null()) output << "NULL"; else { PointerWrapper ptr_obj(obj); ObjectWrapper base_obj = ptr_obj.dereference(); if (ptr_obj.get_meta_class()->is_owning_pointer()) { size_t ref = retrieve_tag(obj.get_object()); output << "t" << ref<< ": "; print2(output, base_obj, emptyLString, _indent+istep, field_deref); } else { print_pointer(output, ptr_obj, emptyLString, _indent, deref); } } } else if (!strcmp(buff, "R")) { // print the ref # if (!what) output << "NULL"; else { // PointerMetaClass *p = (PointerMetaClass*) type; // const Address baseAddr = *(Address*) type; //ObjectWrapper obj(what, type); size_t ref = retrieve_tag(obj); output << "t" << ref<< ": "; } } else if (!strcmp(buff, "LS")) { list_separator = ' '; } else if (!strcmp(buff, "LN")) { list_separator = '\n'; } else if (!strcmp(buff, "LC")) { list_separator = ','; } else if (!strcmp(buff, "ANNOTES")) { // Special CASE for handling ANNOTATIONS AggregateWrapper agg(obj); LString field_name("_annotes"); FieldDescription *f = agg.get_field_description(field_name); if (!f) cerr << type->get_meta_class(what)->get_class_name() << ":No field '" << field_name << "' found to print!!!\n"; else { // Now we need to get the field offset and increment 'what' if (field_deref != 0) cerr << "Extra '*' for %ANNOTES\n"; FieldWrapper field = agg.get_field(field_name); if (need_indent) { indent(output, istep); need_indent = false; } char old_sep = list_separator; list_separator = '\n'; print2(output, field.get_object(), field_name, _indent+istep, 1); list_separator = old_sep; } } else if (j) { // Retrieve the field mentioned // The following cast works as we should reach here only if it // is not an elementary or pointer type. AggregateWrapper agg(obj); char *bf = buff; LString field_name(bf); FieldDescription *f = agg.get_field_description(field_name); if (!f) cerr << type->get_meta_class(what)->get_class_name() << ":No field '" << field_name << "' found to print!!!\n"; else { // Now we need to get the field offset and increment 'what' if (deref) if (!first_field) output << ' '; else first_field = false; FieldWrapper field = agg.get_field(field_name); //char *f_add = (char*)what + f->get_offset(); //indent(output, _indent+istep); if (need_indent) { indent(output, istep); need_indent = false; } if (deref && !field_deref) field_deref = deref - 1; //output << "\tstr:field_deref = " << field_deref << endl; print2(output, field.get_object(), field_name, _indent+istep, field_deref); } } } } } list_separator = l_sep; return true; }
int gen_args1 ( FILE * fp , char * outstr , char * structname , node_t * node , int *linelen , int sw , int deep ) { node_t * p ; int tag ; char post[NAMELEN] ; char fname[NAMELEN] ; char x[NAMELEN], y[NAMELEN] ; char indices[NAMELEN] ; int lenarg ; int only4d = 0 ; if ( sw == ACTUAL_NEW ) { sw = ACTUAL ; only4d = 1 ; } if ( sw == DUMMY_NEW ) { sw = DUMMY ; only4d = 1 ; } if ( node == NULL ) return(1) ; for ( p = node->fields ; p != NULL ; p = p->next ) { if ( p->node_kind & I1 ) continue ; /* short circuit any field that is not state */ /* short circuit scalars; shortening argument lists */ if ( p->ndims == 0 && p->type->type_type != DERIVED && sw_limit_args ) continue ; if ( ( (p->node_kind & FOURD) /* scalar arrays or */ /* it is not a derived type -ajb */ || (p->node_kind & FIELD && (p->type->type_type != DERIVED) ) ) ) { if (!only4d || (p->node_kind & FOURD) || associated_with_4d_array(p) ) { if ( p->node_kind & FOURD ) { sprintf(post,",1)") ; } else if ( p->boundary_array ) { sprintf(post,")") ; } else { sprintf(post,")") ; } for ( tag = 1 ; tag <= p->ntl ; tag++ ) { /* if this is a core-specific variable, prepend the name of the core to */ /* the variable at the driver level */ if ( p->boundary_array && sw_new_bdys ) { int bdy ; for ( bdy = 1 ; bdy <= 4 ; bdy++ ) { strcpy(fname,field_name_bdy(t4,p,(p->ntl>1)?tag:0,bdy)) ; strcpy(indices,"") ; if ( sw_deref_kludge && sw==ACTUAL ) sprintf(indices, "%s",index_with_firstelem("(","",bdy,t2,p,post)) ; /* generate argument */ strcpy(y,structname) ; strcat(y,fname) ; strcat(y,indices) ; strcat(y,",") ; lenarg = strlen(y) ; if ( lenarg+*linelen > MAX_ARGLINE ) { strcat(outstr," &\n") ; *linelen = 0 ; } strcat(outstr,y) ; *linelen += lenarg ; } } else { strcpy(fname,field_name(t4,p,(p->ntl>1)?tag:0)) ; strcpy(indices,"") ; if ( sw_deref_kludge && sw==ACTUAL ) sprintf(indices, "%s",index_with_firstelem("(","",-1,t2,p,post)) ; /* generate argument */ strcpy(y,structname) ; strcat(y,fname) ; strcat(y,indices) ; strcat(y,",") ; lenarg = strlen(y) ; if ( lenarg+*linelen > MAX_ARGLINE ) { strcat(outstr," &\n") ; *linelen = 0 ; } strcat(outstr,y) ; *linelen += lenarg ; } } } } if ( p->type != NULL ) { if ( p->type->type_type == DERIVED && !only4d ) { if ( deep ) { sprintf(x,"%s%s%%",structname,p->name ) ; gen_args1(fp, outstr, (sw==ACTUAL)?x:"", p->type,linelen,sw,deep) ; } else { /* generate argument */ strcpy(y,structname) ; strcat(y,p->name) ; strcat(y,",") ; lenarg = strlen(y) ; if ( lenarg+*linelen > MAX_ARGLINE ) { strcat(outstr," &\n") ; *linelen = 0 ; } strcat(outstr,y) ; *linelen += lenarg ; p->mark = 1 ; } } } } return(0) ; }
//! ofObject = true => returns list of objects this object depends on //! ofObject = false => returns list of objects that depend on this object void MetadataItem::getDependencies(std::vector<Dependency>& list, bool ofObject) { DatabasePtr d = getDatabase(); int mytype = -1; // map DBH type to RDB$DEPENDENT TYPE NodeType dep_types[] = { ntTable, ntView, ntTrigger, ntUnknown, ntUnknown, ntProcedure,ntUnknown, ntException,ntUnknown, ntUnknown, ntUnknown, ntUnknown, ntUnknown, ntUnknown, ntGenerator, ntFunction }; int type_count = sizeof(dep_types)/sizeof(NodeType); for (int i = 0; i < type_count; i++) if (typeM == dep_types[i]) mytype = i; // system tables should be treated as tables if (typeM == ntSysTable) mytype = 0; int mytype2 = mytype; // views count as relations(tables) when other object refer to them if (mytype == 1 && !ofObject) mytype2 = 0; if (typeM == ntUnknown || mytype == -1) throw FRError(_("Unsupported type")); IBPP::Database& db = d->getIBPPDatabase(); IBPP::Transaction tr1 = IBPP::TransactionFactory(db, IBPP::amRead); tr1->Start(); IBPP::Statement st1 = IBPP::StatementFactory(db, tr1); wxString o1 = (ofObject ? "DEPENDENT" : "DEPENDED_ON"); wxString o2 = (ofObject ? "DEPENDED_ON" : "DEPENDENT"); wxString sql = "select RDB$" + o2 + "_TYPE, RDB$" + o2 + "_NAME, RDB$FIELD_NAME \n " " from RDB$DEPENDENCIES \n " " where RDB$" + o1 + "_TYPE in (?,?) and RDB$" + o1 + "_NAME = ? \n "; int params = 1; if ((typeM == ntTable || typeM == ntSysTable || typeM == ntView) && ofObject) // get deps for computed columns { // view needed to bind with generators sql += " union \n" " SELECT DISTINCT d.rdb$depended_on_type, d.rdb$depended_on_name, d.rdb$field_name \n" " FROM rdb$relation_fields f \n" " LEFT JOIN rdb$dependencies d ON d.rdb$dependent_name = f.rdb$field_source \n" " WHERE d.rdb$dependent_type = 3 AND f.rdb$relation_name = ? \n"; params++; } if (!ofObject) // find tables that have calculated columns based on "this" object { sql += "union \n" " SELECT distinct cast(0 as smallint), f.rdb$relation_name, f.rdb$field_name \n" " from rdb$relation_fields f \n" " left join rdb$dependencies d on d.rdb$dependent_name = f.rdb$field_source \n" " where d.rdb$dependent_type = 3 and d.rdb$depended_on_name = ? "; params++; } // get the exact table and fields for views // rdb$dependencies covers deps. for WHERE clauses in SELECTs in VIEW body // but we also need mapping for column list in SELECT. These 2 queries cover it: if (ofObject && typeM == ntView) { sql += " union \n" " select distinct cast(0 as smallint), vr.RDB$RELATION_NAME, f.RDB$BASE_FIELD \n" " from RDB$RELATION_FIELDS f \n" " join RDB$VIEW_RELATIONS vr on f.RDB$VIEW_CONTEXT = vr.RDB$VIEW_CONTEXT \n" " and f.RDB$RELATION_NAME = vr.RDB$VIEW_NAME \n" " where f.rdb$relation_name = ? \n"; params++; } // views can depend on other views as well // we might need to add procedures here one day when Firebird gains support for it if (!ofObject && (typeM == ntView || typeM == ntTable || typeM == ntSysTable)) { sql += " union \n" " select distinct cast(0 as smallint), f.RDB$RELATION_NAME, f.RDB$BASE_FIELD \n" " from RDB$RELATION_FIELDS f \n" " join RDB$VIEW_RELATIONS vr on f.RDB$VIEW_CONTEXT = vr.RDB$VIEW_CONTEXT \n" " and f.RDB$RELATION_NAME = vr.RDB$VIEW_NAME \n" " where vr.rdb$relation_name = ? \n"; params++; } sql += " order by 1, 2, 3"; st1->Prepare(wx2std(sql, d->getCharsetConverter())); st1->Set(1, mytype); st1->Set(2, mytype2); for (int i = 0; i < params; i++) st1->Set(3 + i, wx2std(getName_(), d->getCharsetConverter())); st1->Execute(); MetadataItem* last = 0; Dependency* dep = 0; while (st1->Fetch()) { int object_type; st1->Get(1, &object_type); if (object_type > type_count) // some system object, not interesting for us continue; NodeType t = dep_types[object_type]; if (t == ntUnknown) // ditto continue; std::string objname_std; st1->Get(2, objname_std); wxString objname(std2wxIdentifier(objname_std, d->getCharsetConverter())); MetadataItem* current = d->findByNameAndType(t, objname); if (!current) { if (t == ntTable) { // maybe it's a view masked as table current = d->findByNameAndType(ntView, objname); // or possibly a system table if (!current) current = d->findByNameAndType(ntSysTable, objname); } if (!ofObject && t == ntTrigger) { // system trigger dependent of this object indicates possible check constraint on a table // that references this object. So, let's check if this trigger is used for check constraint // and get that table's name IBPP::Statement st2 = IBPP::StatementFactory(db, tr1); st2->Prepare( "select r.rdb$relation_name from rdb$relation_constraints r " " join rdb$check_constraints c on r.rdb$constraint_name=c.rdb$constraint_name " " and r.rdb$constraint_type = 'CHECK' where c.rdb$trigger_name = ? " ); st2->Set(1, objname_std); st2->Execute(); if (st2->Fetch()) // table using that trigger found { std::string s; st2->Get(1, s); wxString tablecheck(std2wxIdentifier(s, d->getCharsetConverter())); if (getName_() != tablecheck) // avoid self-reference current = d->findByNameAndType(ntTable, tablecheck); } } if (!current) continue; } if (current != last) // new object { Dependency de(current); list.push_back(de); dep = &list.back(); last = current; } if (!st1->IsNull(3)) { std::string s; st1->Get(3, s); dep->addField(std2wxIdentifier(s, d->getCharsetConverter())); } } // TODO: perhaps this could be moved to Table? // call MetadataItem::getDependencies() and then add this if ((typeM == ntTable || typeM == ntSysTable) && ofObject) // foreign keys of this table + computed columns { Table *t = dynamic_cast<Table *>(this); std::vector<ForeignKey> *f = t->getForeignKeys(); for (std::vector<ForeignKey>::const_iterator it = f->begin(); it != f->end(); ++it) { MetadataItem *table = d->findByNameAndType(ntTable, (*it).getReferencedTable()); if (!table) { throw FRError(wxString::Format(_("Table %s not found."), (*it).getReferencedTable().c_str())); } Dependency de(table); de.setFields((*it).getReferencedColumns()); list.push_back(de); } // Add check constraints here (CHECKS are checked via system triggers), example: // table1::check( table1.field1 > select max(field2) from table2 ) // So, table vs any object from this ^^^ select // Algorithm: 1.find all system triggers bound to that CHECK constraint // 2.find dependencies for those system triggers // 3.display those dependencies as deps. of this table st1->Prepare("select distinct c.rdb$trigger_name from rdb$relation_constraints r " " join rdb$check_constraints c on r.rdb$constraint_name=c.rdb$constraint_name " " and r.rdb$constraint_type = 'CHECK' where r.rdb$relation_name= ? " ); st1->Set(1, wx2std(getName_(), d->getCharsetConverter())); st1->Execute(); std::vector<Dependency> tempdep; while (st1->Fetch()) { std::string s; st1->Get(1, s); Trigger t(d->shared_from_this(), std2wxIdentifier(s, d->getCharsetConverter())); t.getDependencies(tempdep, true); } // remove duplicates, and self-references from "tempdep" while (true) { std::vector<Dependency>::iterator to_remove = tempdep.end(); for (std::vector<Dependency>::iterator it = tempdep.begin(); it != tempdep.end(); ++it) { if ((*it).getDependentObject() == this) { to_remove = it; break; } to_remove = std::find(it + 1, tempdep.end(), (*it)); if (to_remove != tempdep.end()) break; } if (to_remove == tempdep.end()) break; else tempdep.erase(to_remove); } list.insert(list.end(), tempdep.begin(), tempdep.end()); } // TODO: perhaps this could be moved to Table? if ((typeM == ntTable || typeM == ntSysTable) && !ofObject) // foreign keys of other tables { st1->Prepare( "select r1.rdb$relation_name, i.rdb$field_name " " from rdb$relation_constraints r1 " " join rdb$ref_constraints c on r1.rdb$constraint_name = c.rdb$constraint_name " " join rdb$relation_constraints r2 on c.RDB$CONST_NAME_UQ = r2.rdb$constraint_name " " join rdb$index_segments i on r1.rdb$index_name=i.rdb$index_name " " where r2.rdb$relation_name=? " " and r1.rdb$constraint_type='FOREIGN KEY' " ); st1->Set(1, wx2std(getName_(), d->getCharsetConverter())); st1->Execute(); wxString lasttable; Dependency* dep = 0; while (st1->Fetch()) { std::string s; st1->Get(1, s); wxString table_name(std2wxIdentifier(s, d->getCharsetConverter())); st1->Get(2, s); wxString field_name(std2wxIdentifier(s, d->getCharsetConverter())); if (table_name != lasttable) // new { MetadataItem* table = d->findByNameAndType(ntTable, table_name); if (!table) continue; // dummy check Dependency de(table); list.push_back(de); dep = &list.back(); lasttable = table_name; } dep->addField(field_name); } } tr1->Commit(); }
/** * Builds a report from database. */ struct lmgr_report_t *ListMgr_Report(lmgr_t *p_mgr, const report_field_descr_t * report_desc_array, unsigned int report_descr_count, const profile_field_descr_t * profile_descr, const lmgr_filter_t *p_filter, const lmgr_iter_opt_t *p_opt) { unsigned int i; char attrname[128]; lmgr_report_t *p_report; int rc; table_enum query_tab; /* supported report fields: ENTRIES, ANNEX_INFO or ACCT */ bool use_acct_table = false; lmgr_iter_opt_t opt = { 0 }; unsigned int profile_len = 0; unsigned int ratio = 0; struct field_count fcnt = { 0 }; GString *req = NULL; GString *fields = NULL; GString *where = NULL; GString *having = NULL; GString *group_by = NULL; GString *order_by = NULL; GString *filter_name = NULL; /* check profile argument and increase output array if needed */ if (profile_descr != NULL) { if (profile_descr->attr_index != ATTR_INDEX_size) { DisplayLog(LVL_CRIT, LISTMGR_TAG, "Profile on attribute '%s' (index=%u) is not supported", field_name(profile_descr->attr_index), profile_descr->attr_index); return NULL; } profile_len = SZ_PROFIL_COUNT; if (profile_descr->range_ratio_len > 0) ratio = 1; } /* allocate a new report structure */ p_report = (lmgr_report_t *) MemAlloc(sizeof(lmgr_report_t)); if (!p_report) return NULL; p_report->p_mgr = p_mgr; p_report->result = (struct result *)MemCalloc(report_descr_count + profile_len + ratio, sizeof(struct result)); if (!p_report->result) goto free_report; p_report->result_count = report_descr_count + profile_len + ratio; p_report->profile_count = profile_len; p_report->ratio_count = ratio; if (profile_descr != NULL) p_report->profile_attr = ATTR_INDEX_size; /* initially, no char * tab allocated */ p_report->str_tab = NULL; if (p_opt) opt = *p_opt; fields = g_string_new(NULL); group_by = g_string_new(NULL); order_by = g_string_new(NULL); having = g_string_new(NULL); where = g_string_new(NULL); if (full_acct(report_desc_array, report_descr_count, p_filter) && !opt.force_no_acct) { listmgr_optimizedstat(p_report, p_mgr, report_descr_count, report_desc_array, profile_descr, fields, group_by, order_by, having, where); use_acct_table = true; } else { /* not only ACCT table */ /* sorting by ratio first */ if (profile_descr && profile_descr->range_ratio_len > 0) { if (profile_descr->attr_index == ATTR_INDEX_size) { coma_if_needed(order_by); if (profile_descr->range_ratio_sort == SORT_ASC) g_string_append(order_by, "sizeratio ASC"); else g_string_append(order_by, "sizeratio DESC"); } } for (i = 0; i < report_descr_count; i++) { /* no field for count or distinct count */ if (report_desc_array[i].report_type != REPORT_COUNT && report_desc_array[i].report_type != REPORT_COUNT_DISTINCT) { /* in what table is this field ? */ if (is_main_field(report_desc_array[i].attr_index)) fcnt.nb_main++; else if (is_annex_field(report_desc_array[i].attr_index)) fcnt.nb_annex++; else { /* Not supported yet */ DisplayLog(LVL_CRIT, LISTMGR_TAG, "Error: report on attribute '%s' (index=%u) is not supported (report item #%u).", field_name(report_desc_array[i].attr_index), report_desc_array[i].attr_index, i); rc = DB_NOT_SUPPORTED; goto free_str; } } sprintf(attrname, "attr%u", i); /* what kind of stat on this field ? */ switch (report_desc_array[i].report_type) { case REPORT_MIN: coma_if_needed(fields); g_string_append_printf(fields, "MIN(%s) as %s", field_str(report_desc_array[i]. attr_index), attrname); p_report->result[i].type = field_type(report_desc_array[i].attr_index); break; case REPORT_MAX: coma_if_needed(fields); g_string_append_printf(fields, "MAX(%s) as %s", field_str(report_desc_array[i]. attr_index), attrname); p_report->result[i].type = field_type(report_desc_array[i].attr_index); break; case REPORT_AVG: coma_if_needed(fields); g_string_append_printf(fields, "ROUND(AVG(%s)) as %s", field_str(report_desc_array[i]. attr_index), attrname); p_report->result[i].type = field_type(report_desc_array[i].attr_index); break; case REPORT_SUM: coma_if_needed(fields); g_string_append_printf(fields, "SUM(%s) as %s", field_str(report_desc_array[i]. attr_index), attrname); p_report->result[i].type = field_type(report_desc_array[i].attr_index); break; case REPORT_COUNT: coma_if_needed(fields); g_string_append_printf(fields, "COUNT(*) as %s", attrname); p_report->result[i].type = DB_BIGUINT; break; case REPORT_COUNT_DISTINCT: coma_if_needed(fields); g_string_append_printf(fields, "COUNT(DISTINCT(%s)) as %s", field_str(report_desc_array[i]. attr_index), attrname); p_report->result[i].type = DB_BIGUINT; break; case REPORT_GROUP_BY: coma_if_needed(fields); g_string_append_printf(fields, "%s as %s", field_str(report_desc_array[i]. attr_index), attrname); coma_if_needed(group_by); g_string_append(group_by, attrname); p_report->result[i].type = field_type(report_desc_array[i].attr_index); break; } /* is this field sorted ? */ append_sort_order(order_by, attrname, report_desc_array[i].sort_flag); /* is this field filtered ? */ listmgr_fieldfilter(p_report, p_mgr, report_desc_array, attrname, having, where, i); p_report->result[i].flags = field_flag(report_desc_array[i].attr_index); } /* generate size profile */ if (profile_descr != NULL) { if (profile_descr->attr_index == ATTR_INDEX_size) { coma_if_needed(fields); g_string_append(fields, "SUM(size=0)"); for (i = 1; i < SZ_PROFIL_COUNT - 1; i++) g_string_append_printf(fields, ",SUM(" SZRANGE_FUNC "(size)=%u)", i - 1); g_string_append_printf(fields, ",SUM(" SZRANGE_FUNC "(size)>=%u)", SZ_PROFIL_COUNT - 1); for (i = 0; i < SZ_PROFIL_COUNT; i++) p_report->result[i + report_descr_count].type = DB_BIGUINT; if (profile_descr->range_ratio_len > 0) { /* add ratio field and sort it */ coma_if_needed(fields); g_string_append_printf(fields, "SUM(size>=%llu", SZ_MIN_BY_INDEX(profile_descr-> range_ratio_start)); /* is the last range = 1T->inf ? */ if (profile_descr->range_ratio_start + profile_descr->range_ratio_len >= SZ_PROFIL_COUNT) g_string_append(fields, ")"); else g_string_append_printf(fields, " and size<%llu)", SZ_MIN_BY_INDEX(profile_descr->range_ratio_start + profile_descr->range_ratio_len)); g_string_append(fields, "/COUNT(*) as sizeratio"); } } } } /* process filter */ if (!(no_filter(p_filter))) { if (full_acct(report_desc_array, report_descr_count, p_filter) && !opt.force_no_acct) { int filter_acct; /* filter on acct fields only */ filter_acct = filter2str(p_mgr, where, p_filter, T_ACCT, (!GSTRING_EMPTY(where) ? AOF_LEADING_SEP : 0) | AOF_PREFIX); if (filter_acct > 0) use_acct_table = true; } else { /* process NAMES filters apart, as with must then join with * DISTINCT(id) */ filter_where(p_mgr, p_filter, &fcnt, where, (!GSTRING_EMPTY(where) ? AOF_LEADING_SEP : 0) | AOF_SKIP_NAME); filter_name = g_string_new(NULL); fcnt.nb_names = filter2str(p_mgr, filter_name, p_filter, T_DNAMES, 0); } } /* start building the whole request */ req = g_string_new("SELECT "); g_string_append_printf(req, "%s FROM ", fields->str); /* FROM clause */ if (use_acct_table) { g_string_append(req, ACCT_TABLE); query_tab = T_ACCT; } else { bool distinct; filter_from(p_mgr, &fcnt, req, &query_tab, &distinct, AOF_SKIP_NAME); if (filter_name != NULL && !GSTRING_EMPTY(filter_name)) { g_string_append_printf(req, " INNER JOIN (SELECT DISTINCT(id)" " FROM " DNAMES_TABLE " WHERE %s) N" " ON %s.id=N.id", filter_name->str, table2name(query_tab)); /* FIXME: what if NAMES is the query tab? */ } /* FIXME: do the same for stripe items */ } /* Build the request */ if (!GSTRING_EMPTY(where)) g_string_append_printf(req, " WHERE %s", where->str); if (!GSTRING_EMPTY(group_by)) g_string_append_printf(req, " GROUP BY %s", group_by->str); if (!GSTRING_EMPTY(having)) g_string_append_printf(req, " HAVING %s", having->str); if (!GSTRING_EMPTY(order_by)) g_string_append_printf(req, " ORDER BY %s", order_by->str); /* iterator opt */ if (opt.list_count_max > 0) g_string_append_printf(req, " LIMIT %u", opt.list_count_max); retry: /* execute request (expect that ACCT table does not exists) */ if (use_acct_table) rc = db_exec_sql_quiet(&p_mgr->conn, req->str, &p_report->select_result); else rc = db_exec_sql(&p_mgr->conn, req->str, &p_report->select_result); if (lmgr_delayed_retry(p_mgr, rc)) goto retry; /* if the ACCT table does exist, switch to standard mode */ if (use_acct_table && (rc == DB_NOT_EXISTS)) { lmgr_iter_opt_t new_opt; if (p_opt != NULL) new_opt = *p_opt; else new_opt.list_count_max = 0; new_opt.force_no_acct = true; DisplayLog(LVL_EVENT, LISTMGR_TAG, "No accounting info: switching to standard query mode"); g_string_free(req, TRUE); g_string_free(fields, TRUE); g_string_free(group_by, TRUE); g_string_free(order_by, TRUE); g_string_free(having, TRUE); g_string_free(where, TRUE); if (filter_name != NULL) g_string_free(filter_name, TRUE); return ListMgr_Report(p_mgr, report_desc_array, report_descr_count, profile_descr, p_filter, &new_opt); } free_str: /* these are always allocated */ g_string_free(fields, TRUE); g_string_free(group_by, TRUE); g_string_free(order_by, TRUE); g_string_free(having, TRUE); g_string_free(where, TRUE); /* these may not be allocated */ if (req != NULL) g_string_free(req, TRUE); if (filter_name != NULL) g_string_free(filter_name, TRUE); if (rc == DB_SUCCESS) return p_report; /* error */ MemFree(p_report->result); free_report: MemFree(p_report); return NULL; } /* ListMgr_Report */
int gen_scalar_indices1 ( FILE * fp, FILE ** fp2 ) { node_t * p, * memb , * pkg, * rconfig, * fourd, *x ; char * c , *pos1, *pos2 ; char assoc_namelist_var[NAMELEN], assoc_namelist_choice[NAMELEN], assoc_4d[NAMELEN_LONG], fname[NAMELEN_LONG] ; char scalars_str[NAMELEN_LONG] ; char * scalars ; int i ; for ( p = FourD ; p != NULL ; p = p->next ) { for ( memb = p->members ; memb != NULL ; memb = memb->next ) { if ( strcmp(memb->name,"-") ) fprintf(fp," P_%s = 1 ; F_%s = .FALSE. \n", memb->name, memb->name ) ; } } for ( pkg = Packages ; pkg != NULL ; pkg = pkg->next ) { strcpy( assoc_namelist_var , pkg->pkg_assoc ) ; if ((c = index( assoc_namelist_var , '=' ))==NULL) continue ; *c = '\0' ; c += 2 ; strcpy( assoc_namelist_choice , c ) ; if ((rconfig=get_rconfig_entry ( assoc_namelist_var )) == NULL ) { fprintf(stderr, "WARNING: There is no associated namelist variable %s\n", assoc_namelist_var) ; continue ; } fprintf(fp," IF (model_config_rec%%%s%s==%s)THEN\n", assoc_namelist_var, (atoi(rconfig->nentries)!=1)?"(idomain)":"", /* a little tricky; atoi of nentries will be '0' for a string like max_domains */ assoc_namelist_choice) ; strcpy(scalars_str,pkg->pkg_4dscalars) ; if ((scalars = strtok_rentr(scalars_str,";", &pos1)) != NULL) { while ( scalars != NULL ) { if ((c = strtok_rentr(scalars,":",&pos2)) != NULL) strcpy(assoc_4d,c) ; /* get name of associated 4d array */ if (strcmp(c,"-")) { if ( (fourd=get_4d_entry( assoc_4d )) != NULL || !strcmp( assoc_4d, "state" ) ) { for ( c = strtok_rentr(NULL,",",&pos2) ; c != NULL ; c = strtok_rentr(NULL,",",&pos2) ) { if ( fourd != NULL && ( ( x = get_entry( c , fourd->members )) != NULL ) ) { fprintf(fp," IF ( %s_index_table( PARAM_%s , idomain ) .lt. 1 ) THEN\n",assoc_4d,c) ; fprintf(fp," %s_num_table(idomain) = %s_num_table(idomain) + 1\n",assoc_4d,assoc_4d) ; fprintf(fp," P_%s = %s_num_table(idomain)\n",c,assoc_4d) ; fprintf(fp," %s_index_table( PARAM_%s , idomain ) = P_%s\n",assoc_4d,c,c) ; fprintf(fp," ELSE\n") ; fprintf(fp," P_%s = %s_index_table( PARAM_%s , idomain )\n",c,assoc_4d,c) ; fprintf(fp," END IF\n") ; { char fourd_bnd[NAMELEN] ; /* check for the existence of a fourd boundary array associated with this 4D array */ /* set io_mask accordingly for gen_wrf_io to know that it should generate i/o for _b and _bt */ /* arrays */ sprintf(fourd_bnd,"%s_b",assoc_4d) ; if ( get_entry( fourd_bnd ,Domain.fields) != NULL ) { x->boundary = 1 ; } } fprintf(fp," %s_boundary_table( idomain, P_%s ) = %s\n",assoc_4d,c, (x->boundary==1)?".TRUE.":".FALSE." ) ; fprintf(fp," %s_dname_table( idomain, P_%s ) = '%s'\n",assoc_4d,c,x->dname) ; fprintf(fp," %s_desc_table( idomain, P_%s ) = '%s'\n",assoc_4d,c,x->descrip) ; fprintf(fp," %s_units_table( idomain, P_%s ) = '%s'\n",assoc_4d,c,x->units) ; for ( i = 0 ; i < IO_MASK_SIZE ; i++ ) { fprintf(fp," %s_streams_table( idomain, P_%s )%%stream(%d) = %d ! %08x \n",assoc_4d,c, i+1,x->io_mask[i],x->io_mask[i] ) ; } fprintf(fp," F_%s = .TRUE.\n",c) ; } else if ((p = get_entry( c , Domain.fields )) != NULL ) { int tag, fo ; for ( tag = 1 ; tag <= p->ntl ; tag++ ) { if ( !strcmp ( p->use , "_4d_bdy_array_") ) { strcpy(fname,p->name) ; } else { strcpy(fname,field_name(t4,p,(p->ntl>1)?tag:0)) ; } make_lower_case(fname) ; fo = 0 ; if ( 'x' <= fname[0] ) { fo = 6 ; } else if ( 't' <= fname[0] ) { fo = 5 ; } else if ( 'o' <= fname[0] ) { fo = 4 ; } else if ( 'l' <= fname[0] ) { fo = 3 ; } else if ( 'g' <= fname[0] ) { fo = 2 ; } else if ( 'd' <= fname[0] ) { fo = 1 ; } else { fo = 0 ; } fprintf(fp2[fo],"IF(TRIM(vname).EQ.'%s')THEN\n",fname) ; fprintf(fp2[fo]," IF(uses.EQ.0)THEN\n"); fprintf(fp2[fo]," in_use = model_config_rec%%%s%s.EQ.%s\n",assoc_namelist_var,(atoi(rconfig->nentries)!=1)?"(id)":"",assoc_namelist_choice) ; fprintf(fp2[fo]," uses = 1\n") ; fprintf(fp2[fo]," ELSE\n") ; fprintf(fp2[fo]," in_use = in_use.OR.model_config_rec%%%s%s.EQ.%s\n",assoc_namelist_var,(atoi(rconfig->nentries)!=1)?"(id)":"",assoc_namelist_choice) ; fprintf(fp2[fo]," ENDIF\n") ; fprintf(fp2[fo],"ENDIF\n") ; } } else { fprintf(stderr, "WARNING: %s is not a member of 4D array %s\n",c,assoc_4d);continue; } } } else { fprintf(stderr, "WARNING: There is no 4D array named %s\n",assoc_4d);continue ; } } scalars = strtok_rentr(NULL,";", &pos1) ; } } fprintf(fp," END IF\n") ; } return(0) ; }
int main(int argc, char* argv[]) { if (argc < 4 || argc > 6) { std::cout << "Usage: embedfile [-wx] [-text] <inout> <output> <fieldname>" << std::endl; return error_invalidargs; } bool wxWidgets_image = false; bool text_content = false; int argc_offset = 1; if (casecmp(argv[argc_offset], "-wx")) { wxWidgets_image = true; argc_offset++; } if (casecmp(argv[argc_offset], "-text")) { text_content = true; argc_offset++; } std::string input_file(argv[argc_offset]); std::string output_basename(argv[argc_offset + 1]); std::string field_name(argv[argc_offset + 2]); std::ios::openmode mode = std::ios::in; if (!text_content) { mode |= std::ios::binary; } std::ifstream file_in(input_file.c_str(), mode); if (file_in.bad()) { std::cout << "ERROR: Error opening input file: " << input_file << std::endl; return error_cantopenfile; } // Get the size of the input stream size_t input_size; file_in.seekg(0, std::ios::end); if ((int) file_in.tellg() != -1) { input_size = (size_t) file_in.tellg(); } else { std::cout << "ERROR: Failed to get size of input file: " << input_file << std::endl; file_in.close(); return error_ioerror; } file_in.seekg(0, std::ios::beg); // Generates two files, one header and one source file std::string headerName = output_basename + ".h"; std::string sourceName = output_basename + ".cpp"; std::ofstream source_out(sourceName.c_str()); if (source_out.bad()) { std::cout << "ERROR: Error opening output file: " << sourceName << std::endl; return error_cantoutputfile; } std::ofstream header_out(headerName.c_str()); if (header_out.bad()) { std::cout << "ERROR: Error opening output file: " << headerName << std::endl; return error_cantoutputfile; } if (text_content) { do_text_content(file_in, source_out, field_name, input_size); } else { do_binary_content(file_in, source_out, field_name, input_size, wxWidgets_image); } write_header(header_out, field_name, text_content, wxWidgets_image); file_in.close(); source_out.close(); header_out.close(); return error_none; }