// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceModel; using System.Data; using System.Data.Common; namespace Spludlow.Data { [ServiceContract] public interface IDAL { [OperationContract] void Initialize(string connectionString); // Used when "remoting the DAL" to call the constructor // Does not allow changing server string CurrentDatabase(); // returns databsename or null if mastor/system. will NOT return "" void ChangeDatabase(string databaseName); // Using null will only change to what used in original connection string not master // null = whatevers in connections string "" = change to master void CommandTimeout(int minutes); string DataSource(); void Begin(); void Commit(); void Rollback(); [OperationContract] DataSet Schema(); DataSet Schema(string tableName); DataSet Schema(string[] tableNames); [OperationContract] DataSet SchemaNative(); [OperationContract] DataSet SchemaConnection(); // Can not be called within a transaction for: SQL - Works with: MySQL [OperationContract] DataSet SchemaReader(); [OperationContract] DataSet SchemaANSI(); [OperationContract] void SchemaRefresh(); string[] DatabaseList(); // ALL Databse methods Can not be called within a transaction void DatabaseCreate(string databaseName); void DatabaseCreate(string databaseName, DataSet schema); // Will create all keys, If don;t want then add each table manually void DatabaseDelete(string databaseName); // If having problems with database in use the do dal.ChangeDatabase(""); before bool DatabaseExists(string databaseName); // Create all tables pass only schema [OperationContract] string[] TableList(); void TableCreate(string tableName, DataSet schema); // Will only add Primary keys "P". Others need adding with TableAddKeys(schema, "UIF") If you don't want PKs then bodge them out of the schema void TableCreate(string tableName, DataTable schemaColumns, DataTable schemaKeys); void TableDelete(string tableName); bool TableExists(string tableName); void TableClear(string tableName); // Uses truncate if no ForeignReferences otherwise uses delete void TableAddKeys(DataSet schema, string keyTypesPUIF); void TableAddKeys(string tableName, DataSet schema, string keyTypesPUIF); void TableAddKeys(string[] tableNames, DataSet schema, string keyTypesPUIF); string[] LoginList(); void LoginCreate(string loginName, bool administrator); void LoginCreate(string loginName, string password, bool administrator); void LoginDelete(string loginName); bool LoginExists(string loginName); string[] UserList(); // All user methods need a current datatabase void UserCreate(string userName, string loginName, bool administrator); void UserDelete(string userName); bool UserExists(string userName); // Only "SQL Server" will work from a remote connection. Others need to be run on the same host as database server, as they all use external executables !!!! void Backup(string serverFilename); // backup and restore no available within a transaction void Restore(string serverFilename); // Will rename data and log files !!!!!!!!!!!!!!!! will not support multiple data files like in big setups string RunScript(string localFilename, string server, string database); string RunScript(string localFilename, string server, string database, string userName, string password); // NEED TO TEST password version void Operation(string details); // Must be lower case commands for speed no string checking make sure clean !!!! string PageCommandText(string commandText, int pageIndex, int pageSize); // @ParamName // @ParamAndColumn:TableName // @ParamName:TableName.ColumnName // Can not use above systax in command text !!!!!!!!!!!!! have to use "string[] parameterNames, object[] parameterValues" overload and not "object[] parameterValues" only DAL.CommandInfo MakeCommandInfo(string commandText); DAL.CommandInfo MakeCommandInfo(string commandText, string[] parameterNames); DbCommand MakeCommand(string commandText); DbCommand MakeCommand(string commandText, params object[] parameterValues); DbCommand MakeCommand(string commandText, string[] parameterNames, params object[] parameterValues); DbCommand MakeCommand(DAL.CommandInfo commandInfo, params object[] parameterValues); [OperationContract] object ExecuteScalar(string commandText); object ExecuteScalar(string commandText, params object[] parameterValues); object ExecuteScalar(string commandText, string[] parameterNames, params object[] parameterValues); object ExecuteScalar(DAL.CommandInfo commandInfo, params object[] parameterValues); object ExecuteScalar(DbCommand command); [OperationContract] int ExecuteNonQuery(string commandText); int ExecuteNonQuery(string commandText, params object[] parameterValues); int ExecuteNonQuery(string commandText, string[] parameterNames, params object[] parameterValues); int ExecuteNonQuery(DAL.CommandInfo commandInfo, params object[] parameterValues); int ExecuteNonQuery(DbCommand command); void Fill(DataSet dataSet, string commandText); void Fill(DataSet dataSet, string commandText, params object[] parameterValues); void Fill(DataSet dataSet, string commandText, string[] parameterNames, params object[] parameterValues); void Fill(DataSet dataSet, DAL.CommandInfo commandInfo, params object[] parameterValues); void Fill(DataSet dataSet, DbCommand command); void Fill(DataTable table, string commandText); void Fill(DataTable table, string commandText, params object[] parameterValues); void Fill(DataTable table, string commandText, string[] parameterNames, params object[] parameterValues); void Fill(DataTable table, DAL.CommandInfo commandInfo, params object[] parameterValues); void Fill(DataTable table, DbCommand command); [OperationContract] //[FaultContract(typeof(System.Data.Odbc.OdbcException))] DataTable Select(string commandText); DataTable Select(string commandText, params object[] parameterValues); DataTable Select(string commandText, string[] parameterNames, params object[] parameterValues); DataTable Select(DAL.CommandInfo commandInfo, params object[] parameterValues); DataTable Select(DbCommand command); [OperationContract] DataSet SelectDS(string commandText); DataSet SelectDS(string commandText, params object[] parameterValues); DataSet SelectDS(string commandText, string[] parameterNames, params object[] parameterValues); DataSet SelectDS(DAL.CommandInfo commandInfo, params object[] parameterValues); DataSet SelectDS(DbCommand command); DAL.CommandInfo MakeInserter(string tableName); // Change to ulong to support MySQL max ???? long Insert(DataRow row); // Table name from row's Table long Insert(string tableName, DataRow row); long Insert(DAL.CommandInfo insertInfo, DataRow row); long Insert(string tableName, params object[] row); // Array must not include identity columns !! long Insert(DAL.CommandInfo insertInfo, params object[] row); DAL.CommandInfo MakeUpdater(string tableName); // Schema from DB update all columns except PKs DAL.CommandInfo MakeUpdater(string tableName, string[] updateColumns); // params !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! int Update(DataRow row); // Table name from row's Table int Update(string tableName, DataRow row); int Update(string tableName, string[] columns, DataRow row); // Just update columns int Update(DAL.CommandInfo info, DataRow row); int Update(string tableName, params object[] row); // ??? Only works if passed object[] is for the whole row- no part updates int Update(string tableName, string[] columns, params object[] row); int Update(DAL.CommandInfo info, params object[] row); // Array is PK columns then update columns long InsertOrUpdate(DataRow row); long InsertOrUpdate(string tableName, DataRow row); // If the rows primary key columns exist in the database then it updates otherwise will insert void BulkInsert(DataTable table, string tableName, string tempDirectory); // BulkInsert on MS SQL will disbale foreigh key checking!!! // BulkInsert on MS SQL not required tempDirectory } }