Skip to content

Commit

Permalink
Refactoring for the connector
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed May 18, 2016
1 parent 84eeb26 commit 67954c1
Show file tree
Hide file tree
Showing 55 changed files with 847 additions and 646 deletions.
47 changes: 25 additions & 22 deletions dg.Sql.Connector.MsSql/MsSqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,36 +329,36 @@ public override DbTransaction Transaction

#region Preparing values for SQL

public override string EncloseFieldName(string FieldName)
public override string WrapFieldName(string fieldName)
{ // Note: For performance, ignoring enclosed [] signs
return '[' + FieldName + ']';
return '[' + fieldName + ']';
}

public override string PrepareValue(Guid Value)
public override string PrepareValue(Guid value)
{
return '\'' + Value.ToString(@"D") + '\'';
return '\'' + value.ToString(@"D") + '\'';
}
public override string PrepareValue(string Value)
public override string PrepareValue(string value)
{
return @"N'" + EscapeString(Value) + '\'';
return @"N'" + EscapeString(value) + '\'';
}
public override string FormatDate(DateTime DateTime)
public override string FormatDate(DateTime dateTime)
{
return DateTime.ToString(@"yyyy-MM-dd HH:mm:ss");
return dateTime.ToString(@"yyyy-MM-dd HH:mm:ss");
}

public override string EscapeLike(string LikeExpression)
public override string EscapeLike(string expression)
{
return LikeExpression.Replace(@"\", @"\\").Replace(@"%", @"\%").Replace(@"_", @"\_");
return expression.Replace(@"\", @"\\").Replace(@"%", @"\%").Replace(@"_", @"\_");
}

#endregion

#region Reading values from SQL

public override Geometry ReadGeometry(object Value)
public override Geometry ReadGeometry(object value)
{
byte[] geometryData = Value as byte[];
byte[] geometryData = value as byte[];
if (geometryData != null)
{
return WkbReader.GeometryFromWkb(geometryData, false);
Expand All @@ -380,21 +380,24 @@ public override string varchar_MAX
get { return "MAX"; }
}

public override string func_UTC_NOW
public override string func_UTC_NOW()
{
get { return @"GETUTCDATE()"; }
return @"GETUTCDATE()";
}
public override string func_HOUR(string Date)

public override string func_HOUR(string date)
{
return @"DATEPART(hour, " + Date + ")";
return @"DATEPART(hour, " + date + ")";
}
public override string func_MINUTE(string Date)

public override string func_MINUTE(string date)
{
return @"DATEPART(minute, " + Date + ")";
return @"DATEPART(minute, " + date + ")";
}
public override string func_SECOND(string Date)

public override string func_SECOND(string date)
{
return @"DATEPART(second, " + Date + ")";
return @"DATEPART(second, " + date + ")";
}

public override string func_MD5(string value)
Expand All @@ -409,9 +412,9 @@ public override string func_MD5(string value)
}
}

public override string func_LENGTH
public override string func_LENGTH(string value)
{
get { return @"LEN"; }
return @"LEN(" + value + ")";
}

public override string type_TINYINT { get { return @"TINYINT"; } }
Expand Down
104 changes: 64 additions & 40 deletions dg.Sql.Connector.MsSql/MsSqlDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public MsSqlDataReader(System.Data.SqlClient.SqlDataReader Reader)
{
_Reader = Reader;
}

public MsSqlDataReader(System.Data.SqlClient.SqlDataReader Reader, ConnectorBase ConnectionToClose)
{
_Reader = Reader;
Expand All @@ -34,6 +35,7 @@ public override void Dispose()
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposing)
Expand All @@ -42,6 +44,7 @@ protected virtual void Dispose(bool disposing)
}
// Now clean up Native Resources (Pointers)
}

~MsSqlDataReader()
{
Dispose(false);
Expand All @@ -54,103 +57,124 @@ public override void Close()
if (_Reader != null) _Reader.Dispose();
if (_ConnectionToClose != null) _ConnectionToClose.Dispose();
}

public override bool Read()
{
return _Reader.Read();
}
public override bool IsDBNull(int ColumnIndex)

public override bool IsDBNull(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex);
return _Reader.IsDBNull(columnIndex);
}
public override int GetInt32(int ColumnIndex)

public override int GetInt32(int columnIndex)
{
return _Reader.GetInt32(ColumnIndex);
return _Reader.GetInt32(columnIndex);
}
public override int GetInt32OrZero(int ColumnIndex)

