Class AbstractTableManager
- Namespace
- CMS.DataEngine
- Assembly
- CMS.DataEngine.dll
Ensures management of database table and table column.
public abstract class AbstractTableManager : ITableManager
- Inheritance
-
objectAbstractTableManager
- Implements
- Derived
- Extension Methods
Constructors
AbstractTableManager()
protected AbstractTableManager()
Fields
mDatabaseCulture
Database culture setting from the web.config.
protected string mDatabaseCulture
Field Value
- string
Properties
ConnectionString
Connection string to use for table management
public string ConnectionString { get; set; }
Property Value
- string
DatabaseCulture
Database culture setting from the web.config.
public virtual string DatabaseCulture { get; }
Property Value
- string
DatabaseName
Database name.
public virtual string DatabaseName { get; }
Property Value
- string
DatabaseServerName
Name of database server.
public virtual string DatabaseServerName { get; }
Property Value
- string
DatabaseServerVersion
Version of database server.
public virtual string DatabaseServerVersion { get; }
Property Value
- string
DatabaseSize
Database size(including log size) in MB.
public virtual string DatabaseSize { get; }
Property Value
- string
DatabaseVersion
Database version
public virtual string DatabaseVersion { get; }
Property Value
- string
Methods
AddTableColumn(string, string, string, bool, string, bool)
Add column to specified table.
public virtual void AddTableColumn(string tableName, string columnName, string columnType, bool allowNull, string defaultValue, bool forceDefaultValue = true)
Parameters
tableNamestringTable name
columnNamestringName of a new column
columnTypestringType of a new column
allowNullboolAllow NULL values in new column or not
defaultValuestringDefault value of the column in system (en) culture. Null if no default value is set
forceDefaultValueboolIndicates if column default value should be set if column doesn't allow NULL values
Exceptions
- ArgumentNullException
tableName,columnNameorcolumnTypeis null.
AlterTableColumn(string, string, string, string, bool, string)
Alter table column with default value.
public virtual void AlterTableColumn(string tableName, string columnName, string newColumnName, string newColumnType, bool newColumnAllowNull, string newColumnDefaultValue)
Parameters
tableNamestringTable name
columnNamestringColumn name
newColumnNamestringNew column name, null if no new column is created
newColumnTypestringNew column type, null if no new column is created
newColumnAllowNullboolAllow NULL values in new column or not
newColumnDefaultValuestringColumn default value in system (en) culture
Exceptions
- ArgumentNullException
tableName,columnNameornewColumnTypeis null.
AlterView(string, string, bool, string)
Alters specified view in database
public virtual void AlterView(string viewName, string selectExpression, bool indexed, string schema)
Parameters
viewNamestringView name to alter
selectExpressionstringSelect expression for the view
indexedboolIf true, the view is indexed (schema bound)
schemastringDatabase schema
ChangeDBObjectOwner(string, string)
Changes database object owner.
[Obsolete("Method was not intended for public use and will be removed.")]
public virtual void ChangeDBObjectOwner(string dbObject, string newOwner)
Parameters
dbObjectstringDatabase object name
newOwnerstringNew owner name
ColumnExistsInView(string, string)
Checks if column name is unique in given view.
public virtual bool ColumnExistsInView(string viewName, string columnName)
Parameters
viewNamestringName of the view
columnNamestringName of the column to be checked
Returns
- bool
CreateColumnIndexes(string, string, DataSet)
Creates the table indexes.
public virtual void CreateColumnIndexes(string tableName, string columnName, DataSet ds)
Parameters
tableNamestringTable name
columnNamestringColumn name
dsDataSetDataSet with the indexes information
CreateForeignKey(string, string, string, string, string)
Creates a foreign key between the source table and the referenced table if a foreign key with the same name doesn't already exist.
public virtual void CreateForeignKey(string foreignKeyName, string sourceTableName, string sourceColumnName, string referencedTableName, string referencedColumnName)
Parameters
foreignKeyNamestringForeign key name.
sourceTableNamestringSource table.
sourceColumnNamestringSource column name.
referencedTableNamestringReferenced table name.
referencedColumnNamestring
CreateIndex(string, string, bool, IList<(string columnName, bool isAscendingOrder)>)
Creates a non-clustered index for a column(s) if an index with the same name doesn't already exist.
public virtual void CreateIndex(string indexName, string tableName, bool isUnique, IList<(string columnName, bool isAscendingOrder)> columns)
Parameters
indexNamestringIndex name.
tableNamestringTable name.
isUniqueboolIndicates whether index should be unique.
columnsIList<(string columnName, bool isAscendingOrder)>Collection of index columns with order specification.
CreateTable(string, string)
Creates specified table in database.
public virtual void CreateTable(string tableName, string primaryKeyName)
Parameters
tableNamestringTable name to create
primaryKeyNamestringPrimary key of table to create
CreateTable(string, string, bool)
Creates specified table in database.
public virtual void CreateTable(string tableName, string primaryKeyName, bool setIdentity)
Parameters
tableNamestringTable name to create
primaryKeyNamestringPrimary key of table to create
setIdentityboolIf true, sets identity on primary key column
CreateTransactionScope()
Returns a transaction scope that can be used to maintain database consistency.
protected virtual ITransactionScope CreateTransactionScope()
Returns
CreateView(string, string, bool, string)
Creates specified view in database
public virtual void CreateView(string viewName, string selectExpression, bool indexed, string schema)
Parameters
viewNamestringView name to create
selectExpressionstringSelect expression for the view
indexedboolIf true, the view is indexed (schema bound)
schemastringDatabase schema
DropColumnIndexes(string, string)
Drops the column indexes, returns the DataSet of indexes.
public virtual DataSet DropColumnIndexes(string tableName, string columnName)
Parameters
tableNamestringTable name
columnNamestringColumn name
Returns
- DataSet
DropDefaultConstraint(string, string)
Drops the default constraint.
public virtual void DropDefaultConstraint(string tableName, string columnName)
Parameters
tableNamestringTable name
columnNamestringColumn name
DropTable(string)
Drop specified table from database.
public virtual void DropTable(string tableName)
Parameters
tableNamestringTable name to drop
DropTableColumn(string, string)
Remove column from specified table.
public virtual void DropTableColumn(string tableName, string columnName)
Parameters
tableNamestringTable name
columnNamestringName of column to remove
DropView(string)
Drop specified view from database. Returns the schema of the dropped view.
public virtual string DropView(string viewName)
Parameters
viewNamestringView name to drop
Returns
- string
EnsureDefaultValue(bool, string, string)
Add apostrophes around the column default value string according to column type.
protected virtual string EnsureDefaultValue(bool allowNull, string sqlType, string defValue)
Parameters
allowNullboolIndicates whether NULL values are allowed
sqlTypestringSQL type of the table column
defValuestringDefault to add apostrophes to
Returns
- string
ExecuteQuery(string, QueryDataParameters, QueryTypeEnum)
Executes query and returns the results in a DataSet.
public virtual DataSet ExecuteQuery(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType)
Parameters
queryTextstringQuery text
queryParamsQueryDataParametersQuery parameters
queryTypeQueryTypeEnumQuery type
Returns
- DataSet
ExecuteScalar(string, QueryDataParameters, QueryTypeEnum)
Executes query and returns the value from the first column of the first row in the returned result set.
public virtual object ExecuteScalar(string queryText, QueryDataParameters queryParams, QueryTypeEnum queryType)
Parameters
queryTextstringQuery text
queryParamsQueryDataParametersQuery parameters
queryTypeQueryTypeEnumQuery type
Returns
- object
GetColumnIndexes(string, string)
Returns the DataSet of column indexes.
public virtual DataSet GetColumnIndexes(string tableName, string columnName)
Parameters
tableNamestringTable name
columnNamestringColumn name
Returns
- DataSet
GetColumnInformation(string, string)
Returns DataSet with specified table column information retrieved from database information schema. Returns columns ColumnName, DataType, DataSize, DataPrecision, Nullable, DefaultValue.
public virtual DataSet GetColumnInformation(string tableName, string columnName)
Parameters
tableNamestringDatabase table name
columnNamestringDatabase table column name
Returns
- DataSet
Remarks
If columnName is not specified data for all table columns are returned.
GetConnection()
Gets the connection for the table management
protected virtual IDataConnection GetConnection()
Returns
GetConstraintName(string, string)
Returns constraint's name truncated to 128 chars (128 chars is limit of database column name).
[Obsolete("Method is obsolete and will be removed in the next version.")]
public static string GetConstraintName(string tableName, string columnName)
Parameters
tableNamestringTable name
columnNamestringColumn name
Returns
- string
GetDatabaseInfo()
Gets size related information about the database.
protected virtual DataSet GetDatabaseInfo()
Returns
- DataSet
DataSet with 2 tables containing related data
GetDatabaseSize(string)
Gets database size (including log size) or N/A string if the size cannot be retrieved
protected virtual string GetDatabaseSize(string databaseCulture)
Parameters
databaseCulturestring
Returns
- string
GetDatabaseVersion()
Gets the database version
protected virtual string GetDatabaseVersion()
Returns
- string
GetPKConstraintName(string)
Returns the name of the primary key constraint.
public virtual string GetPKConstraintName(string tableName)
Parameters
tableNamestringName of the table
Returns
- string
GetPrimaryKeyColumns(string)
Returns list of column names which represent primary keys of the specified database table. Returns empty list if primary keys are not found.
public virtual List<string> GetPrimaryKeyColumns(string tableName)
Parameters
tableNamestringDatabase table name
Returns
- List<string>
GetTableDependencies(string)
Gets list of object names which have foreign key constraint dependency.
[Obsolete("Method is deprecated and will be removed in the next version.")]
public virtual List<string> GetTableDependencies(string tableName)
Parameters
tableNamestring
Returns
- List<string>
GetTablePKName(string)
Returns name of the primary key. If more columns in PK, names are separated by semicolon ";".
public virtual string GetTablePKName(string tableName)
Parameters
tableNamestringName of the table to get PK column(s) from.
Returns
- string
GetValueString(object)
Returns the value string using the database culture. Does not include apostrophes for types that need them
public virtual string GetValueString(object value)
Parameters
valueobjectValue to convert
Returns
- string
GetXmlSchema(string)
Returns XML schema for specified table.
public virtual string GetXmlSchema(string tableName)
Parameters
tableNamestringName of a table to get xml schema for
Returns
- string
RecreatePKConstraint(string, string[])
Drops the current primary key constraint and creates new from given columns.
public virtual void RecreatePKConstraint(string tableName, string[] primaryKeyColumns)
Parameters
tableNamestringName of the table
primaryKeyColumnsstring[]List of columns which should be part of primary key
RefreshView(string)
Refreshes specified view in database.
public virtual void RefreshView(string viewName)
Parameters
viewNamestringView name to refresh
RenameColumn(string, string, string)
Changes name of the column.
protected virtual bool RenameColumn(string tableName, string columnName, string newColumnName)
Parameters
tableNamestringName of the table
columnNamestringCurrent name of the column
newColumnNamestringNew name of the column
Returns
- bool
RenameTable(string, string)
Changes name of the table with original name according to the new name.
public virtual void RenameTable(string oldTableName, string newTableName)
Parameters
oldTableNamestringName of the table to rename
newTableNamestringNew name of the table
TableExists(string)
Determines whether specified DB table exists or not.
public virtual bool TableExists(string tableName)
Parameters
tableNamestringTable name to check
Returns
- bool
ViewExists(string)
Determines whether specified DB view exists or not.
public virtual bool ViewExists(string viewName)
Parameters
viewNamestringView name to check
Returns
- bool
ViewExists(string, out string)
Determines whether specified DB view exists or not.
public virtual bool ViewExists(string viewName, out string schema)
Parameters
viewNamestringView name to check
schemastringReturns the view schema
Returns
- bool