Class SelectSql
Represents a SQL SELECT statement.
NOTE: This is not a full SQL parser.
It supports nested SELECT statements inside parentheses because the parser ignores clause keywords while inside parentheses.
public class SelectSql : BaseDef, IDef, IJsonLoadable, INotifyPropertyChanged
- Inheritance
-
SelectSql
- Implements
- Inherited Members
- Extension Methods
Constructors
SelectSql()
Constructor.
public SelectSql()
SelectSql(string)
Constructor.
public SelectSql(string StatementText)
Parameters
StatementTextstring
Fields
DefaultName
Constant
public static readonly string DefaultName
Field Value
LB
LineBreak
public static readonly string LB
Field Value
SPACE
Space
public static readonly string SPACE
Field Value
SPACES
Spaces
public static readonly string SPACES
Field Value
Properties
CompanyAware
Gets or sets a value indicating whether this object
uses the CompanyFieldName when preparing the statement as a whole
public bool CompanyAware { get; set; }
Property Value
ConnectionName
Gets or sets the database connection name
public string ConnectionName { get; set; }
Property Value
DateRange
A DateRange.
It works in conjuction with DateRangeColumn property in order to produce a fixed part in the WHERE clause of this select statement.
public DateRange DateRange { get; set; }
Property Value
DateRangeColumn
A fully qualified (i.e. TABLE_NAME.FIELD_NAME) column of type date or datetime.
It works in conjuction with DateRange property in order to produce a fixed part in the WHERE clause of this select statement.
public string DateRangeColumn { get; set; }
Property Value
From
Gets or sets the FROM clause.
[JsonIgnore]
public string From { get; set; }
Property Value
GroupBy
Gets or sets the GROUP BY clause.
[JsonIgnore]
public string GroupBy { get; set; }
Property Value
Having
Gets or sets the HAVING clause.
[JsonIgnore]
public string Having { get; set; }
Property Value
IsEmpty
Returns true if the statement is empty
[JsonIgnore]
public bool IsEmpty { get; }
Property Value
OrderBy
Gets or sets the ORDER BY clause.
[JsonIgnore]
public string OrderBy { get; set; }
Property Value
Select
Gets or sets the SELECT clause.
[JsonIgnore]
public string Select { get; set; }
Property Value
Table
The DataTable that results after the select execution
[JsonIgnore]
public MemTable Table { get; set; }
Property Value
Text
Gets the statement as a whole.
Sets clause properties by parsing the passed string value.
public string Text { get; set; }
Property Value
Where
Gets or sets the WHERE clause.
[JsonIgnore]
public string Where { get; set; }
Property Value
WhereUser
Gets or sets the WHERE clause, that part that is considered user where.
[JsonIgnore]
public string WhereUser { get; set; }
Property Value
Methods
AddTo(string, string, string)
Concatenates Clause + Delimiter + Plus
public static string AddTo(string Clause, string Delimiter, string Plus)
Parameters
Returns
AddToGroupBy(string)
Concatenates GROUP BY + , + Plus
public void AddToGroupBy(string Plus)
Parameters
Plusstring
AddToHaving(string)
Concatenates HAVING + and + Plus
public void AddToHaving(string Plus)
Parameters
Plusstring
AddToOrderBy(string)
Concatenates ORDER BY + , + Plus
public void AddToOrderBy(string Plus)
Parameters
Plusstring
AddToWhere(string)
Concatenates WHERE + and + Plus
public void AddToWhere(string Plus)
Parameters
Plusstring
AddToWhere(string, string)
Concatenates WHERE + Delimiter + Plus
public void AddToWhere(string Plus, string Delimiter)
Parameters
Assign(object)
Assigns this properties from Source.
WARNING: We need this because an automated Assign() calls the Text property which in turn calls the SelectSqlParser which has no ability to handle fields surrounded by double quotes or [] or something.
public void Assign(object Source)
Parameters
Sourceobject
CR(string)
Adds a Carriage Return (LineBreak) after S
public static string CR(string S)
Parameters
Sstring
Returns
CheckDescriptor()
Throws an exception if this descriptor is not fully defined
public override void CheckDescriptor()
Clear()
Clears the content of the clause properties
public override void Clear()
Clone()
Returns a clone of this instance.
public override BaseDef Clone()
Returns
DateRangeConstructWhereParams(DateRange, string)
Constructs a DateTime param pair (date range params) suitable for thw WHERE part in a SelectSql
public static string DateRangeConstructWhereParams(DateRange Range, string FieldName)
Parameters
Returns
DateRangeReplaceWhereParams(ref string, SqlProvider)
Replaces any DateTime param pair (date range params) found in SqlText with actual values.
public static void DateRangeReplaceWhereParams(ref string SqlText, SqlProvider Provider)
Parameters
SqlTextstringProviderSqlProvider
GetMainTableName()
Tries to get the main table name from the statement
public string GetMainTableName()
Returns
GetSqlText()
Concatenates Keyword + Clause for all clauses
public string GetSqlText()
Returns
IsMasked(string)
Returns true if Value contains any of the mask characters (%, ?, *)
public static bool IsMasked(string Value)
Parameters
Valuestring
Returns
NormalizeClause(string, string)
Concatenates Keyword + Clause
public static string NormalizeClause(string Clause, string Keyword)
Parameters
Returns
OrToWhere(string)
Concatenates WHERE + or + Plus
public void OrToWhere(string Plus)
Parameters
Plusstring
Parse(string)
Parses StatementText and assigns its clause properties.
public void Parse(string StatementText)
Parameters
StatementTextstring
ParseFromTableName(string)
Creates a select * from TableName statement and then calls Parse()
public void ParseFromTableName(string TableName)
Parameters
TableNamestring
RemoveOrderBy()
Removes the ORDER BY clause.
public void RemoveOrderBy()
ReplaceLastComma(ref string)
Replaces any trailing comma with space in S, ignoring trailing spaces.
public static void ReplaceLastComma(ref string S)
Parameters
Sstring
SelectFromToString()
Returns concatenated the SELECT and FROM clauses only.
public string SelectFromToString()