Esempio n. 1
0
        public void Execute(Func<bool> stopOnError)
        {
            StringBuilder builder = new StringBuilder();
            var reader = new SqlScriptReader(scriptFile);

            while (reader.NextLine())
            {
                string line = reader.Line;

                string formatedLine = line.Trim();
                string upperLine = formatedLine.ToUpper();
                if (upperLine.StartsWith("INSERT")
                    || upperLine.StartsWith("UPDATE")
                    || upperLine.StartsWith("DELETE")
                    || upperLine.StartsWith("CREATE")
                    || upperLine.StartsWith("DROP")
                    || upperLine.StartsWith("ALTER")
                    || upperLine.StartsWith("GO")
                    )
                {
                    if (!ExecuteSql(reader.LineNumber, builder))
                    {
                        if(stopOnError != null && stopOnError())
                            return;
                    }

                    builder.Clear();
                    if (!upperLine.StartsWith("GO"))
                        builder.AppendLine(line);
                }
                else
                {
                    builder.AppendLine(line);
                    while (reader.NextLine())
                    {
                        line = reader.Line;

                        formatedLine = line.Trim();

                        upperLine = formatedLine.ToUpper();

                        if (!upperLine.StartsWith("GO"))
                            builder.AppendLine(line);
                        else
                        {
                            if (!ExecuteSql(reader.LineNumber, builder))
                            {
                                if (stopOnError != null && stopOnError())
                                    return;
                            }

                            builder.Clear();
                            break;
                        }
                    }
                }

            }

            reader.Close();

            if (!ExecuteSql(reader.LineNumber, builder))
                return;

            OnCompleted(new EventArgs());
        }
Esempio n. 2
0
        public void Execute(Func <bool> stopOnError)
        {
            buffer = new StringBuffer(BatchSize);

            StringBuilder builder = new StringBuilder();
            var           reader  = new SqlScriptReader(scriptFile);

            while (reader.NextLine())
            {
                string line = reader.Line;

                string formatedLine = line.Trim();
                string upperLine    = formatedLine.ToUpper();
                if (upperLine.StartsWith("INSERT") ||
                    upperLine.StartsWith("UPDATE") ||
                    upperLine.StartsWith("DELETE") ||
                    upperLine.StartsWith("CREATE") ||
                    upperLine.StartsWith("DROP") ||
                    upperLine.StartsWith("ALTER") ||
                    upperLine.StartsWith(GO)
                    )
                {
                    bool go = upperLine.StartsWith(GO);

                    if (!ExecuteSql(reader.LineNumber, builder, go))
                    {
                        if (stopOnError != null && stopOnError())
                        {
                            reader.Close();
                            return;
                        }
                    }

                    builder.Clear();
                    if (!upperLine.StartsWith(GO))
                    {
                        builder.AppendLine(line);
                    }
                }
                else
                {
                    builder.AppendLine(line);
                    while (reader.NextLine())
                    {
                        line = reader.Line;

                        formatedLine = line.Trim();

                        upperLine = formatedLine.ToUpper();

                        if (!upperLine.StartsWith(GO))
                        {
                            builder.AppendLine(line);
                        }
                        else
                        {
                            if (!ExecuteSql(reader.LineNumber, builder, commit: true))
                            {
                                if (stopOnError != null && stopOnError())
                                {
                                    reader.Close();
                                    return;
                                }
                            }

                            builder.Clear();
                            break;
                        }
                    }
                }
            }

            reader.Close();

            if (!ExecuteSql(reader.LineNumber, builder, commit: true))
            {
                return;
            }

            OnCompleted(new EventArgs());
        }