public CommandResultSchema[] GetCommandResultSchemas(string connectionString, CommandSchema command) { CommandResultSchema[] array = null; string arg = command.ExtendedProperties["CS_Name"].Value as string; using (NpgsqlConnection npgsqlConnection = new NpgsqlConnection(connectionString)) { npgsqlConnection.Open(); string text = string.Format("select data_type from information_schema.routines where specific_schema='public' and specific_name = '{0}'", arg); using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(text, npgsqlConnection)) { using (NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader(CommandBehavior.CloseConnection)) { while (npgsqlDataReader.Read()) { string @string = npgsqlDataReader.GetString(0); if (@string == "void") { array = new CommandResultSchema[0]; } else if (@string == "USER-DEFINED") { NpgsqlCommand npgsqlCommand2 = new NpgsqlCommand(string.Format("SELECT t.typname, attname, a.typname from pg_type t JOIN pg_class on (reltype = t.oid) JOIN pg_attribute on (attrelid = pg_class.oid) JOIN pg_type a on (atttypid = a.oid) WHERE t.typname = (SELECT t.typname FROM pg_catalog.pg_proc p LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace INNER JOIN pg_type t ON p.prorettype = t.oid WHERE n.nspname = 'public' and proname = '{0}' ORDER BY proname);", command.Name), npgsqlConnection); using (NpgsqlDataReader npgsqlDataReader2 = npgsqlCommand2.ExecuteReader(CommandBehavior.CloseConnection)) { string text2 = null; List <CommandResultColumnSchema> list = new List <CommandResultColumnSchema>(); while (npgsqlDataReader2.Read()) { if (string.IsNullOrEmpty(text2)) { text2 = npgsqlDataReader2.GetString(0); } string string2 = npgsqlDataReader2.GetString(2); list.Add(new CommandResultColumnSchema(command, npgsqlDataReader2.GetString(1), PostgreSQLSchemaProvider.GetDbType(string2), string2, 0, 0, 0, true, new ExtendedProperty[] { new ExtendedProperty("NpgsqlDbType", PostgreSQLSchemaProvider.GetNativeDbType(string2), DbType.String) })); } array = new CommandResultSchema[] { new CommandResultSchema(command, text2, list.ToArray()) }; } } } if (!npgsqlDataReader.IsClosed) { npgsqlDataReader.Close(); } } } if (npgsqlConnection.State != ConnectionState.Closed) { npgsqlConnection.Close(); } } return(array ?? new CommandResultSchema[0]); }
private void CreateResult(Function function, CommandResultSchema commandResultSchema, string defaultName, int index) { string name = defaultName; Type result; if (function.Types.Contains(name)) { result = function.Types[name]; } else if (function.Types.Count >= index + 1) { result = function.Types[index]; } else { result = new Type(ToClassName(name)); function.Types.Add(result); } if (result.IsProcessed) { return; } // ElementType/@Name safe attribute if (string.IsNullOrEmpty(result.Name)) { result.Name = ToClassName(name); } foreach (CommandResultColumnSchema c in commandResultSchema.Columns) { Column column; if (result.Columns.Contains(c.Name)) { column = result.Columns[c.Name]; } else { column = new Column(GetSystemType(c)); column.Name = c.Name; result.Columns.Add(column); } if (!column.IsProcessed) { PopulateColumn(column, c, result.Name); } } result.IsProcessed = true; }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { if (context.Instance != null) { // CR modifying to accomodate PropertyBag Type instanceType = null; object objinfo = null; TypeHelper.GetContextInstanceObject(context, ref objinfo, ref instanceType); instance = objinfo.GetType(); PropertyInfo tableInfo = instance.GetProperty("SpSchema"); object table = tableInfo.GetValue(context.Instance, null); if (table != null) { lstColumns.Items.Clear(); CommandResultSchema t = (CommandResultSchema)table; for (int i = 0; i < t.Columns.Count; i++) { lstColumns.Items.Add(t.Columns[i].Name); } editorService.DropDownControl(lstColumns); if (lstColumns.SelectedItem != null) { string column = (string)lstColumns.SelectedItem; if (column != String.Empty) { value = t.Columns[column]; } } } } } } return(value); }
private void CreateResult(Function function, CommandResultSchema commandResultSchema, string defaultName, int index) { string name = defaultName; Type result; if (function.Types.Contains(name)) { result = function.Types[name]; } else if (function.Types.Count >= index + 1) { result = function.Types[index]; } else { result = new Type(ToClassName(name)); function.Types.Add(result); } if (result.IsProcessed) return; // ElementType/@Name safe attribute if (string.IsNullOrEmpty(result.Name)) result.Name = ToClassName(name); foreach (CommandResultColumnSchema c in commandResultSchema.Columns) { Column column; if (result.Columns.Contains(c.Name)) { column = result.Columns[c.Name]; } else { column = new Column(GetSystemType(c)); column.Name = c.Name; result.Columns.Add(column); } if (!column.IsProcessed) PopulateColumn(column, c, result.Name); } result.IsProcessed = true; }