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(""); } }
public SqlToken(SqlKind kind, int start, int end, SqlNode parent) { this.Parent = parent; this.Kind = kind; this.Start = start; this.End = end; }
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); }
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); }
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(); } }
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); }
internal bool PeekKind(SqlKind kind) { SqlKind?k = Peek.FirstOrDefault()?.Kind; return(kind == k); }
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)); }
public RawToken(SqlKind kind, int start, int end) { this.Kind = kind; this.Start = start; this.End = end; }
public RawToken WithKind(SqlKind kind) => new RawToken(kind, this.Start, this.End);
public static RawToken SingleChar(SqlKind type, int position) => new RawToken(type, position, position + 1);
//, 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 ""; } }