示例#1
0
 private static void MapColumnInformation(TableSchema table, TableSchemaInfo tSchema)
 {
     foreach (var c in table.Columns)
     {
         var cSchema = new ColumnSchemaInfo();
         cSchema.ColumnName = c.Name;
         cSchema.DataType   = c.DataType.ToString();
         tSchema.Columns.Add(cSchema);
     }
 }
        /// <summary>
        /// Get information about columns in current data matrix.
        /// </summary>
        /// <param name="odbcConnectionString">An ODBC connection string for connecting DB.</param>
        /// <param name="dataMatrixName">An unescaped name of data matrix.</param>
        /// <param name="boxIdentity">An identity of BoxModule.</param>
        /// <returns>An array of <see cref="T:Ferda.Modules.Boxes.DataMiningCommon.DataMatrix.ColumnInfo"/>.</returns>
        /// <remarks><see cref="T:Ferda.Modules.Boxes.DataMiningCommon.DataMatrix.ColumnInfo"/> is similar to result of <see cref="M:System.Data.Odbc.OdbcDataReader.GetSchemaTable"/>.</remarks>
        /// <exception cref="T:Ferda.Modules.BadParamsError">Thrown if <c>odbcConnectionString</c> or <c>dataMatrixName</c> parameter is wrong.</exception>
        public static ColumnSchemaInfo[] Explain(string odbcConnectionString, string dataMatrixName, string boxIdentity)
        {
            //throws exception if odbcConnectionString is wrong
            OdbcConnection conn = Ferda.Modules.Helpers.Data.OdbcConnections.GetConnection(odbcConnectionString, boxIdentity);

            List<ColumnSchemaInfo> result = new List<ColumnSchemaInfo>();
            ColumnSchemaInfo columnSchemaInfo;

            //create SQL (empty ... WHERE 0) query over dataMatrixName (this select given data matrix)
            dataMatrixName = SqlSecurity.SafeSqlObjectName(dataMatrixName);
            OdbcCommand odbcCommand = new OdbcCommand("SELECT * FROM `" + dataMatrixName + "` WHERE 0", conn);

            try
            {
                //see documentation for System.Data.Odbc.OdbcDataReader.GetSchemaTable()
                foreach (DataRow row in odbcCommand.ExecuteReader().GetSchemaTable().Rows)
                {
                    columnSchemaInfo = new ColumnSchemaInfo();
                    columnSchemaInfo.name = row["ColumnName"].ToString();
                    columnSchemaInfo.columnOrdinal = Convert.ToInt32(row["ColumnOrdinal"]);
                    columnSchemaInfo.columnSize = Convert.ToInt32(row["ColumnSize"]);
                    columnSchemaInfo.numericPrecision = Convert.ToInt32(row["NumericPrecision"]);
                    columnSchemaInfo.numericScale = Convert.ToInt32(row["NumericScale"]);
                    columnSchemaInfo.providerType = Convert.ToInt32(row["ProviderType"]);
                    columnSchemaInfo.dataType = row["DataType"].ToString();
                    columnSchemaInfo.isLong = Convert.ToBoolean(row["IsLong"]);
                    columnSchemaInfo.allowDBNull = Convert.ToBoolean(row["AllowDBNull"]);
                    columnSchemaInfo.isReadOnly = Convert.ToBoolean(row["IsReadOnly"]);
                    columnSchemaInfo.isRowVersion = Convert.ToBoolean(row["IsRowVersion"]);
                    columnSchemaInfo.isUnique = Convert.ToBoolean(row["IsUnique"]);
                    columnSchemaInfo.isKey = Convert.ToBoolean(row["IsKey"]);
                    columnSchemaInfo.isAutoIncrement = Convert.ToBoolean(row["IsAutoIncrement"]);
                    result.Add(columnSchemaInfo);
                }
            }
            catch (Exception ex)
            {
                //throws exception if dataMatrixName is wrong
                TestDataMatrixExists(odbcConnectionString, dataMatrixName, boxIdentity);

                //or other reason for exception
                throw Ferda.Modules.Exceptions.BadParamsUnexpectedReasonError(ex, boxIdentity);
            }
            return result.ToArray();
        }
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="localePrefs">Localeprefs</param>
 /// <param name="dataMatrix">Datamatrix</param>
 /// <param name="dataMatrixInfo">Datamatrix info</param>
 public ExplainTable(string[] localePrefs, ColumnSchemaInfo[] dataMatrix, DataMatrixInfo dataMatrixInfo, IOwnerOfAddIn ownerOfAddIn)
 {
     //setting the ResManager resource manager and localization string
     string locale;
     try
     {
         locale = localePrefs[0];
         localizationString = locale;
         locale = "Ferda.FrontEnd.AddIns.ExplainTable.Localization_" + locale;
         resManager = new ResourceManager(locale, Assembly.GetExecutingAssembly());
     }
     catch
     {
         resManager = new ResourceManager("Ferda.FrontEnd.AddIns.ExplainTable.Localization_en-US",
     Assembly.GetExecutingAssembly());
         localizationString = "en-US";
     }
     this.ownerOfAddIn = ownerOfAddIn;
     comparer.column = 0;
     this.dataMatrix = dataMatrix;
     this.dataMatrixInfo = dataMatrixInfo;
     InitializeComponent();
     this.ListViewInit();
     this.MakeListView();
     this.ToolStripMenuItemCopyAll.Click += new EventHandler(ToolStripMenuItemCopyAll_Click);
     this.ToolStripMenuItemCopySelected.Click += new EventHandler(ToolStripMenuItemCopySelected_Click);
 }