private string CreateSqlSentence(object treeitem, SqlKind sqlKind, int limitCount = 0)
        {
            string[] colums;
            var      col   = treeitem as ColumViewMoodel;
            var      table = GetTreeViewTableName(CurrentDatabase, treeitem);

            if (col == null)
            {
                colums = table.Colums.Select(x => x.ColumName).ToArray();
            }
            else
            {
                colums = new[] { col.ColumName };
            }

            if (sqlKind == SqlKind.Select)
            {
                return(CreateSelectStatement(table.TableName, colums, limitCount));
            }
            else if (sqlKind == SqlKind.Insert)
            {
                return(CreateInsertStatement(table.TableName, colums));
            }
            else if (sqlKind == SqlKind.Update)
            {
                return(CreateUpdateStatement(table.TableName, colums));
            }
            else
            {
                return("");
            }
        }
Ejemplo n.º 2
0
 public SqlToken(SqlKind kind, int start, int end, SqlNode parent)
 {
     this.Parent = parent;
     this.Kind   = kind;
     this.Start  = start;
     this.End    = end;
 }
Ejemplo n.º 3
0
        private static bool TryMatch(ImmutableArray <RawToken> tokens, int position, SqlKind kind, out RawToken token)
        {
            if (tokens.TryElementAt(position, out token) &&
                token.Kind == kind)
            {
                return(true);
            }

            token = default;
            return(false);
        }
Ejemplo n.º 4
0
            internal static bool TryParse(string sql, int position, string expected, SqlKind kind, out RawToken token)
            {
                if (TryMatch(sql, position, expected))
                {
                    token = new RawToken(kind, position, position + expected.Length);
                    return(true);
                }

                token = default;
                return(false);
            }
Ejemplo n.º 5
0
 public SqlStatement(SqlKind kind, SqlFragment sql, SqlPlaceHolderList placeHolders, DbExecutionType executionType,
                     SqlPrecedenceHandler precedenceHandler = null, QueryOptions options = QueryOptions.None)
 {
     Kind          = kind;
     ExecutionType = executionType;
     Options       = options;
     Append(sql, placeHolders, precedenceHandler);
     if (placeHolders == null)
     {
         DiscoverPlaceholders();
     }
 }
Ejemplo n.º 6
0
            internal static bool TryParse(string sql, int position, char expected, SqlKind kind, out RawToken token)
            {
                if (sql.TryElementAt(position, out var c) &&
                    c == expected)
                {
                    token = RawToken.SingleChar(kind, position);
                    return(true);
                }

                token = default;
                return(false);
            }
Ejemplo n.º 7
0
        internal bool PeekKind(SqlKind kind)
        {
            SqlKind?k = Peek.FirstOrDefault()?.Kind;

            return(kind == k);
        }
Ejemplo n.º 8
0
 public bool IsKind(SqlKind kind)
 {
     return(Current?.Kind == kind);
 }
 private SqlStatement CreateNonQueryStatement(SqlFragment sql, SqlKind kind)
 {
     // Placeholders = null means that placeholders should be rediscovered
     return(new SqlStatement(kind, sql, null, DbExecutionType.NonQuery, this.SqlDialect.PrecedenceHandler, QueryOptions.NoQueryCache));
 }
Ejemplo n.º 10
0
 public RawToken(SqlKind kind, int start, int end)
 {
     this.Kind  = kind;
     this.Start = start;
     this.End   = end;
 }
Ejemplo n.º 11
0
 public RawToken WithKind(SqlKind kind) => new RawToken(kind, this.Start, this.End);
Ejemplo n.º 12
0
 public static RawToken SingleChar(SqlKind type, int position) => new RawToken(type, position, position + 1);
Ejemplo n.º 13
0
        //, bool StartOrCondition = false, bool EndOrCondition = false
        public static string GetSql(out SqlParameter prm, object obj, string Col, SqlKind kind, bool AddAndAfter = true, object forbetween = null, bool AfterOr = false, string ManualAdd = null)
        {
            string Sql      = "";
            string Aftersql = " ";

            if (AfterOr)
            {
                Aftersql = " OR ";
            }
            if (ManualAdd != null)
            {
                Aftersql = ManualAdd;
            }
            string Column  = Col;
            string PrmName = "";

            if (obj.ToString() == "")
            {
                prm = null;
                return("");
            }

            /*switch (obj.GetType().Name)
             * {
             *  case "String":
             *      //ForType = "'";
             *      break;
             *  case "DateTime":
             *      ForType = "#";
             *      break;
             * }*/
            prm = null;

            PrmName = "P" + TempId;
            if (AddAndAfter)
            {
                Aftersql = " AND ";
            }
            switch (kind)
            {
            case SqlKind.EQUAL:
                prm = new SqlParameter("@" + PrmName, obj.ToString());
                Sql = Col + "=@" + PrmName + Aftersql;
                break;

            case SqlKind.LIKE:
                prm = new SqlParameter("@" + PrmName, "%" + obj.ToString() + "%");
                Sql = Col + " LIKE @" + PrmName + Aftersql;
                break;

            case SqlKind.BEQUAL:
                prm = new SqlParameter("@" + PrmName, obj.ToString() + "*");
                Sql = Col + "=@" + PrmName + Aftersql;
                break;

            case SqlKind.AEQUAL:
                prm = new SqlParameter("@" + PrmName, "*" + obj.ToString());
                Sql = Col + "=@" + PrmName + Aftersql;
                break;

            case SqlKind.ABEQUAL:
                prm = new SqlParameter("@" + PrmName, "*" + obj.ToString() + "*");
                Sql = Col + "=@" + PrmName + Aftersql;
                break;

            case SqlKind.BETWEEN:
                prm = new SqlParameter("@" + PrmName, obj.ToString());
                Sql = Col + " BETWEEN @" + PrmName + " AND " + forbetween.ToString() + Aftersql;
                break;
            }
            //if (StartOrCondition) Sql = " ( " + Sql;
            //if (EndOrCondition)
            //{
            //    Sql = Sql.Substring(Sql.IndexOf(Aftersql));
            //    Sql += " ) " + Aftersql;
            //}
            TempId++;
            return(Sql);
        }
        private string CreateSqlSentence(object treeitem, SqlKind sqlKind, int limitCount = 0)
        {
            string[] colums;
            var col = treeitem as ColumViewMoodel;
            var table = GetTreeViewTableName(CurrentDatabase, treeitem);

            if (col == null)
            {
                colums = table.Colums.Select(x => x.ColumName).ToArray();
            }
            else
            {
                colums = new[] { col.ColumName };
            }

            if (sqlKind == SqlKind.Select)
            {
                return CreateSelectStatement(table.TableName, colums, limitCount);
            }
            else if (sqlKind == SqlKind.Insert)
            {
                return CreateInsertStatement(table.TableName, colums);
            }
            else if (sqlKind == SqlKind.Update)
            {
                return CreateUpdateStatement(table.TableName, colums);
            }
            else
            {
                return "";
            }
        }