Show / Hide Table of Contents

Class SqlServerCommon

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Inheritance
object
Dialect
SqlServerCommon
Inherited Members
Dialect._tables
Dialect._tablesInJoin
Dialect._returnDBFields
Dialect._dbSchemaTable
Dialect._soSchemaTable
Dialect._returnArguments
Dialect._usedAliases
Dialect._filterCallbacks
Dialect._cmd
Dialect._stringFieldsInOrderByWithDistinct
Dialect.CheckForDuplicateRow(IDataReader)
Dialect.CheckForDistinct(PrivateSelect)
Dialect.ShouldRowBeSkipped(IDataReader)
Dialect.IsTableReferencedInSelect(SoTable)
Dialect.GetUpdatedSchemaTable(DataTable)
Dialect.GenerateCaseInsensitivity(FieldInfo, Parameter, string)
Dialect.GetOriginAsComment(SqlCommand)
Dialect.HandleDateAndTimeWrapping(string, FieldDataType)
Dialect.GetFieldDbDataType(int)
Dialect.GetIndexOfField(Argument)
Dialect.GetFieldInfoFromIndex(int)
Dialect.CheckForAlias()
Dialect.InvokeToSql(params object[])
Dialect.IsAnyArgumentString(params Argument[])
Dialect.ToSqlUpperIfNeeded(Argument)
Dialect.ToSqlFrom()
Dialect.ToSqlField(FieldInfoCollection)
Dialect.ToSqlField(ArgumentCollection)
Dialect.ToSqlField(ReturnFieldsCollection)
Dialect.ToSql(Argument)
Dialect.ToSql(OrderBy)
Dialect.ToSql(GroupBy)
Dialect.ToSql(Count)
Dialect.ToSql(CountAll)
Dialect.ToSql(IsNull)
Dialect.ToSql(IsNotNull)
Dialect.EncodedArraySearch(Argument, Argument[], Dialect.EncodedArraySearchType, Dialect.FulltextEncodedSearch)
Dialect.ToSql(NotIn)
Dialect.ToSql(Between)
Dialect.ToSql(NotBetween)
Dialect.ToSql(TableInfo)
Dialect.ToSql(Parameter)
Dialect.ToSql(NotLike)
Dialect.ToSql(HasFlag)
Dialect.ToSql(HasNoFlag)
Dialect.ToSql(And)
Dialect.ToSql(Or)
Dialect.ParseMathematicalArguments(MathematicalExpression, string)
Dialect.ToSql(Greatest)
Dialect.ToSql(Add)
Dialect.ToSql(Subtract)
Dialect.ToSql(Multiply)
Dialect.ToSql(Divide)
Dialect.ToSql(LeftOuterJoin)
Dialect.ToSql(RightOuterJoin)
Dialect.ToSql(InnerJoin)
Dialect.ParseJoinClause(JoinRestriction)
Dialect.ToSql(Distinct)
Dialect.ToSql(Alias)
Dialect.ToSql(FieldTypeConvert)
Dialect.ToSql(JsonValue)
Dialect.ToSql(FieldDataType)
Dialect.ToSql(Soundex)
Dialect.ToSql(Sum)
Dialect.ToSql(Max)
Dialect.ToSql(Min)
Dialect.ConvertToDbParameterType(object, FieldDataType)
Dialect.ConvertToDbType(object, FieldDataType)
Dialect.ConvertFromDbType(object, FieldDataType)
Dialect.TimeTUtc2DateTime(int)
Dialect.TimeTLocal2DateTime(int)
Dialect.DateTime2TimeTUtc(DateTime)
Dialect.DateTime2TimeTLocal(DateTime)
Dialect.SelectSql(PrivateSelect)
Dialect.InsertSql(PrivateSave)
Dialect.UpdateSql(PrivateSave)
Dialect.DeleteSql(PrivateSave)
Dialect.UnionSql(TableExpression)
Dialect.PreParseUnion(TableExpression)
Dialect.DifferenceSql(TableExpression)
Dialect.GenerateSql(SqlCommand)
Dialect.FieldIsClob(Argument)
Dialect.FieldIsString(Argument)
Dialect.DataReaderGetName(SoDataReader, IDataReader, int)
Dialect.DataReaderGetDataTypeName(SoDataReader, IDataReader, int)
Dialect.DataReaderGetFieldType(SoDataReader, IDataReader, int)
Dialect.DataReaderGetValue(SoDataReader, IDataReader, int)
Dialect.DataReaderGetOrdinal(SoDataReader, IDataReader, string)
Dialect.DataReaderGetItem(SoDataReader, IDataReader, int)
Dialect.DataReaderGetNullValue(SoDataReader, int)
Dialect.DataReaderGetBoolean(SoDataReader, IDataReader, int)
Dialect.DataReaderGetByte(SoDataReader, IDataReader, int)
Dialect.DataReaderGetBytes(SoDataReader, IDataReader, int, long, byte[], int, int)
Dialect.DataReaderGetChar(SoDataReader, IDataReader, int)
Dialect.DataReaderGetChars(SoDataReader, IDataReader, int, long, char[], int, int)
Dialect.DataReaderGetGuid(SoDataReader, IDataReader, int)
Dialect.DataReaderGetInt16(SoDataReader, IDataReader, int)
Dialect.DataReaderGetInt32(SoDataReader, IDataReader, int)
Dialect.DataReaderGetInt32Array(SoDataReader, IDataReader, int)
Dialect.DataReaderGetInt64(SoDataReader, IDataReader, int)
Dialect.DataReaderGetFloat(SoDataReader, IDataReader, int)
Dialect.DataReaderGetDouble(SoDataReader, IDataReader, int)
Dialect.DataReaderGetString(SoDataReader, IDataReader, int)
Dialect.DataReaderGetDecimal(SoDataReader, IDataReader, int)
Dialect.DataReaderGetDateTime(SoDataReader, IDataReader, int)
Dialect.DataReaderGetData(SoDataReader, IDataReader, int)
Dialect.DataReaderIsDBNullAsync(SoDataReader, DbDataReader, int, CancellationToken)
Dialect.IntToSingleWord(int)
Dialect.IntArrayToWordString(params int[])
Dialect.IntFromSingleWord(string)
Dialect.IntArrayFromWordString(string)
Dialect.GetIsolationLevel(IsolationLevel)
Dialect.DataReaderIsDBNull(SoDataReader, DbDataReader, int)
Dialect.CaseSensitiveDatabase
Dialect.BlockUpperInOrderBy
Dialect.MaxInSize
Dialect.Tables
Dialect.ReturnDBFields
Dialect.HasAliasOnSelect
Dialect.CurrentSqlType
Dialect.CurrentOuterSqlType
Dialect.ReturnFieldsIndexer
Dialect.VarcharType
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Data.Dialect
Assembly: SoDataBase.BusinessLogic.dll
Syntax
public class SqlServerCommon : Dialect

