コード例 #1
0
ファイル: Mysqlx.cs プロジェクト: zhouweiaccp/MySQL.Data
        public override int GetHashCode()
        {
            int hash = 1;

            if (Severity != 0)
            {
                hash ^= Severity.GetHashCode();
            }
            if (Code != 0)
            {
                hash ^= Code.GetHashCode();
            }
            if (SqlState.Length != 0)
            {
                hash ^= SqlState.GetHashCode();
            }
            if (Msg.Length != 0)
            {
                hash ^= Msg.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #2
0
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                hashcode = (hashcode * 397) + StatusCode.GetHashCode();
                if (__isset.infoMessages)
                {
                    hashcode = (hashcode * 397) + TCollections.GetHashCode(InfoMessages);
                }
                if (__isset.sqlState)
                {
                    hashcode = (hashcode * 397) + SqlState.GetHashCode();
                }
                if (__isset.errorCode)
                {
                    hashcode = (hashcode * 397) + ErrorCode.GetHashCode();
                }
                if (__isset.errorMessage)
                {
                    hashcode = (hashcode * 397) + ErrorMessage.GetHashCode();
                }
            }
            return(hashcode);
        }
コード例 #3
0
    /// <summary>
    /// 插入路径
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="route"></param>
    /// <returns></returns>
    public SqlState InsertRoute(String userName, string route)
    {
        int      userId;
        SqlState sqlState = GetIdByUserName(userName, out userId);

        if (sqlState != SqlState.Success)
        {
            return(sqlState);
        }
        sql.ExecuteQuery("PRAGMA foreign_keys = ON; ");
        SqliteDataReader reader = sql.InsertValues(SQLUserRoute, new string[] { "User_Id", "Route" }, new string[] { string.Format("{0}", userId), route });

        return(SqlState.Success);
    }
コード例 #4
0
    //插入路径
    public SqlState InsertRoute(string UserName, RouteInfo routeInfo)
    {
        int      userId;
        SqlState sqlState = GetIdByUserName(UserName, out userId);

        if (sqlState != SqlState.Success)
        {
            return(sqlState);
        }
        routeInfo.UserId = userId;
        sql.ExecuteQuery("PRAGMA foreign_keys = ON; ");
        SqliteDataReader reader = sql.InsertValues(SQLUserRoute, new string[] { "User_Id", "Scene_Id", "Start", "Middle", "Destination", "Route", "RouteOrder", "StepNum", "Duration", "fieldOne", "fieldTwo", "MiddleStep" }, routeInfo.GetStr());

        return(SqlState.Success);
    }
コード例 #5
0
        public override int GetHashCode()
        {
            int hashcode = 157;

            unchecked {
                hashcode = (hashcode * 397) + Status.GetHashCode();
                if (__isset.operationState)
                {
                    hashcode = (hashcode * 397) + OperationState.GetHashCode();
                }
                if (__isset.sqlState)
                {
                    hashcode = (hashcode * 397) + SqlState.GetHashCode();
                }
                if (__isset.errorCode)
                {
                    hashcode = (hashcode * 397) + ErrorCode.GetHashCode();
                }
                if (__isset.errorMessage)
                {
                    hashcode = (hashcode * 397) + ErrorMessage.GetHashCode();
                }
                if (__isset.taskStatus)
                {
                    hashcode = (hashcode * 397) + TaskStatus.GetHashCode();
                }
                if (__isset.operationStarted)
                {
                    hashcode = (hashcode * 397) + OperationStarted.GetHashCode();
                }
                if (__isset.operationCompleted)
                {
                    hashcode = (hashcode * 397) + OperationCompleted.GetHashCode();
                }
                if (__isset.hasResultSet)
                {
                    hashcode = (hashcode * 397) + HasResultSet.GetHashCode();
                }
                if (__isset.progressUpdateResponse)
                {
                    hashcode = (hashcode * 397) + ProgressUpdateResponse.GetHashCode();
                }
            }
            return(hashcode);
        }
