Exemple #1
0
 public SQLScriptingClassOLD(DBRegistrationClass drc, string connectionName = "SCRIPT", NotifiesClass pNotifies = null, NotifiesClass eventNotifies = null)
 {
     _parentNotifies = pNotifies;
     _eventNotifies  = eventNotifies;
     _connectionName = connectionName;
     _drc            = drc;
     _connstr        = ConnectionStrings.Instance().MakeConnectionString(_drc);
     _aktCommand     = new SCRIPTCommandClass();
 }
Exemple #2
0
        public bool AddCommandLine(string txt)
        {
            //Wenn erkannt wird das es sich um eine Infozeile handelt dann wird das InComments flag gesetzt.
            //Es wird nichts zum auführbaren Script _commands hinzugefügt.
            _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.AddCommandLine()", Constants.AddCommandLine, 1);
            if (string.IsNullOrEmpty(txt) || txt.Equals("\r\n"))
            {
                return(false);
            }
            if (IsCommentStart(txt))
            {
                _inComments = true;
            }

            if (IsCommentEnd(txt))
            {
                _inComments = false;
                return(false);
            }

            if (_inComments)
            {
                return(false);
            }

            //SET TERM
            if (SetTerminator(txt))
            {
                if (!_inTerminator)
                {
                    // Terminatorbereich wurd zum 2.Male erkannt -> Kommandoende;
                    // Das Kommando wird angefügt. Standardwerte für neues Komamnd werden gesetzt;
                    _aktCommand.CommandType = SQLCommand.GetStaticCommandType(_aktCommand.CommandText);

                    if ((!CommitEachCommand) || (_aktCommand.CommandType != SQLCommandType.commit))
                    {
                        _aktCommand.GUID = Guid.NewGuid().ToString();

                        Commands.Add(_aktCommand.GUID, _aktCommand);
                        _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.AddCommandLine()", Constants.CommandPrepared, _aktCommand);
                    }
                    if ((CommitEachCommand) && (_aktCommand.CommandType != SQLCommandType.commit))
                    {
                        //Wenn das aktelle Kommando kein COMMIT; ist und nach jedem Kommando aber ein COMMIT; geschrieben werden soll.
                        _aktCommand             = new SCRIPTCommandClass($@"COMMIT{_terminator}");
                        _aktCommand.CommandType = SQLCommandType.commit;
                        _aktCommand.GUID        = Guid.NewGuid().ToString();

                        Commands.Add(_aktCommand.GUID, _aktCommand);
                        _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.AddCommandLine()", Constants.CommandPrepared, _aktCommand);
                    }

                    _aktCommand   = new SCRIPTCommandClass();
                    _inBlock      = false;
                    _inTerminator = false;
                    return(true);
                }
                return(false);
            }

            //Wenn die Scriptzeile mit den Terminator endet, dann ist das Kommando fertig
            //Das Kommando wird ohne den Terminator angelegt.
            if (IsTermiatorOrBlockEnd(txt))
            {
                if (txt.Trim().Length > 1)
                {
                    _aktCommand.Add(txt.Trim().Substring(0, txt.Trim().Length - 1));
                    _aktCommand.CommandType = SQLCommand.GetStaticCommandType(_aktCommand.CommandText);
                    if ((!CommitEachCommand) || (_aktCommand.CommandType != SQLCommandType.commit))
                    {
                        _aktCommand.GUID = Guid.NewGuid().ToString();

                        Commands.Add(_aktCommand.GUID, _aktCommand);
                        _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.AddCommandLine()", Constants.CommandPrepared, _aktCommand);
                    }
                    if ((CommitEachCommand) && (_aktCommand.CommandType != SQLCommandType.commit))
                    {
                        //Wenn das aktelle Kommando kein COMMIT; ist und nach jedem Kommando aber ein COMMIT; geschrieben werden soll.
                        _aktCommand             = new SCRIPTCommandClass($@"COMMIT{_terminator}");
                        _aktCommand.CommandType = SQLCommandType.commit;
                        _aktCommand.GUID        = Guid.NewGuid().ToString();;

                        Commands.Add(_aktCommand.GUID, _aktCommand);
                        _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.AddCommandLine()", Constants.CommandPrepared, _aktCommand);
                    }

                    _aktCommand   = new SCRIPTCommandClass();
                    _inTerminator = false;
                    _inBlock      = false;
                }
                return(true);
            }

            if (!_inBlock)
            {
                if (!BlockStart(txt))
                {
                    return(false);
                }

                txt = TestForValidation(txt);
                _aktCommand.Add(txt);
                return(IsTermiatorOrBlockEnd(txt));
            }

            if (_aktCommand.CommandText.Length <= 0)
            {
                return(false);
            }

            _aktCommand.Add(txt);
            return(IsTermiatorOrBlockEnd(txt));
        }