Esempio n. 1
0
        public int RefreshDependenciesTo()
        {
            string cmd_index0      = "SELECT RDB$DEPENDENCIES.RDB$FIELD_NAME as Field ,RDB$DEPENDENCIES.RDB$DEPENDENT_NAME as DepentTo,CASE RDB$DEPENDENCIES.RDB$DEPENDENT_TYPE";
            string case0           = EnumClass.Instance.GetDependenciesTypeSQLCase() + " AS  DependentType FROM RDB$DEPENDENCIES";
            string cmd_index_where = "WHERE UPPER(RDB$DEPENDENCIES.RDB$DEPENDED_ON_NAME) = '" + TriggerObject.Name + "' AND RDB$DEPENDENCIES.RDB$FIELD_NAME IS NOT NULL";
            string cmd_index_order = "ORDER BY RDB$DEPENDENCIES.RDB$DEPENDENT_NAME,RDB$DEPENDENCIES.RDB$FIELD_NAME";
            string cmd_index       = $@"{cmd_index0} {case0} {cmd_index_where} {cmd_index_order};";

            dsDependenciesTo.Clear();
            dgvDependenciesTo.AutoGenerateColumns = true;

            try
            {
                var           con = new FbConnection(ConnectionStrings.Instance.MakeConnectionString(_dbReg));
                FbDataAdapter ds  = new FbDataAdapter(cmd_index, con);
                ds.Fill(dsDependenciesTo);
                con.Close();
                dgvDependenciesTo.DataMember = "Table";
                return(dsDependenciesTo.Tables[0].Rows.Count);
            }
            catch (Exception ex)
            {
                _localNotify?.AddToERROR($@"{StaticFunctionsClass.DateTimeNowStr()}->{this.Name}->RefreshDependenciesTo->{ex.Message}");
            }
            return(0);
        }
Esempio n. 2
0
        private void Restart()
        {
            fctSQL.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} Event tracking stopped...{Environment.NewLine}");
            hsTracking.Marked = false;
            List <string> events = new List <string>();

            foreach (ListViewItem lvi in lvEvents.Items)
            {
                if (string.IsNullOrEmpty(lvi.Text))
                {
                    continue;
                }
                events.Add(lvi.Text);
            }
            if (events.Count > 0)
            {
                revent.CancelEvents();
                revent.QueueEvents(events.ToArray());


                //revent.QueueEvents(new string[] { "new_user","update_user" });

                fctSQL.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} Event tracking restarted...{Environment.NewLine}");
                hsTracking.Marked = true;
            }
            else
            {
                fctSQL.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} No events will be tracked !!!{Environment.NewLine}");
            }
        }
Esempio n. 3
0
        public string RemoveComments(string txt)
        {
            //Remove Singleline Comments
            _parentNotifies?.AddToINFO(StaticFunctionsClass.DateTimeNowStr() + " Remove comments");
            Application.DoEvents();
            int remstart = txt.IndexOf(_drc.SingleLineComment);
            int remend   = -1;

            if (remstart >= 0)
            {
                remend = txt.Substring(remstart).IndexOf(_drc.NewLine) + remstart;

                while ((remstart >= 0) && (remend > remstart))
                {
                    txt      = txt.Remove(remstart, remend - remstart + _drc.NewLine.Length);
                    remstart = txt.IndexOf(_drc.SingleLineComment);
                    remend   = txt.IndexOf(_drc.NewLine);
                }
            }

            //Remore Comments
            remstart = txt.IndexOf(_drc.CommentStart);
            if (remstart >= 0)
            {
                remend = txt.IndexOf(_drc.CommentEnd);
                while ((remstart >= 0) && (remend > remstart))
                {
                    txt      = txt.Remove(remstart, remend - remstart + _drc.CommentEnd.Length);
                    remstart = txt.IndexOf(_drc.CommentStart);
                    remend   = txt.IndexOf(_drc.CommentEnd);
                }
            }
            return(txt);
        }