コード例 #6
0
        /// <summary>
        /// Given a SQL-like query, return a a Select object, ready for adding parameters and querying
        /// </summary>
        /// <param name="sql">SQL-like query</param>
        /// <returns>Select object for adding parameters and executing</returns>
        public static Select Parse(string sql)
        {
            string[] tokens = Utils.Tokenize(sql);
            if (tokens.Length == 0 || (tokens.Length == 1 && string.IsNullOrWhiteSpace(tokens[0])))
            {
                throw new SqlException("No tokens", sql);
            }

            Select   select = new Select();
            SqlState state  = SqlState.SELECT;
            int      idx    = 0;

            while (idx < tokens.Length)
            {
                string currentToken = tokens[idx];
                if (state == SqlState.SELECT)
                {
                    // Should start with SELECT
                    if (!currentToken.Equals("SELECT", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new SqlException("No SELECT", sql);
                    }

                    // Slurp up the SELECT columns
                    select.select = new List <string>();
                    while (true)
                    {
                        ++idx;
                        if (idx >= tokens.Length)
                        {
                            throw new SqlException("No SELECT columns", sql);
                        }

                        currentToken = tokens[idx];

                        bool lastColumn = !currentToken.EndsWith(",", StringComparison.Ordinal);
                        if (!lastColumn)
                        {
                            currentToken = currentToken.TrimEnd(',');
                        }

                        Utils.ValidateColumnName(currentToken, sql);
                        select.select.Add(currentToken);

                        if (lastColumn)
                        {
                            break;
                        }
                    }

                    ++idx;
                    state = SqlState.FROM;
                    continue;
                }

                if (state == SqlState.FROM)
                {
                    if (!currentToken.Equals("FROM", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new SqlException("No FROM", sql);
                    }

                    ++idx;
                    if (idx >= tokens.Length)
                    {
                        throw new SqlException("No FROM table", sql);
                    }
                    currentToken = tokens[idx];
                    Utils.ValidateTableName(currentToken, sql);
                    select.from = currentToken;
                    ++idx;
                    state = SqlState.WHERE;
                    continue;
                }

                if (state == SqlState.WHERE)
                {
                    if (!currentToken.Equals("WHERE", StringComparison.OrdinalIgnoreCase))
                    {
                        state = SqlState.ORDER;
                        continue;
                    }

                    // Gobble up WHERE criteria
                    CriteriaSet criteriaSet = new CriteriaSet();
                    select.where = new List <CriteriaSet> {
                        criteriaSet
                    };
                    ++idx;
                    while ((idx + 3) <= tokens.Length)
                    {
                        var criteria =
                            new Criteria()
                        {
                            name      = tokens[idx++],
                            op        = tokens[idx++],
                            paramName = tokens[idx++]
                        };
                        Utils.ValidateColumnName(criteria.name, sql);
                        Utils.ValidateOperator(criteria.op, sql);
                        Utils.ValidateParameterName(criteria.paramName, sql);
                        criteriaSet.AddCriteria(criteria);

                        if
                        (
                            (idx + 3) <= tokens.Length
                            &&
                            tokens[idx].Equals("AND", StringComparison.OrdinalIgnoreCase)
                        )
                        {
                            ++idx;
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (criteriaSet.criteria.Count == 0)
                    {
                        throw new SqlException("No WHERE criteria", sql);
                    }

                    state = SqlState.ORDER;
                    continue;
                }

                if (state == SqlState.ORDER)
                {
                    string nextToken = (idx + 1) < tokens.Length ? tokens[idx + 1] : "";
                    if
                    (
                        (idx + 3) > tokens.Length
                        ||
                        !currentToken.Equals("ORDER", StringComparison.OrdinalIgnoreCase)
                        ||
                        !nextToken.Equals("BY", StringComparison.OrdinalIgnoreCase)
                    )
                    {
                        state = SqlState.LIMIT;
                        continue;
                    }

                    idx += 2;

                    var orders = new List <Order>();
                    select.orderBy = orders;
                    while (idx < tokens.Length)
                    {
                        currentToken = tokens[idx];

                        bool currentEnds = idx == tokens.Length - 1 || currentToken.EndsWith(",", StringComparison.Ordinal);

                        nextToken = "ASC";
                        if (!currentEnds)
                        {
                            if ((idx + 1) < tokens.Length)
                            {
                                nextToken = tokens[++idx];
                            }
                        }

                        bool nextEnds = nextToken.EndsWith(",", StringComparison.Ordinal);

                        bool isLimit = nextToken.Equals("LIMIT", StringComparison.OrdinalIgnoreCase);

                        bool lastColumn = isLimit || !(currentEnds || nextEnds);

                        currentToken = currentToken.TrimEnd(',');
                        nextToken    = nextToken.TrimEnd(',');

                        bool isDescending;
                        {
                            if (nextToken.Equals("ASC", StringComparison.OrdinalIgnoreCase))
                            {
                                isDescending = false;
                            }
                            else if (nextToken.Equals("DESC", StringComparison.OrdinalIgnoreCase))
                            {
                                isDescending = true;
                            }
                            else if (isLimit)
                            {
                                isDescending = false;
                            }
                            else
                            {
                                throw new SqlException("Invalid ORDER BY", sql);
                            }
                        }

                        Utils.ValidateColumnName(currentToken, sql);

                        var orderObj = new Order()
                        {
                            field = currentToken, descending = isDescending
                        };
                        orders.Add(orderObj);

                        if (!isLimit)
                        {
                            ++idx;
                        }

                        if (lastColumn)
                        {
                            break;
                        }
                    }

                    state = SqlState.LIMIT;
                    continue;
                }

                if (state == SqlState.LIMIT)
                {
                    if (currentToken.Equals("LIMIT", StringComparison.OrdinalIgnoreCase))
                    {
                        ++idx;
                        if (idx >= tokens.Length)
                        {
                            throw new SqlException("No LIMIT value", sql);
                        }
                        currentToken = tokens[idx];

                        int limitVal;
                        if (!int.TryParse(currentToken, out limitVal))
                        {
                            throw new SqlException("Invalid LIMIT value", sql);
                        }
                        select.limit = limitVal;

                        ++idx;
                        break;
                    }
                    else
                    {
                        throw new SqlException("Invalid final statement", sql);
                    }
                }

                throw new SqlException($"Invalid SQL parser state: {state}", sql);
            }

            if (idx < tokens.Length - 1)
            {
                throw new SqlException("Not all parsed", sql);
            }

            if (select.select.Count == 0)
            {
                throw new SqlException("No SELECT columns", sql);
            }

            if (string.IsNullOrWhiteSpace(select.from))
            {
                throw new SqlException("No FROM", sql);
            }

            return(select);
        }
コード例 #7
0
ファイル: SqlParser.cs プロジェクト: Barnickle/InnovatorAdmin
        public IEnumerable<string> FindSqlServerObjectNames(string sql)
        {
            _state = SqlState.Other;
              _keepCurrIdent = false;
              _lastIdentifier = string.Empty;
              _identStart = 0;
              _idents = new List<string>();

              for (int i = 0; i < sql.Length; i++)
              {
            switch (_state)
            {
              case SqlState.BracketIdentifier:
            if (sql[i] == ']')
            {
              PushIdent(sql.Substring(_identStart, i - _identStart));
              _state = SqlState.Other;
            }
            break;
              case SqlState.Identifier:
            if (!(char.IsLetterOrDigit(sql[i]) || sql[i] == '_'))
            {
              PushIdent(sql.Substring(_identStart, i - _identStart));
              if (sql[i] == '.' || sql[i] == '(')
              {
                _lastIdentifier += sql[i];
              }
              _state = SqlState.Other;
            }
            break;
              case SqlState.MultiLineComment:
            if (sql[i] == '/' && i > 0 && sql[i - 1] == '*') _state = SqlState.Other;
            break;
              case SqlState.QuotedIdentifier:
            if (sql[i] == '"')
            {
              PushIdent(sql.Substring(_identStart, i - _identStart));
              _state = SqlState.Other;
            }
            break;
              case SqlState.SingleLineComment:
            if (sql[i] == '\r' || sql[i] == '\n') _state = SqlState.Other;
            break;
              case SqlState.String:
            if (sql[i] == '\'') _state = SqlState.Other;
            break;
              case SqlState.Other:
            if (sql[i] == '[')
            {
              _identStart = i + 1;
              _state = SqlState.BracketIdentifier;
            }
            else if (sql[i] == '*' && i > 0 && sql[i - 1] == '/')
            {
              _state = SqlState.MultiLineComment;
            }
            else if (sql[i] == '"')
            {
              _identStart = i + 1;
              _state = SqlState.QuotedIdentifier;
            }
            else if (sql[i] == '-' && i > 0 && sql[i - 1] == '-')
            {
              _state = SqlState.SingleLineComment;
            }
            else if (sql[i] == '\'')
            {
              _state = SqlState.String;
            }
            else if (char.IsLetter(sql[i]))
            {
              _identStart = i;
              _state = SqlState.Identifier;
            }
            else if (sql[i] == '.' && i == _identStart + _lastIdentifier.Length)
            {
              _lastIdentifier += ".";
            }
            else if (char.IsWhiteSpace(sql[i]))
            {
              // Do nothing, for now
            }
            else
            {
              _lastIdentifier = string.Empty;
            }
            break;
            }
              }
              TryCaptureIdent();

              return _idents;
        }
コード例 #8
0
        public IEnumerable <string> FindSqlServerObjectNames(string sql)
        {
            _state          = SqlState.Other;
            _keepCurrIdent  = false;
            _lastIdentifier = string.Empty;
            _identStart     = 0;
            _idents         = new List <string>();

            for (int i = 0; i < sql.Length; i++)
            {
                switch (_state)
                {
                case SqlState.BracketIdentifier:
                    if (sql[i] == ']')
                    {
                        PushIdent(sql.Substring(_identStart, i - _identStart));
                        _state = SqlState.Other;
                    }
                    break;

                case SqlState.Identifier:
                    if (!(char.IsLetterOrDigit(sql[i]) || sql[i] == '_'))
                    {
                        PushIdent(sql.Substring(_identStart, i - _identStart));
                        if (sql[i] == '.' || sql[i] == '(')
                        {
                            _lastIdentifier += sql[i];
                        }
                        _state = SqlState.Other;
                    }
                    break;

                case SqlState.MultiLineComment:
                    if (sql[i] == '/' && i > 0 && sql[i - 1] == '*')
                    {
                        _state = SqlState.Other;
                    }
                    break;

                case SqlState.QuotedIdentifier:
                    if (sql[i] == '"')
                    {
                        PushIdent(sql.Substring(_identStart, i - _identStart));
                        _state = SqlState.Other;
                    }
                    break;

                case SqlState.SingleLineComment:
                    if (sql[i] == '\r' || sql[i] == '\n')
                    {
                        _state = SqlState.Other;
                    }
                    break;

                case SqlState.String:
                    if (sql[i] == '\'')
                    {
                        _state = SqlState.Other;
                    }
                    break;

                case SqlState.Other:
                    if (sql[i] == '[')
                    {
                        _identStart = i + 1;
                        _state      = SqlState.BracketIdentifier;
                    }
                    else if (sql[i] == '*' && i > 0 && sql[i - 1] == '/')
                    {
                        _state = SqlState.MultiLineComment;
                    }
                    else if (sql[i] == '"')
                    {
                        _identStart = i + 1;
                        _state      = SqlState.QuotedIdentifier;
                    }
                    else if (sql[i] == '-' && i > 0 && sql[i - 1] == '-')
                    {
                        _state = SqlState.SingleLineComment;
                    }
                    else if (sql[i] == '\'')
                    {
                        _state = SqlState.String;
                    }
                    else if (char.IsLetter(sql[i]))
                    {
                        _identStart = i;
                        _state      = SqlState.Identifier;
                    }
                    else if (sql[i] == '.' && i == _identStart + _lastIdentifier.Length)
                    {
                        _lastIdentifier += ".";
                    }
                    else if (char.IsWhiteSpace(sql[i]))
                    {
                        // Do nothing, for now
                    }
                    else
                    {
                        _lastIdentifier = string.Empty;
                    }
                    break;
                }
            }
            TryCaptureIdent();

            return(_idents);
        }