110 lines
4.1 KiB
C#
110 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using Sarand.Net.Standard.Base.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
|
|
namespace Sarand.Net.Standard.Base.Dbas
|
|
{
|
|
//=======================================================================
|
|
// Definitions.
|
|
public enum DbmsType
|
|
{
|
|
General = 0,
|
|
Access = 10,
|
|
MsSql,
|
|
MySql,
|
|
Oracle,
|
|
Pervasive,
|
|
Dbase,
|
|
FoxPro,
|
|
Paradox,
|
|
Interbase,
|
|
Postgres,
|
|
/// <summary>Sage db - No 'AS' in table alias, no 'OUTER' in join type.</summary>
|
|
Sage,
|
|
QBooks,
|
|
SybaseAdvantage,
|
|
}
|
|
public enum SelectLockMode
|
|
{
|
|
/// <summary>No specific lock mode requested - use DBMS default.</summary>
|
|
Default,
|
|
/// <summary>Shared locks (MSSQL default). [MSSQL]</summary>
|
|
ReadCommitted,
|
|
/// <summary>Dirty reads - no locking. [MSSQL]</summary>
|
|
ReadUncommitted,
|
|
/// <summary>Locks all data in query. [MSSQL]</summary>
|
|
RepeatableRead,
|
|
/// <summary>Range lock on data preventing modifications. [MSSQL]</summary>
|
|
Serializable,
|
|
};
|
|
/// <summary>Reserved word delimiters - used by database definitions.</summary>
|
|
public enum DbReservedWordDelim
|
|
{
|
|
None,
|
|
SquareBrackets,
|
|
DoubleQuotes
|
|
};
|
|
public enum DbGetValueType { eDbValueSum, eDbValueMin, eDbValueMax };
|
|
|
|
//=======================================================================
|
|
public interface ISacsDatabase : ISacsStateItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Database properties.
|
|
String ConnectionString { get; }
|
|
DbmsType DbmsType { get; }
|
|
String DatabaseName { get; }
|
|
SelectLockMode SelectLockMode { get; set; }
|
|
bool DisplayErrors { get; set; }
|
|
DbConnection CreateConnection(bool forceOdbc = false);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Identity generation.
|
|
SysId GetNextId(String objectName, DbUpdateInfo dbUpdateInfo, bool databaseTable = true, String idColumn = "Id");
|
|
int GetNextIdFromTable(String objectName, String idColumn = "Id");
|
|
bool SetMinNextId(String objectName, SysId id, DbUpdateInfo dbUpdateInfo, bool databaseTable = true, String idColumn = "Id", bool force = false);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Database schema.
|
|
List<String> GetTableNames(bool refresh = false);
|
|
List<DbDfnTable> GetTableDfns(bool refresh = false);
|
|
DbDfnTable GetTableDfn(String name, bool refresh = false);
|
|
bool TableExists(String tableName);
|
|
bool ColumnExists(String tableName, String columnName);
|
|
bool IndexExists(String tableName, String indexName);
|
|
// Database info - schema summary.
|
|
IDatabaseInfo CreateDbInfo();
|
|
|
|
//-------------------------------------------------------------------
|
|
// Password utilities.
|
|
public enum PasswordHashMethod { MsSql }
|
|
/// <summary>Generate password hash using the specified method.</summary>
|
|
String EncodePassword_Hex(String password, PasswordHashMethod method = PasswordHashMethod.MsSql);
|
|
/// <summary>Compare password to hashed value using the specified method.</summary>
|
|
bool ComparePassword_Hex(String password, String passwordHashHex, ISacsDatabase.PasswordHashMethod method = ISacsDatabase.PasswordHashMethod.MsSql);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Query records.
|
|
String GetSelectQueryPrefix();
|
|
/// <summary>
|
|
/// Execute query directly against database.
|
|
/// <para>- NB Check for null response and error state.</para>
|
|
/// </summary>
|
|
DbResultSet ExecuteQuery(String query);
|
|
int ExecuteNonQuery(String query);
|
|
int ExecuteInsert(String tableName, List<StringPair> columnNameValues);
|
|
int ExecuteUpdate(String tableName, List<StringPair> columnNameValues, String filter);
|
|
int ExecuteDelete(String tableName, String filter);
|
|
// Specific queries.
|
|
long GetRowCount(String tableName, String filter);
|
|
DataValue GetRowValue(String tableName, String columnName, String filter);
|
|
DataValue GetRowValue(String tableName, String columnName, String filter, DbGetValueType getValueType);
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
|
|
//=======================================================================
|
|
}
|