Esempio n. 4
0
        private void ExecuteCommandsFromFile(string filename)
        {
            var fi = new FileInfo(filename);

            if (!fi.Exists)
            {
                return;
            }

            var content = new StringBuilder();

            _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Prepare executing script in file {filename}");
            Application.DoEvents();
            string _connstr = ConnectionStrings.Instance.MakeConnectionString(_actScriptingDbReg);

            _sql = new DBBasicClassLibrary.SQLScriptingClass(_connstr, AppSettingsClass.Instance.SQLVariables.GetNewLine(), AppSettingsClass.Instance.SQLVariables.CommentStart, AppSettingsClass.Instance.SQLVariables.CommentEnd, AppSettingsClass.Instance.SQLVariables.SingleLineComment, "SCRIPT");
            _sql.ScriptNotify.Register4Info(EventMeldungRaised);
            _sql.Commands.Clear();

            int lineCount  = 0;
            int clearAfter = StaticFunctionsClass.ToIntDef(txtClear.Text, 1000);

            fcbCommands.Clear();
            fcbCommands.BeginUpdate();
            content.Clear();
            long mx = fi.Length / 20;

            pbProgress.Maximum = (int)mx;
            pbProgress.Minimum = 0;
            pbProgress.Value   = 0;

            using (var sr = new StreamReader(fi.FullName, Encoding.Default))
            {
                if (pbProgress.Maximum >= pbProgress.Minimum)
                {
                    pbProgress.Value = 0;
                }
                var startDt = DateTime.Now;
                while (!sr.EndOfStream)
                {
                    string str     = sr.ReadLine();
                    bool   cmdeady = _sql.AddCommandLine($@"{str}{Environment.NewLine}");
                    if (!cmdeady)
                    {
                        continue;
                    }
                    lineCount++;
                    var returnList = _sql.RunPreparedCommands();
                    _sql.Commands.Clear();
                }
                fcbCommands.EndUpdate();
                Cursor = Cursors.Default;
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Preparing done {lineCount.ToString()} commands");
                Application.DoEvents();
            }
        }
Esempio n. 5
0
 public string RemoveDoubleSpaces(string txt)
 {
     //Remove double spaces
     _parentNotifies?.AddToINFO(StaticFunctionsClass.DateTimeNowStr() + " Remove double spaces");
     Application.DoEvents();
     while (txt.IndexOf("  ") >= 0)
     {
         txt = txt.Replace("  ", " ");
     }
     return(txt);
 }
Esempio n. 6
0
 public void ScriptInfoRaised(object sender, MessageEventArgs e)
 {
     if (e.Data.GetType() == typeof(SCRIPTCommandClass))
     {
         var sc = (SCRIPTCommandClass)e.Data;
         fcbNotify.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} {e.Meldung}->{e.Key}->{sc.CommandType}->done in {sc.Costs} ms{Environment.NewLine}");
     }
     else
     {
         fcbNotify.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} {e.Meldung}->{e.Key}{Environment.NewLine}");
     }
 }
Esempio n. 7
0
        public string TestForValidation(string txt)
        {
            string cmd = txt.Replace(" ,", ",");

            int indv = cmd.IndexOf("VALUES(");

            if (indv >= 0)
            {
                int    changed = 0;
                string cmd2    = cmd.Substring(indv + 7);
                if (cmd2.Trim().EndsWith(");"))
                {
                    cmd2 = cmd2.Trim().Substring(0, cmd2.Trim().Length - 2);
                }
                string[] arr = cmd2.Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    string arrcmd = arr[i].Trim();
                    int    n      = arrcmd.IndexOf("'", 1);
                    if ((n > -1) && (n < arrcmd.Length - 1))
                    {
                        arrcmd = arrcmd.Insert(n, "'");

                        _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} ...Executing script, Apostroph quotet:{arr[i]}->{arrcmd}");

                        arr[i] = arrcmd;
                        changed++;
                    }
                }
                if (changed > 0)
                {
                    var sb = new StringBuilder();
                    sb.Append(cmd.Substring(0, indv + 7));
                    bool first = true;
                    foreach (string str in arr)
                    {
                        if (!first)
                        {
                            sb.Append(",");
                        }
                        sb.Append(str);
                        first = false;
                    }
                    sb.Append($@");{Environment.NewLine}");
                    return(sb.ToString());
                }
            }
            return(cmd);
        }
