public void GetSql(DbTarget db_target, ref StringBuilder sql) { if (db_target == DbTarget.SqlServer) { sql.Append("CHARINDEX("); if (!_expressionToFind.IsLiteral) { sql.Append("("); } _expressionToFind.GetSql(db_target, ref sql); if (!_expressionToFind.IsLiteral) { sql.Append(")"); } sql.Append(","); if (!_expressionToSearch.IsLiteral) { sql.Append("("); } _expressionToSearch.GetSql(db_target, ref sql); if (!_expressionToSearch.IsLiteral) { sql.Append(")"); } } else { sql.Append("LOCATE("); if (!_expressionToSearch.IsLiteral) { sql.Append("("); } _expressionToSearch.GetSql(db_target, ref sql); if (!_expressionToSearch.IsLiteral) { sql.Append(")"); } sql.Append(","); if (!_expressionToFind.IsLiteral) { sql.Append("("); } _expressionToFind.GetSql(db_target, ref sql); if (!_expressionToFind.IsLiteral) { sql.Append(")"); } } sql.Append(","); sql.Append(_startLocation.ToString()); sql.Append(")"); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { switch (db_target) { case DbTarget.SqlServer: sql.Append("SUBSTRING("); break; case DbTarget.MySql: sql.Append("SUBSTRING("); break; case DbTarget.SqlLite: sql.Append("SUBSTR("); break; } if (!_Expression.IsLiteral) { sql.Append("("); } _Expression.GetSql(db_target, ref sql); if (!_Expression.IsLiteral) { sql.Append(")"); } sql.Append(_Position.ToString()); sql.Append(","); sql.Append(_Length.ToString()); sql.Append(")"); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { if (!_Expression1.IsLiteral) { sql.Append("("); } _Expression1.GetSql(db_target, ref sql); if (!_Expression1.IsLiteral) { sql.Append(")"); } sql.Append(" AND "); if (!_Expression2.IsLiteral) { sql.Append("("); } _Expression2.GetSql(db_target, ref sql); if (!_Expression2.IsLiteral) { sql.Append(")"); } }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { _expression.GetSql(db_target, ref sql); sql.Append(" IS "); if (Negation) { sql.Append("NOT "); } sql.Append("NULL"); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { if (Negation) { sql.Append("NOT "); } sql.Append("EXISTS("); _expression.GetSql(db_target, ref sql); sql.Append(")"); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { /*switch (_aggregateFunctionType) * { * case AggregateFunctionType.Sum: * sql.Append("SUM"); * break; * * case AggregateFunctionType.Avg: * sql.Append("AVG"); * break; * * case AggregateFunctionType.Max: * sql.Append("MAX"); * break; * * case AggregateFunctionType.Min: * sql.Append("MIN"); * break; * * case AggregateFunctionType.Count: * sql.Append("COUNT"); * break; * * }*/ sql.Append(_aggregateFunctionType.ToString()); sql.Append("("); if (_expression != null) { if (!_expression.IsLiteral) { sql.Append("("); } _expression.GetSql(db_target, ref sql); if (!_expression.IsLiteral) { sql.Append(")"); } } else { if (_aggregateFunctionType == AggregateFunctionType.Count) { sql.Append("*"); } } sql.Append(")"); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { sql.Append("CASE "); if (!_InputExpression.IsLiteral) { sql.Append("("); } _InputExpression.GetSql(db_target, ref sql); if (!_InputExpression.IsLiteral) { sql.Append(")"); } foreach (WhenExpression we in _WhenExpressions) { sql.Append(" WHEN "); we.BooleanExpression.GetSql(db_target, ref sql); sql.Append(" THEN "); if (!we.ResultExpression.IsLiteral) { sql.Append("("); } we.ResultExpression.GetSql(db_target, ref sql); if (!we.ResultExpression.IsLiteral) { sql.Append(")"); } } if (_ElseResultExpression != null) { sql.Append(" ELSE "); if (!_ElseResultExpression.IsLiteral) { sql.Append("("); } _ElseResultExpression.GetSql(db_target, ref sql); if (!_ElseResultExpression.IsLiteral) { sql.Append(")"); } } sql.Append(" END "); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { switch (db_target) { case DbTarget.SqlServer: sql.Append("ISNULL("); break; case DbTarget.MySql: sql.Append("IFNULL("); break; case DbTarget.SqlLite: sql.Append("IFNULL("); break; } if (!_expression.IsLiteral) { sql.Append("("); } _expression.GetSql(db_target, ref sql); if (!_expression.IsLiteral) { sql.Append(")"); } sql.Append(","); if (!_on_null.IsLiteral) { sql.Append("("); } _on_null.GetSql(db_target, ref sql); if (!_on_null.IsLiteral) { sql.Append(")"); } sql.Append(")"); }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { if (db_target == DbTarget.SqlServer) { sql.Append("DATEDIFF(day,"); if (!_StartDate.IsLiteral) { sql.Append("("); } _StartDate.GetSql(db_target, ref sql); if (!_StartDate.IsLiteral) { sql.Append(")"); } sql.Append(","); if (!_EndDate.IsLiteral) { sql.Append("("); } _EndDate.GetSql(db_target, ref sql); if (!_EndDate.IsLiteral) { sql.Append(")"); } sql.Append(")"); } else if (db_target == DbTarget.MySql) { sql.Append("DATEDIFF("); if (!_StartDate.IsLiteral) { sql.Append("("); } _StartDate.GetSql(db_target, ref sql); if (!_StartDate.IsLiteral) { sql.Append(")"); } sql.Append(","); if (!_EndDate.IsLiteral) { sql.Append("("); } _EndDate.GetSql(db_target, ref sql); if (!_EndDate.IsLiteral) { sql.Append(")"); } sql.Append(")"); } else if (db_target == DbTarget.SqlLite) { sql.Append("julianday("); if (!_EndDate.IsLiteral) { sql.Append("("); } _EndDate.GetSql(db_target, ref sql); if (!_EndDate.IsLiteral) { sql.Append(")"); } sql.Append(") - julianday("); if (!_StartDate.IsLiteral) { sql.Append("("); } _StartDate.GetSql(db_target, ref sql); if (!_StartDate.IsLiteral) { sql.Append(")"); } sql.Append(")"); } }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { if (db_target == DbTarget.SqlServer) { if (_DatePart == DatePart.Date) { sql.Append("CONVERT(VARCHAR(10),"); if (!_Date.IsLiteral) { sql.Append("('"); } _Date.GetSql(db_target, ref sql); if (!_Date.IsLiteral) { sql.Append("')"); } sql.Append(",126)"); } else if (_DatePart == DatePart.Time) { sql.Append("CONVERT(VARCHAR(8),"); if (!_Date.IsLiteral) { sql.Append("('"); } _Date.GetSql(db_target, ref sql); if (!_Date.IsLiteral) { sql.Append("')"); } sql.Append(",108)"); } else { sql.Append("DATEPART("); sql.Append((new string[] { "dd", "dw", "dy", "hh", "mi", "mm", "ss", "ww", "yyyy" })[(int)_DatePart]); sql.Append(","); if (!_Date.IsLiteral) { sql.Append("('"); } _Date.GetSql(db_target, ref sql); if (!_Date.IsLiteral) { sql.Append("')"); } sql.Append(")"); } } else if (db_target == DbTarget.MySql) { sql.Append("DATE_FORMAT('"); sql.Append((new string[] { "%d", "%w", "%j", "%H", "%i", "%m", "%S", "%U", "%Y", "%Y-%m-%d", "%H:%i:%S" })[(int)_DatePart]); sql.Append("',"); if (!_Date.IsLiteral) { sql.Append("("); } _Date.GetSql(db_target, ref sql); if (!_Date.IsLiteral) { sql.Append(")"); } sql.Append(")"); } else if (db_target == DbTarget.SqlLite) { sql.Append("DATETIME("); if (!_Date.IsLiteral) { sql.Append("('"); } _Date.GetSql(db_target, ref sql); sql.Append(",'"); if (!_Date.IsLiteral) { sql.Append("')"); } sql.Append((new string[] { "%d", "%w", "%j", "%H", "%M", "%m", "%S", "%W", "%Y", "%Y-%m-%d", "%H:%M:%S" })[(int)_DatePart]); sql.Append("')"); } }
public void GetSql(DbTarget db_target, ref StringBuilder sql) { _Expression.GetSql(db_target, ref sql); sql.Append((this.SortType == SortType.Ascending) ? " ASC" : " DESC"); }
public override void GetSql(DbTarget db_target, ref StringBuilder sql) { sql.Append("SELECT "); if (IsDistinct) { sql.Append("DISTINCT "); } if (db_target == DbTarget.SqlServer && Top > 0) { sql.Append(String.Format("TOP {0} ", _Top)); } int count = Columns.Count; if (count == 0) { sql.Append(" * "); } else { for (int x = 0; x < count; x++) { if (x > 0) { sql.Append(","); } SelectColumn col = _Columns[x]; col.GetSql(db_target, ref sql); } } if (_From != null) { _From.GetSql(db_target, ref sql); } if (_Where != null && _Where.Count > 0) { _Where.GetSql(db_target, ref sql); } if (_GroupBy != null) { count = _GroupBy.Count; if (count > 0) { sql.Append(" GROUP BY "); for (int x = 0; x < count; x++) { ISqlExpression item = _GroupBy[x]; if (!item.IsLiteral) { sql.Append("("); } item.GetSql(db_target, ref sql); if (!item.IsLiteral) { sql.Append(")"); } if (x + 1 < count) { sql.Append(", "); } else { sql.Append(" "); } } } } if (_Having != null && _Having.Count > 0) { _Having.GetSql(db_target, ref sql); } if (_OrderBy != null) { count = _OrderBy.Count; if (count > 0) { sql.Append(" ORDER BY "); for (int x = 0; x < count; x++) { IOrderByExpression item = _OrderBy[x]; item.GetSql(db_target, ref sql); if (x + 1 < count) { sql.Append(","); } } } } if ((db_target == DbTarget.SqlLite || db_target == DbTarget.MySql) && Top > 0) { sql.Append(String.Format(" LIMIT {0} ", _Top)); } }