Ejemplo n.º 1
0
        public static SqlAnalyzerResults AnalyzeSql(string sqlText, bool combine)
        {
            SqlAnalyzerResults result = new SqlAnalyzerResults();

            //1- Variables

            result.VariableNamesWithDataTypes = GetVariables(sqlText, true);
            //result.VariableNames = GetVariables(sqlText,false);

            //2- Table aliases
            result.TableAliasFrom = GetTableAliases(sqlText, TableAliasType.From);
            result.TableAliasJoin = GetTableAliases(sqlText, TableAliasType.Join);

            //3- Table definitions

            result.TableAsTemp     = GetTables(sqlText, TableType.Temp);
            result.TableAsVariable = GetTables(sqlText, TableType.Variable);

            //4- Combine all
            if (combine)
            {
                result.CombineResults();
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static SqlAnalyzerResults AnalyzeSql(string sqlText, bool combine)
        {
            SqlAnalyzerResults      result          = new SqlAnalyzerResults();
            SqlVariablesWorkItem    varsItem1       = (SqlVariablesWorkItem)AsyncSqlVariablesWorker.StartWork(sqlText, false, HandleVariablesEndRegexWork);
            SqlTableAliasesWorkItem tblAliasesItem1 = (SqlTableAliasesWorkItem)AsyncSqlTableAliasesWorker.StartWork(sqlText, TableAliasType.From, HandleTableAliasesEndRegexWork);
            SqlTableAliasesWorkItem tblAliasesItem2 = (SqlTableAliasesWorkItem)AsyncSqlTableAliasesWorker.StartWork(sqlText, TableAliasType.Join, HandleTableAliasesEndRegexWork);
            SqlTablesWorkItem       tablesItem1     = (SqlTablesWorkItem)AsyncSqlTablesWorker.StartWork(sqlText, TableType.Temp, HandleTablesEndRegexWork);
            SqlTablesWorkItem       tablesItem2     = (SqlTablesWorkItem)AsyncSqlTablesWorker.StartWork(sqlText, TableType.Variable, HandleTablesEndRegexWork);


            CancellableWorkItem[] jobs = new CancellableWorkItem[] {
                varsItem1,
                tblAliasesItem1,
                tblAliasesItem2,
                tablesItem1,
                tablesItem2
            };

            // Wait for 2 seconds.  After that we cancel any jobs that have not completed
            WaitHandle[] waitHandles = new WaitHandle[] { varsItem1.AsyncWaitHandle,
                                                          tblAliasesItem1.AsyncWaitHandle,
                                                          tblAliasesItem2.AsyncWaitHandle,
                                                          tablesItem1.AsyncWaitHandle,
                                                          tablesItem2.AsyncWaitHandle };

            WaitAll(waitHandles);


            for (int i = 0; i < jobs.Length; i++)
            {
                if (jobs[i].IsCompleted)
                {
                    if (jobs[i] is SqlVariablesWorkItem)
                    {
                        SqlVariablesWorkItem vars = jobs[i] as SqlVariablesWorkItem;
                        if (!vars.NamesOnly)
                        {
                            result.VariableNamesWithDataTypes = vars.Result;
                        }
                        else
                        {
                            result.Variables = vars.Result;
                        }
                    }
                    else if (jobs[i] is SqlTableAliasesWorkItem)
                    {
                        SqlTableAliasesWorkItem aliases = jobs[i] as SqlTableAliasesWorkItem;
                        switch (aliases.AliasType)
                        {
                        case TableAliasType.From:
                            result.TableAliasFrom = aliases.Result;
                            break;

                        case TableAliasType.Join:
                            result.TableAliasJoin = aliases.Result;
                            break;

                        default:
                            break;
                        }
                    }
                    else if (jobs[i] is SqlTablesWorkItem)
                    {
                        SqlTablesWorkItem tables = jobs[i] as SqlTablesWorkItem;
                        switch (tables.TableType)
                        {
                        case TableType.Temp:
                            result.TableAsTemp = tables.Result;
                            break;

                        case TableType.Variable:
                            result.TableAsVariable = tables.Result;
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    jobs[i].Cancel();
                }
            }

            if (combine)
            {
                result.CombineResults();
            }

            return(result);
        }