Esempio n. 8
0
        public string RefreshIndicesAndGetTablename()
        {
            string cmd_index = SQLStatements.Instance().GetIndiciesByName(_dbReg.Version, IndexName.Trim());

            DataFilled        = false;
            txtIndexName.Text = IndexName.Trim();
            string TableName = string.Empty;

            try
            {
                lvFields.Items.Clear();

                var con = new FbConnection(ConnectionStrings.Instance().MakeConnectionString(_dbReg));
                con.Open();
                string PkColumn        = string.Empty;
                string IndexName       = string.Empty;
                string IndexColumnName = string.Empty;
                int    Unique          = 0;

                FbCommand fcmd  = new FbCommand(cmd_index, con);
                var       dread = fcmd.ExecuteReader();

                if (dread.HasRows)
                {
                    while (dread.Read())
                    {
                        TableName        = dread.GetValue(0).ToString().Trim();
                        IndexColumnName  = dread.GetValue(2).ToString().Trim();
                        Unique           = StaticFunctionsClass.ToIntDef(dread.GetValue(3).ToString().Trim(), 0);
                        cbUnique.Checked = Unique > 0;
                        string[] lv = new string[1];
                        lv[0] = IndexColumnName;

                        ListViewItem lvi = new ListViewItem(lv);
                        lvFields.Items.Add(lvi);
                    }
                    DataFilled = true;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                _localNotify?.AddToERROR(StaticFunctionsClass.DateTimeNowStr() + "->ConstraintForm->RefreshIndices()->" + ex.Message);
            }

            return(TableName);
        }
Esempio n. 9
0
        private void Notify_OnRaiseErrorHandler(object sender, MessageEventArgs k)
        {
            var sb = new StringBuilder();

            _errorCount++;
            if (_messagesCount > 0)
            {
                sb.Append($@"{StaticFunctionsClass.DateTimeNowStr()} Messages ({_messagesCount}) ");
            }
            if (_errorCount > 0)
            {
                sb.Append($@"{StaticFunctionsClass.DateTimeNowStr()} Errors ({_errorCount})");
            }

            fctMessages.AppendText($@"ERROR {k.Meldung}");
            tabPageMessages.Text = sb.ToString();
            fctMessages.ScrollLeft();
        }
Esempio n. 10
0
        private void Restore_ServiceOutput(object sender, FirebirdSql.Data.Services.ServiceOutputEventArgs e)
        {
            n++;
            StaticFunctionsClass.SetDoubleBuffered(lvBackupMessage);
            lvBackupMessage.BeginUpdate();

            string[]     m   = { n.ToString(), e.Message, StaticFunctionsClass.DateTimeNowStr() };
            ListViewItem lvi = new ListViewItem(m);

            lvRestoreMessage.Items.Add(lvi);
            lvRestoreMessage.Items[lvRestoreMessage.Items.Count - 1].EnsureVisible();
            lvRestoreMessage.EndUpdate();

            if (n % 20 == 0)
            {
                Application.DoEvents();
            }
        }
Esempio n. 11
0
        public int RefreshDependenciesTo()
        {
            string cmd = SQLStatementsClass.Instance.GetDepentenciesGenerators(_dbReg.Version, GeneratorObject.Name);

            try
            {
                dsDependenciesTo.Clear();
                dgvDependenciesTo.AutoGenerateColumns = true;

                var con = new FbConnection(ConnectionStrings.Instance.MakeConnectionString(_dbReg));
                var ds  = new FbDataAdapter(cmd, con);
                ds.Fill(dsDependenciesTo);
                con.Close();
                bsDependenciesTo.DataMember = "Table";
                return(dsDependenciesTo.Tables[0].Rows.Count);
            }
            catch (Exception ex)
            {
                NotifiesClass.Instance.AddToERROR($@"{StaticFunctionsClass.DateTimeNowStr()} GeneratorForm -> RefreshDependenciesTo: {ex.Message}");
            }
            return(0);
        }
Esempio n. 12
0
        void InfoRaised(object sender, MessageEventArgs k)
        {
            if (DoInfoNotifications)
            {
                _cmdDone++;
                tabMELDUNG.Text = $@"Messages ({_cmdDone})";
                if (((txtMeldIntervall.Inhalt.Length > 0) && (cbErrAutoclear.Checked)) && (rtfMELDUNG.Lines.Length > Int32.Parse(txtMeldIntervall.Inhalt)))
                {
                    rtfMELDUNG.Clear();
                }

                if (rbMeldAppend.Checked)
                {
                    rtfMELDUNG.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} {k.Meldung}");
                    if (cbAutoScroll.Checked)
                    {
                        rtfMELDUNG.SelectionStart = rtfMELDUNG.TextLength;
                        rtfMELDUNG.Select(rtfMELDUNG.TextLength, 0);
                        rtfMELDUNG.ScrollToCaret();
                        rtfMELDUNG.Refresh();
                    }
                }
                else
                {
                    rtfMELDUNG.SelectionStart = 0;
                    rtfMELDUNG.Select(0, 0);
                    rtfMELDUNG.Text.Insert(0, $@"{StaticFunctionsClass.DateTimeNowStr()} {k.Meldung}");
                    rtfMELDUNG.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} {k.Meldung}");
                }
            }

            var nf = _localNotifies.Find("GLOBAL");

            if (nf == null)
            {
                return;
            }
            nf.Notify.OnRaiseInfo(k);
        }
