コード例 #1
0
        public static string DisambiguateAndRenderCSharpProperty(SQLColumn s, Dictionary <string, int> columnNamesAndCounts)
        {
            string name = CSharpRenderer.FieldNameToCSharpPropertyName(s.ColumnName);

            if (columnNamesAndCounts.ContainsKey(name))
            {
                columnNamesAndCounts[name] += 1;
                name = String.Format("{0}_{1}", name, columnNamesAndCounts[name]);
            }
            else
            {
                columnNamesAndCounts.Add(name, 1);
            }

            return(RenderCSharpProperty(s, name));
        }
コード例 #2
0
        public static void DoSqlQueryWork(DoWorkEventArgs e, BackgroundWorker bw, Config config)
        {
            FlexResultSet resultSet = null;
            var           srp       = (SqlRunParameters)e.Argument;

            bw.ReportProgress(1, "Opening connection...");
            SqlConnection conn        = null;
            string        currentTask = "";

            try
            {
                using (conn = new SqlConnection(srp.connStringBuilder.ConnectionString))
                {
                    if (bw.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    currentTask = "while opening SQL connection";
                    conn.Open();

                    bw.ReportProgress(2, "Running query...");

                    if (bw.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    currentTask = "while running the query or analyzing the data";
                    resultSet   = FlexResultSet.AnalyzeResultWithRollback(conn, srp, config, bw);

                    currentTask = "while closing the database connection";
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                renderExceptionToSqlRunParameters(currentTask, srp, ex);
            }
            finally
            {
                if (conn != null && conn.State != System.Data.ConnectionState.Closed)
                {
                    conn.Close();
                }
            }

            if (bw.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            if (resultSet == null)
            {
                e.Result = srp;
                return;
            }

            try
            {
                bw.ReportProgress(90, "Scripting results...");
                renderAndCountExceptions(resultSet, srp);
            }
            catch (Exception ex)
            {
                renderExceptionToSqlRunParameters("scripting results", srp, ex);
                e.Result = srp;
                return;
            }


            if (bw.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            bw.ReportProgress(92, "Scripting results...");
            if (srp.outputType == SqlRunParameters.TO_INSERT_STATEMENTS)
            {
                try
                {
                    renderSchemaAndData(resultSet, srp);
                }
                catch (Exception ex)
                {
                    renderExceptionToSqlRunParameters("while rendering schema and dataset", srp, ex);
                }
            }
            else if (srp.outputType == SqlRunParameters.TO_XML_SPREADSHEET)
            {
                try
                {
                    XmlSpreadsheetRenderer.renderAsXMLSpreadsheet(resultSet, srp);
                }
                catch (Exception ex)
                {
                    srp.worksheetIsValid = false;
                    srp.flushAndCloseOutputStreamIfNeeded();
                    renderExceptionToSqlRunParameters("while rendering spreadsheet", srp, ex);
                }
            }
            else if (srp.outputType == SqlRunParameters.TO_CSV)
            {
                try
                {
                    CSVRenderer.renderAsCSV(resultSet, srp);
                }
                catch (Exception ex)
                {
                    srp.worksheetIsValid = false;
                    srp.flushAndCloseOutputStreamIfNeeded();
                    renderExceptionToSqlRunParameters("while rendering csv", srp, ex);
                }
            }
            else if (srp.outputType == SqlRunParameters.TO_CSHARP)
            {
                try
                {
                    CSharpRenderer.renderAsCSharp(resultSet, srp);
                }
                catch (Exception ex)
                {
                    renderExceptionToSqlRunParameters("while rendering C#", srp, ex);
                }
            }
            e.Result = srp;
        }