Properties

DefaultConnectionString

Default connection string for MS SQL Server

Declaration
public override string DefaultConnectionString { get; }
Property Value
Type Description
string
Overrides
Dialect.DefaultConnectionString

HasAliasOnDelete

Overridden method. Used to check if alias is used with fields and tables in the SQL DELETE-command.

Declaration
protected override bool HasAliasOnDelete { get; }
Property Value
Type Description
bool
Overrides
Dialect.HasAliasOnDelete
Remarks

Default value is false.

HasAliasOnInsert

Overridden method. Used to check if alias is used with fields and tables in the SQL INSERT-command.

Declaration
protected override bool HasAliasOnInsert { get; }
Property Value
Type Description
bool
Overrides
Dialect.HasAliasOnInsert
Remarks

Default value is false.

HasAliasOnUpdate

Overridden method. Used to check if alias is used with fields and tables in the SQL UPDATE-command.

Declaration
protected override bool HasAliasOnUpdate { get; }
Property Value
Type Description
bool
Overrides
Dialect.HasAliasOnUpdate
Remarks

Default value is false.

Methods

ComposeSelect(string, string, string, string, StringBuilder, PrivateSelect)

Compose the final SELECT from its constituent parts. For SQL Server, that means appending OPTION(RECOMPILE) if forced execution plan recompilation has been requested.

Declaration
protected override string ComposeSelect(string select, string fields, string from, string join, StringBuilder sql, PrivateSelect originalCommand)
Parameters
Type Name Description
string select
string fields
string from
string join
StringBuilder sql
PrivateSelect originalCommand
Returns
Type Description
string
Overrides
Dialect.ComposeSelect(string, string, string, string, StringBuilder, PrivateSelect)

ConvertToDbString(string)

Convert a string to a type that can be used in an SQL command when communication to the database; using UNICODE data

Declaration
public override string ConvertToDbString(string value)
Parameters
Type Name Description
string value

The string value that is to be converted.

Returns
Type Description
string

A string that can be used in an SQL command.

Overrides
Dialect.ConvertToDbString(string)
Remarks

Appropriate ' characters are put in the front of and in the end of the string when processed by this method.

DateToVarchar(string)