Esempio n. 13
0
        public void RefreshIndices()
        {
            string cmd_index = IndexSQLStatementsClass.Instance().GetIndiciesByName(_dbReg.Version, IndexName.Trim());

            DataFilled             = false;
            txtConstraintName.Text = IndexName.Trim();

            try
            {
                var con = new FbConnection(ConnectionStrings.Instance().MakeConnectionString(_dbReg));
                con.Open();
                string PkColumn        = string.Empty;
                string IndexName       = string.Empty;
                string IndexColumnName = string.Empty;
                int    Unique          = 0;

                FbCommand fcmd  = new FbCommand(cmd_index, con);
                var       dread = fcmd.ExecuteReader();

                if (dread.HasRows)
                {
                    while (dread.Read())
                    {
                        TableName       = dread.GetValue(0).ToString().Trim();
                        IndexColumnName = dread.GetValue(2).ToString().Trim();
                        Unique          = StaticFunctionsClass.ToIntDef(dread.GetValue(3).ToString().Trim(), 0);

                        string[] lv = new string[1];
                        lv[0] = IndexColumnName;
                    }
                    DataFilled = true;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                _localNotify?.AddToERROR(StaticFunctionsClass.DateTimeNowStr() + "->NotNullForm->RefreshIndices()->" + ex.Message);
            }
        }
Esempio n. 14
0
        public void GetFieldConstraintList(string TableName)
        {
            string cmd = ConstraintsSQLStatementsClass.Instance.GetAllTableConstraintsByTableName(_dbReg.Version, eConstraintType.NOTNULL, TableName);

            DataFilled = false;

            try
            {
                lvFields.Items.Clear();
                var con = new FbConnection(ConnectionStrings.Instance.MakeConnectionString(_dbReg));
                con.Open();
                string        PkColumn  = string.Empty;
                string        IndexName = string.Empty;
                FbCommand     fcmd      = new FbCommand(cmd, con);
                var           dread     = fcmd.ExecuteReader();
                List <string> fields    = new List <string>();
                if (dread.HasRows)
                {
                    while (dread.Read())
                    {
                        TableName = dread.GetValue(0).ToString().Trim();
                        string   FieldName = dread.GetValue(6).ToString().Trim();
                        string[] st        = new string[2];
                        st[0] = FieldName;
                        st[1] = TableName;
                        ListViewItem lvi = new ListViewItem(st);
                        lvFields.Items.Add(lvi);
                    }
                    DataFilled = true;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                _localNotify?.AddToERROR(StaticFunctionsClass.DateTimeNowStr() + "->NotNullForm->RefreshConstraints()->" + ex.Message);
            }
        }
Esempio n. 15
0
        public int RefreshDependencies()
        {
            dsDependencies.Clear();
            dgvDependenciesTo.AutoGenerateColumns = true;

            string cmd_index = SQLStatementsClass.Instance.GetFieldDependencies(_dbReg.Version, TableObject.Name, FieldObject.Name);

            try
            {
                var           con = new FbConnection(ConnectionStrings.Instance.MakeConnectionString(_dbReg));
                FbDataAdapter ds  = new FbDataAdapter(cmd_index, con);
                ds.Fill(dsDependencies);
                con.Close();
                bsDependencies.DataMember = "Table";
                bsDependencies.DataSource = dsDependencies;

                return(dsDependencies.Tables[0].Rows.Count);
            }
            catch (Exception ex)
            {
                NotifiesClass.Instance.AddToERROR($"{StaticFunctionsClass.DateTimeNowStr()}->{Name}->RefreshDependencies->{ex.Message}");
            }
            return(0);
        }
Esempio n. 16
0
 private void Revent_RemoteEventCounts(object sender, FbRemoteEventCountsEventArgs e)
 {
     fctSQL.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} Event occured ->{e.Name}->{e.Counts}");
 }
Esempio n. 17
0
 private void CancelTracking()
 {
     revent.CancelEvents();
     fctSQL.AppendText($@"{Environment.NewLine}{StaticFunctionsClass.DateTimeNowStr()} Event tracking stopped...{Environment.NewLine}");
 }
Esempio n. 18
0
 private void Notify_OnRaiseErrorHandler(object sender, MessageEventArgs k)
 {
     fctMessages.CurrentLineColor = System.Drawing.Color.Red;
     fctMessages.AppendText($@"{StaticFunctionsClass.DateTimeNowStr()} ERROR  {k.Meldung}");
     fctMessages.ScrollLeft();
 }
Esempio n. 19
0
        public string RefreshIndicesAndGetTablename(string _indexObjectName)
        {
            string cmd_index = IndexSQLStatementsClass.Instance.GetIndiciesByName(_dbReg.Version, _indexObjectName.Trim());

            _dataFilled       = false;
            txtIndexName.Text = _indexObjectName.Trim();
            string TableName = string.Empty;

            try
            {
                lvFields.Items.Clear();
                var con = new FbConnection(ConnectionStrings.Instance.MakeConnectionString(_dbReg));
                con.Open();
                string    pkColumn           = string.Empty;
                string    indexName          = string.Empty;
                string    indexColumnName    = string.Empty;
                string    oldIndexColumnName = string.Empty;
                int       Unique             = 0;
                int       IndexType          = -1;
                bool      Active             = false;
                FbCommand fcmd  = new FbCommand(cmd_index, con);
                var       dread = fcmd.ExecuteReader();

                if (dread.HasRows)
                {
                    while (dread.Read())
                    {
                        TableName        = dread.GetValue(0).ToString().Trim();
                        indexColumnName  = dread.GetValue(2).ToString().Trim();
                        Unique           = StaticFunctionsClass.ToIntDef(dread.GetValue(3).ToString().Trim(), 0);
                        Active           = StaticFunctionsClass.ToIntDef(dread.GetValue(4).ToString().Trim(), 0) != 1;
                        IndexType        = StaticFunctionsClass.ToIntDef(dread.GetValue(5).ToString().Trim(), 0);
                        cbUnique.Checked = Unique > 0;
                        ckActive.Checked = Active;

                        if (IndexType < 0)
                        {
                            cbSorting.SelectedItem = eSort.NONE;
                        }
                        else if (IndexType == 0)
                        {
                            cbSorting.SelectedItem = eSort.ASC;
                        }
                        else if (IndexType == 1)
                        {
                            cbSorting.SelectedItem = eSort.DESC;
                        }

                        string[] lv = new string[1];
                        lv[0] = indexColumnName;
                        if (this.oldIndexColumnName != indexColumnName)
                        {
                            ListViewItem lvi = new ListViewItem(indexColumnName);
                            lvFields.Items.Add(lvi);
                            this.oldIndexColumnName = indexColumnName;
                        }
                    }
                    _dataFilled = true;
                }
                con.Close();
            }
            catch (Exception ex)
            {
                _localNotify?.AddToERROR($@"{StaticFunctionsClass.DateTimeNowStr()}->IndexForm->RefreshIndicesAndGetTablename()->{ex.Message}");
            }
            return(TableName);
        }
Esempio n. 20
0
        private void RunSingleCommand(SCRIPTCommandClass command)
        {
            _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing script command");
            Application.DoEvents();
            var _sql = new SQLScriptingClass(_actScriptingDbReg, "SCRIPT", _notifies);

            _sql.ClearCommands();
            FbConnection fbConn   = null;
            FbCommand    fbCmd    = null;
            bool         connOpen = false;

            if (_actScriptingDbReg.DatabasePath.Length > 0)
            {
                var connstr = ConnectionStrings.Instance().MakeConnectionString(_actScriptingDbReg);
                try
                {
                    fbConn = new FbConnection(connstr);
                    fbConn.Open();
                    connOpen = fbConn.State == System.Data.ConnectionState.Open;
                }
                catch (Exception ex)
                {
                    Enabled = false;
                    object[] param = { ex.Message };
                    SEMessageBox.ShowMDIDialog(FbXpertMainForm.Instance(), "DatabaseExceptionCaption", "ErrorWhileOpeningDatabase", SEMessageBoxButtons.OK, SEMessageBoxIcon.Exclamation, null, param);
                    Enabled = true;
                    BringToFront();
                }
            }

            if (connOpen)
            {
                var sw = new Stopwatch();
                sw.Start();
                FbConnection usedCon = IsCreateDatabaseOrConnect(command.CommandText, fbConn);
                if (usedCon != null)
                {
                    //Create database oder connect database
                    fbConn = usedCon;
                }
                else // kein create oder connect, voreingestellte connetion wird verwended
                {
                    fbCmd             = new FbCommand(command.CommandText, fbConn);
                    fbCmd.Transaction = fbConn.BeginTransaction();
                    try
                    {
                        if (command.CommandType == SQLCommandType.commit)
                        {
                            fbCmd.Transaction.Commit();
                        }
                        else
                        {
                            fbCmd.ExecuteNonQuery();
                            if (fbCmd.Transaction != null)
                            {
                                fbCmd.Transaction.Commit();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (fbCmd.Transaction != null)
                        {
                            fbCmd.Transaction.Rollback();
                        }
                        fbCmd.Transaction = null;
                        _notifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"Command error {fbCmd.CommandText}", ex));
                    }
                }
                if (connOpen)
                {
                    fbConn.Close();
                }
                sw.Stop();
                Cursor = Cursors.Default;
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing done in {sw} ms");
                Application.DoEvents();
            }
            else
            {
                _notifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Database {_actScriptingDbReg.Alias} not open ");
                Application.DoEvents();
            }
        }
Esempio n. 21
0
        private FbConnection CreateConnection(string sqlCmd, FbConnection fbConn)
        {
            /*
             * CONNECT 'LOCALHOST:D:\Data\test.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
             */
            string sql      = sqlCmd.ToUpper();
            string location = "D:\\Data\\test111.FDB";

            string user     = "******";
            string password = "******";

            int inx = sql.IndexOf("CONNECT ", StringComparison.Ordinal);

            if (inx >= 0)
            {
                string cmd3 = sqlCmd.Substring(inx + 8);
                int    inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal);
                string arg  = cmd3.Substring(0, inx2);

                int inx3 = arg.IndexOf(":\\", StringComparison.Ordinal);
                int inx4 = arg.IndexOf(":", StringComparison.Ordinal);
                if (inx4 < inx3)
                {
                    //server

                    location = arg.Substring(inx4 + 1);
                    location = location.Replace("'", "");
                }
                else
                {
                    //nur dateipfad

                    location = arg.Replace("'", "");
                }
            }

            inx = sql.IndexOf("USER ", StringComparison.Ordinal);
            if (inx >= 0)
            {
                var cmd3 = sqlCmd.Substring(inx + 5);
                int inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal);
                var arg  = cmd3.Substring(0, inx2);
                user = arg.Replace("'", "");
            }

            inx = sql.IndexOf("PASSWORD ", StringComparison.Ordinal);
            if (inx >= 0)
            {
                var cmd3 = sqlCmd.Substring(inx + 9);

                var arg = cmd3.Substring(0);
                password = arg.Replace("'", "");
            }

            var drc = new DBRegistrationClass
            {
                DatabasePath   = location,
                Dialect        = 3,
                Password       = password,
                User           = user,
                Alias          = "ConScript",
                CharSet        = "UTF8",
                Server         = "localhost",
                ConnectionType = eConnectionType.server
            };


            string connstr = ConnectionStrings.Instance().MakeConnectionString(drc);

            if (fbConn?.State == System.Data.ConnectionState.Open)
            {
                fbConn.Close();
            }
            fbConn = new FbConnection(connstr);
            fbConn.Open();
            _parentNotifies?.AddToINFO(StaticFunctionsClass.DateTimeNowStr() + " ...Opening database via script" + drc);
            _parentNotifies?.AddToINFO(StaticFunctionsClass.DateTimeNowStr() + " ...Database state:" + fbConn.State.ToString());
            return(fbConn);
        }
