Checking in latest SDALEO changes optimizing Advantage really only.

This commit is contained in:
2016-07-25 14:48:03 -04:00
parent 122796eaa3
commit 4a683f3443
114 changed files with 1173 additions and 372 deletions

View File

@@ -2,13 +2,26 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Sdaleo.Systems;
using System.Data.Common;
#if SQLSERVER
using System.Data.SqlClient;
using System.Collections;
#endif
#if SQLCOMPACT
using System.Data.SqlServerCe;
using Sdaleo.Systems;
using Devart.Data.PostgreSql;
#endif
#if ADVANTAGE
using Advantage.Data.Provider;
#endif
#if CTREE
#endif
#if MYSQL
#endif
#if POSTGRES
//using Devart.Data.PostgreSql;
#endif
namespace Sdaleo
{
@@ -17,6 +30,8 @@ namespace Sdaleo
/// </summary>
internal static class DBMS
{
#region Connection DB Specifics
/// <summary>
/// Creates a Connection Object depending on the type of DBMS we are using
/// </summary>
@@ -30,34 +45,37 @@ namespace Sdaleo
{
switch (dbsystem)
{
#if SQLSERVER
case DBSystem.SQL_SERVER:
if(SystemAvailable.Check(dbsystem))
connection = (DbConnection)new SqlConnection(ConnectionStr);
connection = (DbConnection)new SqlConnection(ConnectionStr);
break;
case DBSystem.SQL_CE:
if (SystemAvailable.Check(dbsystem))
connection = (DbConnection)new SqlCeConnection(ConnectionStr);
#endif
#if SQLCOMPACT
case DBSystem.SQL_CE:
connection = (DbConnection)new SqlCeConnection(ConnectionStr);
break;
#endif
#if ADVANTAGE
case DBSystem.ADVANTAGE:
if (SystemAvailable.Check(dbsystem))
connection = (DbConnection)new SqlCeConnection(ConnectionStr);
connection = (DbConnection)new AdsConnection(ConnectionStr);
break;
#endif
#if CTREE
case DBSystem.CTREE:
if (SystemAvailable.Check(dbsystem))
connection = (DbConnection)new SqlCeConnection(ConnectionStr);
connection = null;
break;
#endif
#if MYSQL
case DBSystem.MYSQL:
if (SystemAvailable.Check(dbsystem))
connection = (DbConnection)new SqlCeConnection(ConnectionStr);
connection = null;
break;
#endif
#if POSTGRES
case DBSystem.POSTGRES:
if (SystemAvailable.Check(dbsystem))
connection = (DbConnection)new PgSqlConnection(ConnectionStr);
connection = null;
break;
#endif
default:
break;
}
}
@@ -75,118 +93,41 @@ namespace Sdaleo
DbDataAdapter dbDataAdapter = null;
switch (dbsystem)
{
case DBSystem.SQL_SERVER:
if (SystemAvailable.Check(dbsystem))
dbDataAdapter = new SqlDataAdapter((SqlCommand) dbcommand);
#if SQLSERVER
case DBSystem.SQL_SERVER:
dbDataAdapter = new SqlDataAdapter((SqlCommand) dbcommand);
break;
#endif
#if SQLCOMPACT
case DBSystem.SQL_CE:
if (SystemAvailable.Check(dbsystem))
dbDataAdapter = new SqlCeDataAdapter((SqlCeCommand) dbcommand);
dbDataAdapter = new SqlCeDataAdapter((SqlCeCommand) dbcommand);
break;
#endif
#if ADVANTAGE
case DBSystem.ADVANTAGE:
if (SystemAvailable.Check(dbsystem))
dbDataAdapter = new SqlCeDataAdapter((SqlCeCommand)dbcommand);
dbDataAdapter = new AdsDataAdapter((AdsCommand) dbcommand);
break;
#endif
#if CTREE
case DBSystem.CTREE:
if (SystemAvailable.Check(dbsystem))
dbDataAdapter = new SqlCeDataAdapter((SqlCeCommand)dbcommand);
dbDataAdapter = null;
break;
#endif
#if MYSQL
case DBSystem.MYSQL:
if (SystemAvailable.Check(dbsystem))
dbDataAdapter = new SqlCeDataAdapter((SqlCeCommand)dbcommand);
dbDataAdapter = null;
break;
case DBSystem.POSTGRES:
if (SystemAvailable.Check(dbsystem))
dbDataAdapter = new PgSqlDataAdapter((PgSqlCommand)dbcommand);
#endif
#if POSTGRES
case DBSystem.POSTGRES:
dbDataAdapter = null;
break;
#endif
default:
break;
}
return dbDataAdapter;
}
/// <summary>
/// Creates an Error Object to be returned to the Caller, fills values depending on DBMS
/// </summary>
/// <param name="dbsystem">the DBSystem you want an Error for</param>
/// <param name="e">the exception being thrown by the DBMS</param>
/// <returns>a DBRetVal Object filled with the Error Data, or null if system is not available</returns>
internal static DBRetVal CreateErrorDBRetVal(DBSystem dbsystem, Exception e)
{
DBRetVal retVal = null;
switch (dbsystem)
{
case DBSystem.SQL_SERVER:
{
if (SystemAvailable.Check(dbsystem))
{
SqlException ex = e as SqlException;
if (ex != null)
retVal = new DBRetVal(ex.Number, ex.Message, ex.Errors);
}
}
break;
case DBSystem.SQL_CE:
{
if (SystemAvailable.Check(dbsystem))
{
SqlCeException ex = e as SqlCeException;
if (ex != null)
retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
}
break;
case DBSystem.ADVANTAGE:
{
if (SystemAvailable.Check(dbsystem))
{
SqlCeException ex = e as SqlCeException;
if (ex != null)
retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
}
break;
case DBSystem.CTREE:
{
if (SystemAvailable.Check(dbsystem))
{
SqlCeException ex = e as SqlCeException;
if (ex != null)
retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
}
break;
case DBSystem.MYSQL:
{
if (SystemAvailable.Check(dbsystem))
{
SqlCeException ex = e as SqlCeException;
if (ex != null)
retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
}
break;
case DBSystem.POSTGRES:
{
if (SystemAvailable.Check(dbsystem))
{
PgSqlException ex = e as PgSqlException;
if (ex != null)
retVal = new DBRetVal(0, ex.Message, null);
}
}
break;
}
return retVal;
}
/// <summary>
/// Creates a DBMS Specific Parameter Array from a DMBS Independent Parameter Array
@@ -203,64 +144,244 @@ namespace Sdaleo
{
switch (dbsystem)
{
#if SQLSERVER
case DBSystem.SQL_SERVER:
{
if (SystemAvailable.Check(dbsystem))
{
param_s.Add(new SqlParameter(parameter.parameterName, parameter.Value));
}
}
param_s.Add(new SqlParameter(parameter.parameterName, parameter.Value));
break;
#endif
#if SQLCOMPACT
case DBSystem.SQL_CE:
{
if (SystemAvailable.Check(dbsystem))
{
param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
}
}
param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
break;
#endif
#if ADVANTAGE
case DBSystem.ADVANTAGE:
{
if (SystemAvailable.Check(dbsystem))
{
param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
}
}
param_s.Add(new AdsParameter(parameter.parameterName, parameter.Value));
break;
#endif
#if CTREE
case DBSystem.CTREE:
{
if (SystemAvailable.Check(dbsystem))
{
param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
}
}
//param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
break;
#endif
#if MYSQL
case DBSystem.MYSQL:
{
if (SystemAvailable.Check(dbsystem))
{
param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
}
}
//param_s.Add(new SqlCeParameter(parameter.parameterName, parameter.Value));
break;
case DBSystem.POSTGRES:
{
if (SystemAvailable.Check(dbsystem))
{
param_s.Add(new PgSqlParameter(parameter.parameterName, parameter.Value));
}
}
#endif
#if POSTGRES
case DBSystem.POSTGRES:
//param_s.Add(new PgSqlParameter(parameter.parameterName, parameter.Value));
break;
#endif
default:
break;
}
}
// Return the Parameter
return param_s.ToArray();
return param_s.ToArray();
}
#endregion
#region Exception DB Specifics
/// <summary>
/// Creates an Error Object to be returned to the Caller, fills values depending on DBMS
/// </summary>
/// <param name="dbsystem">the DBSystem you want an Error for</param>
/// <param name="e">the exception being thrown by the DBMS</param>
/// <returns>a DBRetVal Object filled with the Error Data, or null if system is not available</returns>
internal static DBRetVal CreateErrorDBRetVal(DBSystem dbsystem, Exception e)
{
////
// We want to always make sure in this function that we always return a DBRetVal object
// we should never return null
////
DBRetVal retVal = null;
if(e == null || String.IsNullOrEmpty(e.Message))
{
retVal = new DBRetVal("DB Error Exception object is null or with Empty Message");
return retVal;
}
try
{
switch (dbsystem)
{
#if SQLSERVER
case DBSystem.SQL_SERVER:
{
SqlException ex = e as SqlException;
if (ex != null)
retVal = new DBRetVal(ex.Number, ex.Message, ex.Errors);
}
break;
#endif
#if SQLCOMPACT
case DBSystem.SQL_CE:
{
SqlCeException ex = e as SqlCeException;
if (ex != null)
retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
break;
#endif
#if ADVANTAGE
case DBSystem.ADVANTAGE:
{
AdsException ex = e as AdsException;
if (ex != null)
retVal = new DBRetVal(ex.Number, ex.Message, null);
}
break;
#endif
#if CTREE
case DBSystem.CTREE:
{
//SqlCeException ex = e as SqlCeException;
//if (ex != null)
// retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
break;
#endif
#if MYSQL
case DBSystem.MYSQL:
{
//SqlCeException ex = e as SqlCeException;
//if (ex != null)
// retVal = new DBRetVal(ex.NativeError, ex.Message, ex.Errors);
}
break;
#endif
#if POSTGRES
case DBSystem.POSTGRES:
{
//PgSqlException ex = e as PgSqlException;
//if (ex != null)
// retVal = new DBRetVal(0, ex.Message, null);
}
break;
#endif
default:
break;
}
}
catch (Exception ex)
{
retVal = new DBRetVal(ex.Message);
}
////
// We want to always make sure in this function that we always return a DBRetVal object
// we should never return null
////
if (retVal == null)
retVal = new DBRetVal("DB Error Exception object could not be created");
return retVal;
}
/// <summary>
/// Returns the Error Number for the specified Exception Object for the specified DMBS,
/// or -1 if an error occured
/// </summary>
/// <param name="dbsystem">>the DBSystem you want an Error Number for</param>
/// <param name="e">the exception being thrown by the DBMS</param>
/// <returns>the Error Number (ID) of the Exception thrown or -1 if anything else happened</returns>
internal static int GetErrorNumberForErrorObject(DBSystem dbsystem, Exception e)
{
int nError = -1;
if (e == null || String.IsNullOrEmpty(e.Message))
return nError;
try
{
switch (dbsystem)
{
#if SQLSERVER
case DBSystem.SQL_SERVER:
{
SqlException ex = e as SqlException;
if (ex != null)
nError = ex.Number;
}
break;
#endif
#if SQLCOMPACT
case DBSystem.SQL_CE:
{
SqlCeException ex = e as SqlCeException;
if (ex != null)
nError = ex.NativeError;
}
break;
#endif
#if ADVANTAGE
case DBSystem.ADVANTAGE:
{
AdsException ex = e as AdsException;
if (ex != null)
nError = ex.Number;
}
break;
#endif
#if CTREE
case DBSystem.CTREE:
{
//SqlCeException ex = e as SqlCeException;
//if (ex != null)
// nError = ex.NativeError;
}
break;
#endif
#if MYSQL
case DBSystem.MYSQL:
{
//SqlCeException ex = e as SqlCeException;
//if (ex != null)
// nError = ex.NativeError;
}
break;
#endif
#if POSTGRES
case DBSystem.POSTGRES:
{
//PgSqlException ex = e as PgSqlException;
//if (ex != null)
// nError = ex.NativeError;
}
break;
#endif
default:
break;
}
}
catch (Exception ex) { /* ignore */ }
return nError;
}
/// <summary>
/// Retrieves all Error Numbers that the specified DBError has in it's collection.
/// If it doesn't have a collection it will just return an empty list.
/// </summary>
/// <param name="dbsystem"></param>
/// <param name="error"></param>
/// <returns></returns>
internal static List<int> GetAllErrorNumbers(DBSystem dbsystem, DBError error)
{
List<int> list = new List<int>();
if (error != null && error.Errors != null)
{
foreach (Exception e in error.Errors)
{
int nError = GetErrorNumberForErrorObject(dbsystem, e);
list.Add(nError);
}
}
return list;
}
#endregion
}
}

View File

@@ -23,6 +23,19 @@ namespace Sdaleo
return false;
}
/// <summary>
/// Returns true if passed in object is valid and is empty
/// </summary>
/// <param name="oToValidate">an object to validate</param>
/// <returns>true if valid, false otherwise</returns>
internal static bool IsNotNullAndIsEmpty(object oToValidate)
{
if ((oToValidate != null) && (oToValidate.ToString() == String.Empty))
return true;
else
return false;
}
/// <summary>
/// Convert a string to an Object of Type T
/// </summary>

View File

@@ -75,7 +75,7 @@ namespace Sdaleo
ServerAddress = values[0];
InstanceName = values[1];
}
else if (value.Length > 2)
else if (values.Length > 2)
{
int nIndx = value.LastIndexOf('\\');
ServerAddress = value.Substring(0, nIndx);
@@ -120,6 +120,11 @@ namespace Sdaleo
/// </summary>
internal string AttachDBFilename { get; private set; }
/// <summary>
///
/// </summary>
internal string ServerType { get; private set; }
#endregion
#region ReadOnly Bool Getters
@@ -180,6 +185,26 @@ namespace Sdaleo
#endregion
#region Advantage Constructors
/// <summary>
/// Construction Advantage (Set common UDL Settings for Advantage)
/// </summary>
/// <param name="path"></param>
/// <param name="filename"></param>
/// <param name="Password"></param>
/// <param name="ServerType"></param>
internal UDL(string FileNameNPath, string UserID, string Password, string ServerType)
{
UseConnectionTimeout = false;
this.DataSource = FileNameNPath;
this.Username = UserID;
this.Password = Password;
this.ServerType = ServerType;
}
#endregion
#region SQL Server Constructors
/// <summary>
@@ -330,6 +355,14 @@ namespace Sdaleo
strUDL += strAddMore;
}
// Advantage DB
if (!String.IsNullOrEmpty(ServerType))
{
string strAddMore = String.Format("ServerType={0};", ServerType);
strUDL += strAddMore;
strUDL += "TableType=ADT;";
}
// At the end, specifically add the connection timeout * If asked to *
if (UseConnectionTimeout)
{
@@ -367,41 +400,43 @@ namespace Sdaleo
String[] tokens = ConnectionString.Split(';');
foreach (string Pair in tokens)
{
string[] KeyValuePair = Pair.Split('=');
string[] KeyValuePair = Pair.Split('=');
try
{
string left = KeyValuePair[0];
string right = KeyValuePair[1];
switch (KeyValuePair[0].ToUpper().Trim())
{
case "INITIAL CATALOG":
DataBase = KeyValuePair[1].Trim();
DataBase = right.Trim();
break;
case "USER ID":
Username = KeyValuePair[1].Trim();
Username = right.Trim();
break;
case "PASSWORD":
Password = KeyValuePair[1];
Password = right;
break;
case "DATA SOURCE":
DataSource = KeyValuePair[1].Trim();
case "DATA SOURCE":
DataSource = right.Trim();
break;
case "ATTACHDBFILENAME":
AttachDBFilename = KeyValuePair[1].Trim();
AttachDBFilename = right.Trim();
break;
case "USER INSTANCE":
UserInstance = Boolean.Parse(KeyValuePair[1].Trim());
UserInstance = Boolean.Parse(right.Trim());
break;
case "CONNECTION TIMEOUT":
ConnectionTimeout = UInt32.Parse(KeyValuePair[1].Trim());
ConnectionTimeout = UInt32.Parse(right.Trim());
break;
case "TRUSTED_CONNECTION":
TrustedConnection = Boolean.Parse(KeyValuePair[1].Trim());
TrustedConnection = Boolean.Parse(right.Trim());
break;
case "INTEGRATED SECURITY":
@@ -420,9 +455,13 @@ namespace Sdaleo
Encrypt = true;
break;
case "SERVERTYPE":
ServerType = KeyValuePair[1].Trim();
break;
}
}
catch (Exception) { /* ignore and continue iteration */ }
catch (Exception e) { string m = e.Message; /* ignore and continue iteration */ }
}
}
}