コード例 #1
0
        public List <Dimension> GetDimensionsOf(string tablename)
        {
            // the tempTable is used to store the Database-results
            DataTable tempTable  = new DataTable();
            DataTable tempTable2 = new DataTable();
            // this list will be filled and returned
            List <Dimension> dimensions = new List <Dimension>();

            try
            {
                Open();
                // see http://swp.offis.uni-oldenburg.de:8082/display/MPMDoku/Metadaten-Repository for sql-explanation
                MySqlCommand getMetaDataSQL = new MySqlCommand(
                    "SELECT constraint_name as FromConstraint, table_name as FromTable, column_name as FromColumn, constraint_name as ToConstraint, " +
                    "referenced_table_name as ToTable, referenced_column_name as ToColumn " +
                    "FROM information_schema.key_column_usage " +
                    "WHERE constraint_schema = '" + DBWorker.getParams().Database + "' AND constraint_name != 'PRIMARY' AND table_name = '" + tablename + "' AND referenced_table_name != 'CASE';", Connection);

                MySqlDataAdapter metaDataAdapter = new MySqlDataAdapter(getMetaDataSQL);
                // Fill the temporally used Table
                metaDataAdapter.Fill(tempTable);

                // every Database-row is a dimension
                foreach (DataRow row in tempTable.Rows)
                {
                    // create a dimension-object (see MetaWorker.Dimension)
                    Dimension d = new Dimension(row["FromColumn"].ToString(), row["FromConstraint"].ToString(),
                                                row["FromTable"].ToString(), row["FromColumn"].ToString(),
                                                row["ToConstraint"].ToString(), row["ToTable"].ToString(), row["ToColumn"].ToString());

                    // Now get the Data than can be filtered later:
                    MySqlCommand getContentSQL = new MySqlCommand("SELECT * FROM `" + row["ToTable"].ToString() + "` LIMIT 100", Connection);

                    /*
                     * This SQL-Command seems pretty unsafe, why so? Well, Oracle lets you use parameters for the WHERE-part of the query,
                     * however you can't do the same thing for the FROM-part. God knows why.
                     */

                    MySqlDataAdapter contentAdapter = new MySqlDataAdapter(getContentSQL);
                    // Fill the temporally used Table
                    contentAdapter.Fill(tempTable2);
                    // create DimensionContent-Objects and add them to the current dimension
                    foreach (DataRow row2 in tempTable2.Rows)
                    {
                        string desc = "";
                        if (row2.ItemArray.Count() > 2)
                        {
                            desc = row2[2].ToString();
                        }
                        d.DimensionContentsList.Add(new DimensionContent(row2[0].ToString(), row2[1].ToString(), desc));
                    }

                    // save the DimensionColumnNames for generated DB-querys
                    d.DimensionColumnNames = new DimensionColumnNames(tempTable2.Columns[0].ColumnName,
                                                                      tempTable2.Columns[1].ColumnName, tempTable2.Columns[2].ColumnName);

                    tempTable2.Reset();
                    // now recursively find all sub-ListOfDimensions of this Table and add them to the current dimension
                    d.AddDimensionLevel(GetDimensionsOf(row["ToTable"].ToString()));

                    // add the current dimension to the list that will be returned eventually
                    dimensions.Add(d);
                }

                return(dimensions);
            }
            finally
            {
                Close();
            }
        }
コード例 #2
0
        /// <summary>
        /// Returns the columns in a given Table.
        /// </summary>
        /// <param Name="Table">The Name of the Table.</param>
        /// <returns>A List of strings.</returns>
        /// <author>Jannik Arndt</author>
        public List <String> GetColumnNamesOfTable(String tablename)
        {
            List <String> ListOfColoumnames = new List <string>();

            try
            {
                Open();
                MySqlCommand cmd    = new MySqlCommand("SELECT column_name FROM information_schema.columns WHERE table_schema = '" + DBWorker.getParams().Database + "' AND table_name = '" + tablename + "';", Connection);
                DbDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ListOfColoumnames.Add((string)reader["column_name"]);
                }

                return(ListOfColoumnames);
            }
            finally
            {
                Close();
            }
        }