Esempio n. 22
0
        private bool CreateDatabase(string sqlCmd)
        {
            /*
             *  CREATE DATABASE 'localhost:D:\Data\kj\KJFERT59.FDB'
             *  USER 'SYSDBA' PASSWORD 'masterkey'
             *  PAGE_SIZE 8192
             *  DEFAULT CHARACTER SET NONE;
             */
            string sql        = sqlCmd.ToUpper();
            string location   = "D:\\Data\\test111.FDB";
            string server     = "localhost";
            string user       = "******";
            string password   = "******";
            string packetsize = "8192";

            int inx = sql.IndexOf("CREATE DATABASE ", StringComparison.Ordinal);

            if (inx >= 0)
            {
                string cmd3 = sqlCmd.Substring(inx + 16);
                int    inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal);
                string arg  = cmd3.Substring(0, inx2);

                int inx3 = arg.IndexOf(":\\", StringComparison.Ordinal);
                int inx4 = arg.IndexOf(":", StringComparison.Ordinal);
                if (inx4 < inx3)
                {
                    //server
                    server   = arg.Substring(0, inx4).Replace("'", "");
                    location = arg.Substring(inx4 + 1);
                    location = location.Replace("'", "");
                }
                else
                {
                    //nur dateipfad
                    server   = "localhost";
                    location = arg.Replace("'", "");
                }
            }

            inx = sql.IndexOf("USER ", StringComparison.Ordinal);
            if (inx >= 0)
            {
                string cmd3 = sqlCmd.Substring(inx + 5);
                int    inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal);
                string arg  = cmd3.Substring(0, inx2);
                user = arg.Replace("'", "");
            }

            inx = sql.IndexOf("PASSWORD ", StringComparison.Ordinal);
            if (inx >= 0)
            {
                string cmd3 = sqlCmd.Substring(inx + 9);
                int    inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal);
                string arg  = cmd3.Substring(0, inx2);
                password = arg.Replace("'", "");
            }

            inx = sql.IndexOf("PAGE_SIZE ", StringComparison.Ordinal);
            if (inx >= 0)
            {
                string cmd3 = sqlCmd.Substring(inx + 10);
                int    inx2 = cmd3.IndexOf(" ", StringComparison.Ordinal);
                string arg  = cmd3.Substring(0, inx2);
                packetsize = arg;
            }

            try
            {
                _parentNotifies?.AddToINFO(StaticFunctionsClass.DateTimeNowStr() + " ...Creating new database via script " + server + ":" + location);
                DBProviderSet.CreateDatabase(location, server, user, password, StaticFunctionsClass.ToIntDef(packetsize, AppSettingsClass.Instance().DatabaseSettings.DefaultPacketSize));
            }
            catch (Exception ex)
            {
                NotifiesClass.Instance().AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"{sqlCmd}-> CreateDatabase()", ex));
            }

            return(true);
        }
