Class SQLExtensions
Inheritance
Inherited Members
Namespace: LemonEdge.Utils.Database
Assembly: Utils.dll
Syntax
public static class SQLExtensions
Methods
GetEquivelantDotNetType(SQLType, Boolean)
Returns the equivelant .Net Core type for the specified sql type
Declaration
public static Type GetEquivelantDotNetType(this SQLType type, bool nullable)
Parameters
| Type | Name | Description |
|---|---|---|
| SQLType | type | The sql data type |
| System.Boolean | nullable | Whether or not the sql type is nullable |
Returns
| Type | Description |
|---|---|
| System.Type | The equivelant .Net Core type for the specified sql type |
GetFunction(AggregateFunction)
Returns the sql equivelant of the specified AggregateFunction
Declaration
public static string GetFunction(this AggregateFunction aggFunc)
Parameters
| Type | Name | Description |
|---|---|---|
| AggregateFunction | aggFunc | The aggregatefunction to return the equivelant sql for |
Returns
| Type | Description |
|---|---|
| System.String | The sql equivelant of the specified AggregateFunction |
GetJoinTypeSQL(RelationshipJoinType, Boolean)
Returns the sql equivelant for the specified join
Declaration
public static string GetJoinTypeSQL(this RelationshipJoinType join, bool useCrossApply)
Parameters
| Type | Name | Description |
|---|---|---|
| RelationshipJoinType | join | The join to use |
| System.Boolean | useCrossApply | Indicates if the join should be using a cross apply or not |
Returns
| Type | Description |
|---|---|
| System.String | The sql for joining using this type of |
GetNextSortDirection(Order)
Returns the next sort direction to use when cycling through sorting states
Declaration
public static Order GetNextSortDirection(this Order currentSortDirection)
Parameters
| Type | Name | Description |
|---|---|---|
| Order | currentSortDirection | The current sort direction |
Returns
| Type | Description |
|---|---|
| Order | Returns the next sort direction according to the following cycle: Ascending->Descending->None |
GetOrder(Order)
Returns the sql equiveleant of the specified order
Declaration
public static string GetOrder(this Order order)
Parameters
| Type | Name | Description |
|---|---|---|
| Order | order | The order either ascending or descending |
Returns
| Type | Description |
|---|---|
| System.String | The sql equiveleant of the specified order |
SQLNameWithoutDBOPrefix(String)
Returns the specified name without the xxx. prefix
Declaration
public static string SQLNameWithoutDBOPrefix(this string s)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string that optionally contains a xxx. prefix |
Returns
| Type | Description |
|---|---|
| System.String | The specified name without the xxx. prefix |
SQLVariableToSafeName(String, Boolean, Boolean)
Taks a string and returns it as a sql variable safe name by removing all non alphanumerical characters (excluding the underscore _) with
Declaration
public static string SQLVariableToSafeName(this string s, bool addSquareBrackets = false, bool allowSpaces = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to return as a sql variable safe name |
| System.Boolean | addSquareBrackets | Indicates if the system should add square brackets around the resulting string |
| System.Boolean | allowSpaces | Indicates if spaces should be allowed in the variable name |
Returns
| Type | Description |
|---|---|
| System.String |
SQLVariableToSafeName(String, Boolean, IEnumerable<Char>)
Taks a string and returns it as a sql variable safe name by removing all non alphanumerical characters with
Declaration
public static string SQLVariableToSafeName(this string s, bool addSquareBrackets = false, IEnumerable<char> validNonAlphaNumericalChars = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | s | The string to return as a sql variable safe name |
| System.Boolean | addSquareBrackets | Indicates if the system should add square brackets around the resulting string |
| System.Collections.Generic.IEnumerable<System.Char> | validNonAlphaNumericalChars | Contains a list of non alphanumerical characters that are allowed to be included such as the underscore _ |
Returns
| Type | Description |
|---|---|
| System.String |
test()
Declaration
public static void test()
ToSqlDBType(SQLType)
Converts the LemonEdge SQLType to the equivelant System.Data.SqlDbType
Declaration
public static SqlDbType ToSqlDBType(this SQLType val)
Parameters
| Type | Name | Description |
|---|---|---|
| SQLType | val | The value to convert |
Returns
| Type | Description |
|---|---|
| System.Data.SqlDbType | An equivelant System.Data.SqlDbType |
ToSQLQuotedString(String)
Returns the supplied string enclosed in single quotes and with any embedded quotes doubled up, as required for including a string literal in a SQL statement
Declaration
public static string ToSQLQuotedString(this string sql)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | sql | The sql to be enclosed in quotes, and have single quotes replaced with two single quotes to make sure strings can't be escaped. |
Returns
| Type | Description |
|---|---|
| System.String | The supplied string enclosed in single quotes and with any embedded quotes doubled up, as required for including a string literal in a SQL statement |
ToSQLStatement(SQLOperator, String, String)
Returns the sql equivelant of the specified comparrison
Declaration
public static string ToSQLStatement(this SQLOperator op, string leftSideSQL, string rightSideSQL)
Parameters
| Type | Name | Description |
|---|---|---|
| SQLOperator | op | The operation to use to compare the left and right side |
| System.String | leftSideSQL | The left side of the comparrison |
| System.String | rightSideSQL | The right side of the comparrison |
Returns
| Type | Description |
|---|---|
| System.String | The sql equivelant of the specified comparrison |
Remarks
For example:
var left = 5;
var right = 7;
var op = SQLOperator.NotEquals;
var statement = op.ToSQLStatement(left.ToString(), right.ToString());
Would result in statement holding 5 <> 7
ToSQLValue(Boolean)
Returns 1 or 0 as a string depending on the boolean value
Declaration
public static string ToSQLValue(this bool b)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | b |
Returns
| Type | Description |
|---|---|
| System.String | 1 if |
ToSQLValue(Byte[])
Returns the specified byte array formatted for sql such as 0x....
Declaration
public static string ToSQLValue(this byte[] bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | bytes | The byte array to format for sql |
Returns
| Type | Description |
|---|---|
| System.String | The specified byte array formatted for sql such as 0x.... |
ToSQLValue(Nullable<Boolean>)
Returns 1 or 0 as a string depending on the boolean value
Declaration
public static string ToSQLValue(this bool? b)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Nullable<System.Boolean> | b |
Returns
| Type | Description |
|---|---|
| System.String | 1 if |
ToSQLValue(Object, Boolean)
Converts the specified value into a equivelant string value for sql input
Declaration
public static string ToSQLValue(this object value, bool addQuotes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | value | The value to return formatted for sql |
| System.Boolean | addQuotes | Indicates if quotes should be added around the value. Not needed for types that require it such as a text or datetime, the function will automatically add quotes for those |
Returns
| Type | Description |
|---|---|
| System.String | The specified value into a equivelant string value for sql input |