Exemplo n.º 1
0
        private void ExecuteSql(int update, ref bool started)
        {
            var queryText  = AddSqlForVariables(SqlQuery);
            var statements = TSQLStatementReader.ParseStatements(queryText);

            if (queryText.Contains("UNION") && statements.Count == 2)
            {
                var tables = statements[0].GetAllTables();
                foreach (var table in tables)
                {
                    LoadRecordset(table.TableName);
                }
                var sqlQueryToUpdate = queryText;
                foreach (var item in AdvancedRecordset.HashedRecSets)
                {
                    sqlQueryToUpdate = sqlQueryToUpdate.Replace(item.recSet, item.hashCode);
                }
                var results = AdvancedRecordset.ExecuteQuery(sqlQueryToUpdate);
                foreach (DataTable dt in results.Tables)
                {
                    AdvancedRecordset.ApplyResultToEnvironment(dt.TableName, Outputs, dt.Rows.Cast <DataRow>().ToList(), false, update, ref started);
                }
            }
            else
            {
                ExecuteAllSqlStatements(update, statements, ref started);
            }
        }
        void ProcessSelectStatement(TSQLSelectStatement selectStatement, int update, ref bool started)
        {
            var results = AdvancedRecordset.ExecuteQuery(AdvancedRecordset.ReturnSql(selectStatement.Tokens));

            foreach (DataTable dt in results.Tables)
            {
                AdvancedRecordset.ApplyResultToEnvironment(dt.TableName, Outputs, dt.Rows.Cast <DataRow>().ToList(), false, update, ref started);
            }
        }
Exemplo n.º 3
0
        void ProcessSelectStatement(TSQLSelectStatement selectStatement, int update, ref bool started)
        {
            var sqlQuery = AdvancedRecordset.UpdateSqlWithHashCodes(selectStatement);
            var results  = AdvancedRecordset.ExecuteQuery(sqlQuery);

            foreach (DataTable dt in results.Tables)
            {
                AdvancedRecordset.ApplyResultToEnvironment(dt.TableName, Outputs, dt.Rows.Cast <DataRow>().ToList(), false, update, ref started);
            }
        }
Exemplo n.º 4
0
        void ProcessUpdateStatement(TSQLUnknownStatement complexStatement, int update, ref bool started)
        {
            var tokens = complexStatement.Tokens;
            var outputRecordsetName = "";

            for (int i = 0; i < complexStatement.Tokens.Count; i++)
            {
                if (i == 1 && tokens[i].Type.ToString() == "Identifier" && (tokens[i - 1].Text.ToUpper() == "UPDATE"))
                {
                    outputRecordsetName = tokens[i].Text;
                }
                if (tokens[i].Type.ToString() == "Keyword" && (tokens[i].Text.ToUpper() == "INSERT"))
                {
                    outputRecordsetName = tokens[i + 2].Text;
                }
                if (tokens[i].Type.ToString() == "Identifier" && (tokens[i].Text.ToUpper() == "REPLACE"))
                {
                    outputRecordsetName = tokens[i + 2].Text;
                }
                if (tokens[i].Type.ToString() == "Keyword" && (tokens[i].Text.ToUpper() == "DELETE"))
                {
                    outputRecordsetName = tokens[i + 2].Text;
                }
            }

            var sqlQuery = AdvancedRecordset.UpdateSqlWithHashCodes(complexStatement);

            var recordset = new DataTable();

            recordset.Columns.Add("records_affected", typeof(int));
            recordset.Rows.Add(AdvancedRecordset.ExecuteNonQuery(sqlQuery));
            object sumObject;

            sumObject         = recordset.Compute("Sum(records_affected)", "");
            _recordsAffected += Convert.ToInt16(sumObject.ToString());
            var mapping = Outputs.FirstOrDefault(e => e.MappedFrom == "records_affected");


            if (mapping != null)
            {
                AdvancedRecordset.ApplyScalarResultToEnvironment(mapping.MappedTo, _recordsAffected);
            }
            var results = AdvancedRecordset.ExecuteQuery("SELECT * FROM " + AdvancedRecordset.HashedRecSets.FirstOrDefault(x => x.recSet == outputRecordsetName).hashCode);

            foreach (DataTable dt in results.Tables)
            {
                AdvancedRecordset.ApplyResultToEnvironment(outputRecordsetName, Outputs, dt.Rows.Cast <DataRow>().ToList(), true, update, ref started);
            }
        }
        private void ExecuteSql(int update, List <string> allTables, ref bool started)
        {
            var queryText  = AddSqlForVariables(SqlQuery);
            var statements = TSQLStatementReader.ParseStatements(queryText);

            if (queryText.Contains("UNION") && statements.Count == 2)
            {
                var tables = statements[0].GetAllTables();
                foreach (var table in tables)
                {
                    LoadRecordset(table.TableName);
                    allTables.Add(table.TableName);
                }
                var results = AdvancedRecordset.ExecuteQuery(queryText);
                foreach (DataTable dt in results.Tables)
                {
                    AdvancedRecordset.ApplyResultToEnvironment(dt.TableName, Outputs, dt.Rows.Cast <DataRow>().ToList(), false, update, ref started);
                }
            }
            else
            {
                ExecuteAllSqlStatements(update, allTables, statements, ref started);
            }
        }