Table of Contents

Class SelectSql

Namespace
Tripous.Data
Assembly
Tripous.Data.dll

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

StatementText string

Fields

DefaultName

Constant

public static readonly string DefaultName

Field Value

string

LB

LineBreak

public static readonly string LB

Field Value

string

SPACE

Space

public static readonly string SPACE

Field Value

string

SPACES

Spaces

public static readonly string SPACES

Field Value

string

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

bool

ConnectionName

Gets or sets the database connection name

public string ConnectionName { get; set; }

Property Value

string

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

DateRange

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

string

From

Gets or sets the FROM clause.

[JsonIgnore]
public string From { get; set; }

Property Value

string

GroupBy

Gets or sets the GROUP BY clause.

[JsonIgnore]
public string GroupBy { get; set; }

Property Value

string

Having

Gets or sets the HAVING clause.

[JsonIgnore]
public string Having { get; set; }

Property Value

string

IsEmpty

Returns true if the statement is empty

[JsonIgnore]
public bool IsEmpty { get; }

Property Value

bool

OrderBy

Gets or sets the ORDER BY clause.

[JsonIgnore]
public string OrderBy { get; set; }

Property Value

string

Select

Gets or sets the SELECT clause.

[JsonIgnore]
public string Select { get; set; }

Property Value

string

Table

The DataTable that results after the select execution

[JsonIgnore]
public MemTable Table { get; set; }

Property Value

MemTable

Text

Gets the statement as a whole.

Sets clause properties by parsing the passed string value.

public string Text { get; set; }

Property Value

string

Where

Gets or sets the WHERE clause.

[JsonIgnore]
public string Where { get; set; }

Property Value

string

WhereUser

Gets or sets the WHERE clause, that part that is considered user where.

[JsonIgnore]
public string WhereUser { get; set; }

Property Value

string

Methods

AddTo(string, string, string)

Concatenates Clause + Delimiter + Plus

public static string AddTo(string Clause, string Delimiter, string Plus)

Parameters

Clause string
Delimiter string
Plus string

Returns

string

AddToGroupBy(string)

Concatenates GROUP BY + , + Plus

public void AddToGroupBy(string Plus)

Parameters

Plus string

AddToHaving(string)

Concatenates HAVING + and + Plus

public void AddToHaving(string Plus)

Parameters

Plus string

AddToOrderBy(string)

Concatenates ORDER BY + , + Plus

public void AddToOrderBy(string Plus)

Parameters

Plus string

AddToWhere(string)

Concatenates WHERE + and + Plus

public void AddToWhere(string Plus)

Parameters

Plus string

AddToWhere(string, string)

Concatenates WHERE + Delimiter + Plus

public void AddToWhere(string Plus, string Delimiter)

Parameters

Plus string
Delimiter string

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

Source object

CR(string)

Adds a Carriage Return (LineBreak) after S

public static string CR(string S)

Parameters

S string

Returns

string

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

BaseDef

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

Range DateRange
FieldName string

Returns

string

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

SqlText string
Provider SqlProvider

GetMainTableName()

Tries to get the main table name from the statement

public string GetMainTableName()

Returns

string

GetSqlText()

Concatenates Keyword + Clause for all clauses

public string GetSqlText()

Returns

string

IsMasked(string)

Returns true if Value contains any of the mask characters (%, ?, *)

public static bool IsMasked(string Value)

Parameters

Value string

Returns

bool

NormalizeClause(string, string)

Concatenates Keyword + Clause

public static string NormalizeClause(string Clause, string Keyword)

Parameters

Clause string
Keyword string

Returns

string

OrToWhere(string)

Concatenates WHERE + or + Plus

public void OrToWhere(string Plus)

Parameters

Plus string

Parse(string)

Parses StatementText and assigns its clause properties.

public void Parse(string StatementText)

Parameters

StatementText string

ParseFromTableName(string)

Creates a select * from TableName statement and then calls Parse()

public void ParseFromTableName(string TableName)

Parameters

TableName string

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

S string

SelectFromToString()

Returns concatenated the SELECT and FROM clauses only.

public string SelectFromToString()

Returns

string