Esempio n. 23
0
        public List <SQLCommandsReturnInfoClass> RunPreparedCommands()
        {
            //var sb = new StringBuilder();
            var riList = new List <SQLCommandsReturnInfoClass>();

            _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing script");
            Application.DoEvents();



            // int i = 0;
            int nr = 0;


            FbConnection fbConn = null;
            FbCommand    fbCmd  = null;


            if (_drc.DatabasePath.Length > 0)
            {
                var connstr = ConnectionStrings.Instance().MakeConnectionString(_drc);
                try
                {
                    fbConn = new FbConnection(connstr);
                    fbConn.Open();
                }
                catch (Exception ex)
                {
                    object[] param = { ex.Message };
                    SEMessageBox.ShowMDIDialog(FbXpertMainForm.Instance(), "DatabaseExceptionCaption", "ErrorWhileOpeningDatabase", SEMessageBoxButtons.OK, SEMessageBoxIcon.Exclamation, null, param);
                }
            }

            if (fbConn.State == System.Data.ConnectionState.Open)
            {
                var  startDt   = DateTime.Now;
                bool DBRepoend = false;
                bool ReopenConnectionEachCommand = true;
                foreach (SCRIPTCommandClass command in this.Commands.Values)
                {
                    var ri = new SQLCommandsReturnInfoClass();
                    if (ReopenConnectionEachCommand)
                    {
                        if (fbCmd != null && fbCmd.Transaction != null)
                        {
                            ri.lastSQL = "ReopenDatabase";
                            try
                            {
                                fbCmd.Transaction.Commit();
                                fbCmd.Transaction = null;
                                ri.commandDone    = true;
                            }
                            catch (Exception ex)
                            {
                                ri.commandDone = false;
                                _parentNotifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"Command error {fbCmd.CommandText}", ex));
                                if (fbCmd.Transaction != null)
                                {
                                    fbCmd.Transaction.Rollback();
                                    fbCmd.Transaction = null;
                                }
                            }
                        }
                        fbConn.Close();
                        fbConn.Open();
                        DBRepoend = fbConn.State == System.Data.ConnectionState.Open;
                    }

                    var actDt = DateTime.Now;
                    if ((actDt.Ticks - startDt.Ticks) > 30000000000)
                    {
                        _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} ...Executing script{nr.ToString()} commands done of {Commands.Count}.");
                    }


                    FbConnection usedCon = IsCreateDatabaseOrConnect(command.CommandText, fbConn);
                    if (usedCon != null)
                    {
                        //Create Databes oder connect
                        if (fbConn != null)
                        {
                            if (fbConn.State != System.Data.ConnectionState.Closed)
                            {
                                fbConn.Close();
                            }
                        }
                        fbConn = usedCon;
                        if (fbConn.State != System.Data.ConnectionState.Open)
                        {
                            fbConn.Open();
                        }
                        continue;
                    }

                    if (fbCmd == null || fbCmd.Transaction == null || DBRepoend)
                    {
                        fbCmd             = new FbCommand(command.CommandText, fbConn);
                        fbCmd.Transaction = fbConn.BeginTransaction();
                        DBRepoend         = false;
                    }
                    else
                    {
                        fbCmd.CommandText = command.CommandText;
                    }

                    var sw = new Stopwatch();
                    sw.Start();
                    ri.lastCommandType = command.CommandType;
                    ri.lastSQL         = command.CommandText;
                    try
                    {
                        if (command.CommandType == SQLCommandType.commit)
                        {
                            fbCmd.Transaction.Commit();

                            fbCmd.Transaction = null;
                        }
                        else
                        {
                            fbCmd.ExecuteNonQuery();
                        }
                        ri.commandDone = true;
                    }
                    catch (Exception ex)
                    {
                        ri.nErrors++;
                        ri.lastError   = ex.Message;
                        ri.commandDone = false;
                        _parentNotifies?.AddToERROR(AppStaticFunctionsClass.GetFormattedError($@"Command error {fbCmd.CommandText}", ex));
                        if (fbCmd.Transaction != null)
                        {
                            fbCmd.Transaction.Rollback();
                            fbCmd.Transaction = null;
                        }
                    }
                    sw.Stop();
                    command.Costs = sw.ElapsedMilliseconds;
                    _eventNotifies?.Notify.RaiseInfo($@"SQLScriptingClass.RunPreparedCommands()", Constants.CommandDone, command);
                    ri.costs = sw.ElapsedMilliseconds;
                    riList.Add(ri);
                    nr++;
                }

                if (fbCmd != null && fbCmd.Transaction != null)
                {
                    fbCmd.Transaction.Commit();

                    fbCmd.Transaction = null;
                }

                if (fbConn.State == System.Data.ConnectionState.Open)
                {
                    fbConn.Close();
                }
            }

            _parentNotifies?.AddToINFO($@"{StaticFunctionsClass.DateTimeNowStr()} Executing done {nr.ToString()} Commands");
            Application.DoEvents();
            return(riList);
        }