Example #1
0
        private void dataTableColumns_ColumnChanged(
			object sender, System.Data.DataColumnChangeEventArgs e)
        {
            /*
            MessageBox.Show(
                "ColumnName    = " + e.Column.ColumnName +";\n" +
                "ProposedValue = " + (e.ProposedValue!=null?e.ProposedValue:"<null>") + "\n" +
                "RowState      = " + e.Row.RowState,
                "ColumnChanged");
            */
            DataRow        row    = e.Row;
            DataRowState rowState = e.Row.RowState;

            MetaData.Column oldCol = null;
            string oldColumnName   = "";
            string oldTableName    = "";
            string oldTableNameSpec= "";

            Object obj;  // work object

            int index = DataRowIndex(row);  // index into table

            string columnName;
            obj = row["Column Name"];
            if (!Convert.IsDBNull(obj))
                columnName = ((string)obj).Trim();
            else
                columnName = String.Empty;

            if (columnName.Length != 0)
            {
                string aliasSpec;
                obj = row["Alias"];
                if (!Convert.IsDBNull(obj))
                    aliasSpec = (string)obj;
                else
                    aliasSpec = String.Empty;

                string tableSpec;
                obj = row["Table"];
                if (!Convert.IsDBNull(obj))
                    tableSpec = (string)obj;
                else
                    tableSpec = String.Empty;

                MetaData.Column newCol = new MetaData.Column();
                newCol.ColumnName = columnName;
                //newCol.TableName  = tableSpec;
                newCol.AliasName  = aliasSpec;
                newCol.AliasNameSpecification =
                    MetaData.WrapInQuotesIfEmbeddedSpaces(aliasSpec);

                if (index != -1  &&
                    index < this.md.Columns.Count)
                {
                    oldCol = (MetaData.Column)this.md.Columns[index];
                    if (oldCol != null)
                    {
                        if (oldCol.ColumnName != null)
                            oldColumnName = oldCol.ColumnName;
                        if (oldCol.TableName != null)
                            oldTableName = oldCol.TableName;
                        if (oldCol.TableNameSpecification != null)
                            oldTableNameSpec =
                                oldCol.TableNameSpecification;
                    }
                }

                int token;
                StringBuilder sb = new StringBuilder(100);

                if (oldCol != null)
                {
                    token = oldCol.Token;       // replacing old entry
                    token = this.md.RemoveToken(index);
                }
                else
                    token = this.md.TokenFROM;  // adding new entry

                // if inserting last col, need a preceding comma
                if (index > 0  &&  index + 1 >= this.md.Columns.Count)
                    sb.Append(", ");  // append leading comma

                sb.Append(newCol.ToString());

                // if we are not the last column then append a
                // trailing comma.  e.g. "mycol,"
                if (index + 1 < this.md.Columns.Count)
                    sb.Append(",");  // append trailing comma

                this.md.CmdTokenList.Insert(token, sb.ToString());
            }
            else  // columnName == String.Empty (treat as delete)
            {
                this.md.RemoveToken(index);  // remove the column's token
            }
            // update the query text pane
            UpdateQueryTextBox(this.md.CmdTokenList);

            // rebuild the metadata
            this.md = this.Connection.GetMetaData(this.textQuery.Text);

            // update table property pages display
            UpdateTableColumnCheckBoxList(md);

            this.rebuildDataGrid = true;  // rebuild the data grid later
        }
Example #2
0
        // list of tables to expand from
        /*
        ** ExpandSelectStarColumnReference method
        **
        ** History:
        **	28-Jan-03 (thoda04)
        **	    Created.
        **	30-sep-08 (thoda04)
        **	    "SELECT *"  must insert columns from all tables
        **	    before removing * reference.  Bug 120972.
        */
        /// <summary>
        /// Expand the "*" column reference in a SELECT *
        /// to all of the columns defined in the table or tables.
        /// </summary>
        private void ExpandSelectStarColumnReference(
			ArrayList columns,  // array of columns that contains the "*" column
			int index,          // index into columns for the "*" column
			ArrayList tablelist)
        {
            int starindex = index;    // save the index of the "*" column

            foreach(Table table in tablelist)
            {
                Catalog.Table catTable = table.CatTable;
                if (catTable         == null ||
                    catTable.Columns == null ||
                    catTable.Columns.Count == 0)
                    continue;
                foreach (Catalog.Column catCol in catTable.Columns)
                {
                    Column col = new MetaData.Column();
                    col.SchemaName = catCol.SchemaName;
                    col.TableName  = catCol.TableName;
                    col.ColumnName = "*";  // indicate to GetSchemaTable() that
                                           // this column is from "SELECT * ..."
                    if (table.AliasNameSpecification != null)
                        col.TableNameSpecification = table.AliasNameSpecification;
                    else
                    {
                        col.TableNameSpecification = table.TableNameSpecification;
                        if (table.SchemaNameSpecification != null)
                            col.SchemaNameSpecification =
                                table.SchemaNameSpecification;
                    }
                    col.Table = table;      // Table reference in FROM list

                    columns.Insert(++index, col);  // insert new column into list
                }  // end loop thru catalog columns for the table
            } // end loop thru tables

            if (index != starindex)  // if new columns replaced "*" column
                columns.RemoveAt(starindex);  // remove the "*" column
            else  // for some strange reason (e.g. table not in database),
                  // couldn't replace columns
            {
                Column col = (Column)columns[starindex];
                col.Clear();   // clear the strange "*" column
            }
        }