private void DeserializeSQLStatements()
        {
            // whooo boy
            List <string> SQLText     = new List <string>();
            List <string> ContextList = new List <string>();

            /* read in all SQLText */
            var sqlTextCount = ReadUint();

            for (var x = 0; x < sqlTextCount; x++)
            {
                SQLText.Add(ReadString());
            }

            /* read in all Context List */
            var contextCount = ReadUint();

            for (var x = 0; x < contextCount; x++)
            {
                ContextList.Add(ReadString());
            }

            var totalStatements = ReadUint();

            for (var x = 0; x < totalStatements; x++)
            {
                var          statementIndex = ReadUint();
                SQLStatement item           = new SQLStatement(SQLText[(int)statementIndex]);
                Data.SQLStatements.Add(item);

                item.InternalID = ReadUint();
                item.LineNumber = ReadLong();
                var parentPresent = ReadBool();

                if (parentPresent)
                {
                    SQLToResolveParent.Add(item, ReadUint());
                }
                item.FetchCount = ReadInt();
                item.ExecTime   = ReadDouble();
                item.FetchTime  = ReadDouble();
                item.IsError    = ReadBool();

                var errorPresent = ReadBool();
                if (errorPresent)
                {
                    item.ErrorInfo               = new SQLError();
                    item.ErrorInfo.InternalID    = ReadUint();
                    item.ErrorInfo.ErrorPosition = (int)ReadUint();
                    item.ErrorInfo.ReturnCode    = (int)ReadUint();
                    item.ErrorInfo.Message       = ReadString();
                }

                item.RCNumber = (int)ReadUint();

                var contextIndex = ReadUint();
                item.Context = ContextList[(int)contextIndex];

                var bindCount = ReadUint();

                for (var y = 0; y < bindCount; y++)
                {
                    SQLBindValue bind = new SQLBindValue();
                    item.BindValues.Add(bind);

                    bind.InternalID = ReadUint();
                    bind.Index      = (int)ReadUint();
                    bind.Type       = (int)ReadUint();
                    bind.Length     = (int)ReadUint();
                    bind.Value      = ReadString();
                }
            }
        }
Beispiel #2
0
        public void ProcessLine(string line, long lineNumber)
        {
            if (lineValid.IsMatch(line) == false)
            {
                return;
            }


            Match m = newStatement.Match(line);

            if (m.Success)
            {
                if (currentStatement != null)
                {
                    Statements.Add(currentStatement);
                }
                string context = contextMarker.Match(line).Groups[0].Value;

                currentStatement            = new SQLStatement(m.Groups[3].Value);
                currentStatement.Context    = context;
                currentStatement.RCNumber   = int.Parse(m.Groups[1].Value);
                currentStatement.LineNumber = lineNumber;

                /* AET TRC files don't have explicit Exec statements, so set the Exec time from the COM Stmt line's Duration */
                /* this will be overwritten in case we are in a tracesql file by the subsequent Exec statement */
                currentStatement.ExecTime = double.Parse(m.Groups[2].Value);
                return;
            }

            m = execStatement.Match(line);
            if (m.Success)
            {
                currentStatement.ExecTime = double.Parse(m.Groups[2].Value);
                return;
            }

            m = fetchStatement.Match(line);
            if (m.Success)
            {
                if (int.Parse(m.Groups[1].Value) != currentStatement.RCNumber)
                {
                    return;
                }

                currentStatement.FetchCount++;
                currentStatement.FetchTime += double.Parse(m.Groups[2].Value);
                return;
            }

            m = bindStatement.Match(line);
            if (m.Success)
            {
                SQLBindValue bind = new SQLBindValue();
                bind.Index  = int.Parse(m.Groups[1].Value);
                bind.Type   = int.Parse(m.Groups[2].Value);
                bind.Length = int.Parse(m.Groups[3].Value);
                bind.Value  = m.Groups[4].Value;
                currentStatement.BindValues.Add(bind);
                return;
            }

            m = errPosStatement.Match(line);
            if (m.Success)
            {
                /* we have an error on this SQL */
                currentStatement.IsError   = true;
                currentStatement.ErrorInfo = new SQLError();

                currentStatement.ErrorInfo.ErrorPosition = Int32.Parse(m.Groups[1].Value);
                return;
            }

            m = errorLine.Match(line);
            if (m.Success)
            {
                currentStatement.ErrorInfo.ReturnCode = Int32.Parse(m.Groups[1].Value);
                currentStatement.ErrorInfo.Message    = m.Groups[2].Value;
            }
        }
Beispiel #3
0
        public void ProcessLine(string line, long lineNumber)
        {
            if (stepHasSQL.IsMatch(line))
            {
                expectingSQL = true;
                return;
            }

            if (line.Equals("-- Buffers:"))
            {
                expectingBuffers = true;
                return;
            }

            if (line.Equals("-- Bind variables:"))
            {
                expectingBinds = true;
                return;
            }

            if (expectingBuffers)
            {
                var match = bufferBindValue.Match(line);
                if (match.Success)
                {
                    /* add to buffer of previous SQL */
                    if (latestSQLStatement.BufferData == null)
                    {
                        /* init buffer data */
                        latestSQLStatement.BufferData = new List <string>();
                    }
                    latestSQLStatement.BufferData.Add(match.Groups[2].Value);
                }
                else
                {
                    expectingBuffers = false;
                    return;
                }
            }

            if (expectingBinds)
            {
                var match = bufferBindValue.Match(line);
                if (match.Success)
                {
                    /* add to buffer of previous SQL */
                    if (latestSQLStatement.BindValues == null)
                    {
                        /* init buffer data */
                        latestSQLStatement.BindValues = new List <SQLBindValue>();
                    }
                    SQLBindValue bind = new SQLBindValue();
                    bind.Index  = int.Parse(match.Groups[1].Value);
                    bind.Type   = 0;
                    bind.Length = match.Groups[2].Value.Length;
                    bind.Value  = match.Groups[2].Value;

                    latestSQLStatement.BindValues.Add(bind);
                }
                else
                {
                    expectingBinds = false;
                    return;
                }
            }

            if (expectingSQL && line.Equals("/") == false)
            {
                if (sqlStartLine == 0)
                {
                    sqlStartLine = lineNumber;
                }

                /* dirty check for if we might be in a loop or something and we dont have a SQL where we expect it */
                if (line.StartsWith("--"))
                {
                    /* this isn't where we want to be... false positive for SQL statement */
                    sqlStartLine = 0;
                    currentSQL.Clear();
                    expectingSQL = false;
                    return;
                }

                currentSQL.Append(line);
                return;
            }

            if (expectingSQL && line.Equals("/"))
            {
                latestSQLStatement            = new SQLStatement(currentSQL.ToString());
                latestSQLStatement.LineNumber = sqlStartLine;

                statements.Add(latestSQLStatement);

                /* reset state */
                sqlStartLine = 0;
                currentSQL.Clear();
                expectingSQL = false;
            }

            //throw new System.NotImplementedException();
        }