public override int GetInt32OrZero(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? 0 : _Reader.GetInt32(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? 0 : _Reader.GetInt32(columnIndex);
}
public override Int64 GetInt64(int ColumnIndex)

public override Int64 GetInt64(int columnIndex)
{
return _Reader.GetInt64(ColumnIndex);
return _Reader.GetInt64(columnIndex);
}
public override Int64 GetInt64OrZero(int ColumnIndex)

public override Int64 GetInt64OrZero(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? 0 : _Reader.GetInt64(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? 0 : _Reader.GetInt64(columnIndex);
}
public override bool GetBoolean(int ColumnIndex)

public override bool GetBoolean(int columnIndex)
{
return _Reader.GetBoolean(ColumnIndex);
return _Reader.GetBoolean(columnIndex);
}
public override string GetString(int ColumnIndex)

public override string GetString(int columnIndex)
{
return _Reader.GetString(ColumnIndex);
return _Reader.GetString(columnIndex);
}
public override string GetStringOrNull(int ColumnIndex)

public override string GetStringOrNull(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? null : _Reader.GetString(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? null : _Reader.GetString(columnIndex);
}
public override string GetStringOrEmpty(int ColumnIndex)

public override string GetStringOrEmpty(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? String.Empty : _Reader.GetString(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? String.Empty : _Reader.GetString(columnIndex);
}
public override DateTime GetDateTime(int ColumnIndex)

public override DateTime GetDateTime(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? DateTime.FromBinary(0) : _Reader.GetDateTime(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? DateTime.FromBinary(0) : _Reader.GetDateTime(columnIndex);
}
public override DateTime? GetDateTimeOrNull(int ColumnIndex)

public override DateTime? GetDateTimeOrNull(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? null : (DateTime?)_Reader.GetDateTime(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? null : (DateTime?)_Reader.GetDateTime(columnIndex);
}
public override DateTime GetDateTimeOrMinValue(int ColumnIndex)

public override DateTime GetDateTimeOrMinValue(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? DateTime.MinValue : _Reader.GetDateTime(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? DateTime.MinValue : _Reader.GetDateTime(columnIndex);
}
public override decimal GetDecimal(int ColumnIndex)

public override decimal GetDecimal(int columnIndex)
{
return _Reader.GetDecimal(ColumnIndex);
return _Reader.GetDecimal(columnIndex);
}
public override decimal GetDecimalOrZero(int ColumnIndex)

public override decimal GetDecimalOrZero(int columnIndex)
{
return _Reader.IsDBNull(ColumnIndex) ? 0 : _Reader.GetDecimal(ColumnIndex);
return _Reader.IsDBNull(columnIndex) ? 0 : _Reader.GetDecimal(columnIndex);
}
public override bool HasColumn(string ColumnName)

public override bool HasColumn(string columnName)
{
for (int j = 0, len = _Reader.VisibleFieldCount; j < len; j++)
{
if (_Reader.GetName(j).Equals(ColumnName, StringComparison.OrdinalIgnoreCase)) return true;
if (_Reader.GetName(j).Equals(columnName, StringComparison.OrdinalIgnoreCase)) return true;
}
return false;
}

public override Int32 GetColumnCount()
{
return _Reader.VisibleFieldCount;
}
public override string GetColumnName(Int32 ColumnIndex)

public override string GetColumnName(Int32 columnIndex)
{
return _Reader.GetName(ColumnIndex);
return _Reader.GetName(columnIndex);
}
public override object this[int ColumnIndex]

public override object this[int columnIndex]
{
get { return _Reader[ColumnIndex]; }
get { return _Reader[columnIndex]; }
}
public override object this[string ColumnName]

public override object this[string columnName]
{
get { return _Reader[ColumnName]; }
get { return _Reader[columnName]; }
}

public override Geometry GetGeometry(int ColumnIndex)
public override Geometry GetGeometry(int columnIndex)
{
byte[] geometryData = _Reader[ColumnIndex] as byte[];
byte[] geometryData = _Reader[columnIndex] as byte[];
if (geometryData != null)
{
return WkbReader.GeometryFromWkb(geometryData, false);
}
return null;
}
public override Geometry GetGeometry(string ColumnName)

public override Geometry GetGeometry(string columnName)
{
byte[] geometryData = _Reader[ColumnName] as byte[];
byte[] geometryData = _Reader[columnName] as byte[];
if (geometryData != null)
{
return WkbReader.GeometryFromWkb(geometryData, false);
Expand Down
71 changes: 42 additions & 29 deletions dg.Sql.Connector.MsSql/MsSqlFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,41 @@ namespace dg.Sql.Connector
{
public class MsSqlFactory : FactoryBase
{
public override DbParameter NewParameter(string Name, object Value)
public override DbParameter NewParameter(string name, object value)
{
SqlParameter p = new SqlParameter(Name, Value);
SqlParameter p = new SqlParameter(name, value);
return p;
}
public override DbParameter NewParameter(string Name, DbType Type, object Value)

public override DbParameter NewParameter(string name, DbType type, object value)
{
SqlParameter p = new SqlParameter(Name, Value);
p.DbType = Type;
SqlParameter p = new SqlParameter(name, value);
p.DbType = type;
return p;
}
public override DbParameter NewParameter(string Name, object Value, ParameterDirection ParameterDirection)

public override DbParameter NewParameter(string name, object value, ParameterDirection ParameterDirection)
{
SqlParameter p = new SqlParameter(Name, Value);
SqlParameter p = new SqlParameter(name, value);
p.Direction = ParameterDirection;
return p;
}
public override DbParameter NewParameter(string Name, DbType Type, ParameterDirection ParameterDirection, int Size, bool IsNullable, byte Precision, byte Scale, string SourceColumn, DataRowVersion SourceVersion, object Value)

public override DbParameter NewParameter(string name, DbType type, ParameterDirection parameterDirection,
int size, bool isNullable,
byte precision, byte scale,
string sourceColumn, DataRowVersion sourceVersion,
object value)
{
SqlParameter p = new SqlParameter(Name, Value);
p.DbType = Type;
p.Direction = ParameterDirection;
p.Size = Size;
p.IsNullable = IsNullable;
p.Precision = Precision;
p.Scale = Scale;
p.SourceColumn = SourceColumn;
p.SourceVersion = SourceVersion;
SqlParameter p = new SqlParameter(name, value);
p.DbType = type;
p.Direction = parameterDirection;
p.Size = size;
p.IsNullable = isNullable;
p.Precision = precision;
p.Scale = scale;
p.SourceColumn = sourceColumn;
p.SourceVersion = sourceVersion;
return p;
}

Expand All @@ -45,19 +52,22 @@ public override DbCommand NewCommand()
SqlCommand p = new SqlCommand();
return p;
}
public override DbCommand NewCommand(string CommandText)

public override DbCommand NewCommand(string commandText)
{
SqlCommand p = new SqlCommand(CommandText);
SqlCommand p = new SqlCommand(commandText);
return p;
}
public override DbCommand NewCommand(string CommandText, DbConnection Connection)

public override DbCommand NewCommand(string commandText, DbConnection connection)
{
SqlCommand p = new SqlCommand(CommandText, (SqlConnection)Connection);
SqlCommand p = new SqlCommand(commandText, (SqlConnection)connection);
return p;
}
public override DbCommand NewCommand(string CommandText, DbConnection Connection, DbTransaction Transaction)

public override DbCommand NewCommand(string commandText, DbConnection connection, DbTransaction transaction)
{
SqlCommand p = new SqlCommand(CommandText, (SqlConnection)Connection, (SqlTransaction)Transaction);
SqlCommand p = new SqlCommand(commandText, (SqlConnection)connection, (SqlTransaction)transaction);
return p;
}

Expand All @@ -66,19 +76,22 @@ public override DbDataAdapter NewDataAdapter()
SqlDataAdapter da = new SqlDataAdapter();
return da;
}
public override DbDataAdapter NewDataAdapter(DbCommand SelectCommand)

public override DbDataAdapter NewDataAdapter(DbCommand selectCommand)
{
SqlDataAdapter da = new SqlDataAdapter((SqlCommand)SelectCommand);
SqlDataAdapter da = new SqlDataAdapter((SqlCommand)selectCommand);
return da;
}
public override DbDataAdapter NewDataAdapter(string SelectCommandText, DbConnection Connection)

public override DbDataAdapter NewDataAdapter(string selectCommandText, DbConnection connection)
{
SqlDataAdapter da = new SqlDataAdapter(SelectCommandText, (SqlConnection)Connection);
SqlDataAdapter da = new SqlDataAdapter(selectCommandText, (SqlConnection)connection);
return da;
}
public override DbDataAdapter NewDataAdapter(string SelectCommandText, string SelectConnString)

public override DbDataAdapter NewDataAdapter(string selectCommandText, string selectConnString)
{
SqlDataAdapter da = new SqlDataAdapter(SelectCommandText, SelectConnString);
SqlDataAdapter da = new SqlDataAdapter(selectCommandText, selectConnString);
return da;
}
}
Expand Down
Loading

0 comments on commit 67954c1

Please sign in to comment.