Subclass override: How to convert a datetime to a varchar (or whatever it's called), in the database, taking only the DATE part

Declaration
protected override string DateToVarchar(string innerValue)
Parameters
Type Name Description
string innerValue

The actual reference to the datetime to work on; this is an opaque parameter that the method should NOT attempt to understand, just assume it will be a valid datetime value or parameter at query-execution time

Returns
Type Description
string
Overrides
Dialect.DateToVarchar(string)

GetDefaultTransaction(SoConnection, SqlCommand)

Create and return a default transaction for SELECT queries that have no current transaction

Declaration
protected override SoTransaction GetDefaultTransaction(SoConnection connection, SqlCommand sqlCommand)
Parameters
Type Name Description
SoConnection connection

Connection the command will be executed on

SqlCommand sqlCommand

Command to be executed

Returns
Type Description
SoTransaction

Newly created default transaction for SELECT-type queries, or null

Overrides
Dialect.GetDefaultTransaction(SoConnection, SqlCommand)
Remarks

On SQL Server, large SELECT's are problematic due to automatic lock escalation. When 5000 row locks have been accumulated, the server tends to escalate this to a table lock, thereby blocking concurrent INSERTs and UPDATEs, even if they are happening far away from the select.

A fairly clean way to avoid this is to have IsolationLevel.ReadUncommited on those selects - this causes them to create no locks and honour no locks.

GetOrderbyCollationHint()

Translate the current thread culture into an Sql Server collation hint

Declaration
protected override string GetOrderbyCollationHint()
Returns
Type Description
string
Overrides
Dialect.GetOrderbyCollationHint()

TimeToVarchar(string)

Subclass override: How to convert a datetime to a varchar (or whatever it's called), in the database, taking only the TIME part

Declaration
protected override string TimeToVarchar(string innerValue)
Parameters
Type Name Description
string innerValue

The actual reference to the datetime to work on; this is an opaque parameter that the method should NOT attempt to understand, just assume it will be a valid datetime value or parameter at query-execution time

Returns
Type Description
string
Overrides
Dialect.TimeToVarchar(string)

ToSql(Day)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected override string ToSql(Day arg)
Parameters
Type Name Description
Day arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Day)

ToSql(Equal)

The text-field in the database on SQL Server is of type text (like a CLOB). It is not possible to use the EQUAL operator on this type. So we need to convert the field before running the EQUAL operator on the value given.

Declaration
protected override string ToSql(Equal arg)
Parameters
Type Name Description
Equal arg

The EQUAL argument.

Returns
Type Description
string

A parsed and build sql string according with the necessary alterations if dealing with a clob-field.

Overrides
Dialect.ToSql(Equal)

ToSql(FieldInfo)

Will return the Field's name together with the generated table-alias.

T1."contact"
Declaration
protected override string ToSql(FieldInfo arg)
Parameters
Type Name Description
FieldInfo arg
Returns
Type Description
string
Overrides
Dialect.ToSql(FieldInfo)
Remarks

Same as base implementation, but removed .ToUpper(): Area.MaxDataAge in upper contains AA which is understood differently from aA. (AA becomes Å, while Aa stays Aa) Hence; ToUpper can not be used on MS SQL Server. Does anyone think that this is completely pathological behaviour on the part of SQL Server???

ToSql(GreaterThan)

The text-field in the database on SQL Server is of type text (like a CLOB). It is not possible to use the GreaterThan operator on this type. So we need to convert the field before running the GreaterThan operator on the value given.

Declaration
protected override string ToSql(GreaterThan arg)
Parameters
Type Name Description
GreaterThan arg

The EQUAL argument.

Returns
Type Description
string

A parsed and build sql string according with the necessary alterations if dealing with a clob-field.

Overrides
Dialect.ToSql(GreaterThan)

ToSql(GreaterThanOrEqual)

The text-field in the database on SQL Server is of type text (like a CLOB). It is not possible to use the GreaterThanOrEqual operator on this type. So we need to convert the field before running the GreaterThanOrEqual operator on the value given.

Declaration
protected override string ToSql(GreaterThanOrEqual arg)
Parameters
Type Name Description
GreaterThanOrEqual arg

The UNEQUAL argument.

Returns
Type Description
string

A parsed and build sql string according with the necessary alterations if dealing with a clob-field.

Overrides
Dialect.ToSql(GreaterThanOrEqual)

ToSql(HasAll)

Process the special HasAny, which doesn't correspond to SQL. However it does work (only!) with our special simulated int[] datatype, encoded as words in a text field

Declaration
protected override string ToSql(HasAll arg)
Parameters
Type Name Description
HasAll arg
Returns
Type Description
string
Overrides
Dialect.ToSql(HasAll)

ToSql(HasAny)

Process the special HasAny, which doesn't correspond to SQL. However it does work (only!) with our special simulated int[] datatype, encoded as words in a text field

Declaration
protected override string ToSql(HasAny arg)
Parameters
Type Name Description
HasAny arg
Returns
Type Description
string
Overrides
Dialect.ToSql(HasAny)

ToSql(Hour)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected override string ToSql(Hour arg)
Parameters
Type Name Description
Hour arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Hour)

ToSql(In)

The not in-operator (NOT IN) is used when you want to get data that corresponds with the restriction-clause but does not contain the values described in the not in-clause.

SELECT T0.associate_id
FROM associate TO
WHERE associate_id BETWEEN 10 AND 100
AND T0.associate_id NOT IN (20, 30, 40, 50, 60, 70, 80, 90);

This example will give you all the associate_id's between 10 and 100 but the ones described in the not in-clause.

Declaration
protected override string ToSql(In arg)
Parameters
Type Name Description
In arg
Returns
Type Description
string
Overrides
Dialect.ToSql(In)
Remarks

SQL parameters will not be used for huge IN queries.

ToSql(LessThan)

The text-field in the database on SQL Server is of type text (like a CLOB). It is not possible to use the LessThan operator on this type. So we need to convert the field before running the LessThan operator on the value given.

Declaration
protected override string ToSql(LessThan arg)
Parameters
Type Name Description
LessThan arg

The EQUAL argument.

Returns
Type Description
string

A parsed and build sql string according with the necessary alterations if dealing with a clob-field.

Overrides
Dialect.ToSql(LessThan)

ToSql(LessThanOrEqual)

The text-field in the database on SQL Server is of type text (like a CLOB). It is not possible to use the LessThanOrEqual operator on this type. So we need to convert the field before running the LessThanOrEqual operator on the value given.

Declaration
protected override string ToSql(LessThanOrEqual arg)
Parameters
Type Name Description
LessThanOrEqual arg

The UNEQUAL argument.

Returns
Type Description
string

A parsed and build sql string according with the necessary alterations if dealing with a clob-field.

Overrides
Dialect.ToSql(LessThanOrEqual)

ToSql(Like)

Override: If we have a LIKE operator, used on a field that has fulltext indexing, and fulltext indexing preference is enabled on this database, THEN use the custom syntax (in its simplest form) for that. Handle multi-word searches as "exact sentence" Reference: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/fulltxt9/html/7624ba76-594b-4be5-ac10-c3ac4a3529bd.htm or http://msdn.microsoft.com/en-us/library/ms187787.aspx

Declaration
protected override string ToSql(Like arg)
Parameters
Type Name Description
Like arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Like)

ToSql(Lower)

ToSql Lower

Declaration
protected override string ToSql(Lower arg)
Parameters
Type Name Description
Lower arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Lower)

ToSql(Minute)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected override string ToSql(Minute arg)
Parameters
Type Name Description
Minute arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Minute)

ToSql(MissingAll)

Process the special HasAny, which doesn't correspond to SQL. However it does work (only!) with our special simulated int[] datatype, encoded as words in a text field

Declaration
protected override string ToSql(MissingAll arg)
Parameters
Type Name Description
MissingAll arg
Returns
Type Description
string
Overrides
Dialect.ToSql(MissingAll)

ToSql(MissingAny)

Process the special HasAny, which doesn't correspond to SQL. However it does work (only!) with our special simulated int[] datatype, encoded as words in a text field

Declaration
protected override string ToSql(MissingAny arg)
Parameters
Type Name Description
MissingAny arg
Returns
Type Description
string
Overrides
Dialect.ToSql(MissingAny)

ToSql(Month)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected override string ToSql(Month arg)
Parameters
Type Name Description
Month arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Month)

ToSql(Second)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected override string ToSql(Second arg)
Parameters
Type Name Description
Second arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Second)

ToSql(Trim)

ToSql( Trim arg ) will return the given argument enclosed by the SQL TRIM function.

Declaration
protected override string ToSql(Trim arg)
Parameters
Type Name Description
Trim arg

The argument to wrap TRIM around.

Returns
Type Description
string

The parsed Trim-string

Overrides
Dialect.ToSql(Trim)

ToSql(UnEqual)

The text-field in the database on SQL Server is of type text (like a CLOB). It is not possible to use the UNEQUAL operator on this type. So we need to convert the field before running the UNEQUAL operator on the value given.

Declaration
protected override string ToSql(UnEqual arg)
Parameters
Type Name Description
UnEqual arg

The UNEQUAL argument.

Returns
Type Description
string

A parsed and build sql string according with the necessary alterations if dealing with a clob-field.

Overrides
Dialect.ToSql(UnEqual)

ToSql(Upper)

ToSql Upper

Declaration
protected override string ToSql(Upper arg)
Parameters
Type Name Description
Upper arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Upper)

ToSql(Year)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected override string ToSql(Year arg)
Parameters
Type Name Description
Year arg
Returns
Type Description
string
Overrides
Dialect.ToSql(Year)

ToSql(WaitFor)

This class contains all common code for the MS SQL Server family. Specific "version-sql" will be treated in the versions different subclasses.

Declaration
protected string ToSql(WaitFor arg)
Parameters
Type Name Description
WaitFor arg
Returns
Type Description
string

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top