Data project added (previously Office)
This commit is contained in:
@@ -12,12 +12,12 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private int id = 0;
|
||||
private Int64 id = 0;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SysId () { }
|
||||
public SysId (int id)
|
||||
public SysId (Int64 id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
//-------------------------------------------------------------------
|
||||
// Properties - for serialisation.
|
||||
//[XmlAttribute]
|
||||
public int Id
|
||||
public Int64 Id
|
||||
{
|
||||
get { return id; }
|
||||
set
|
||||
@@ -62,12 +62,16 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
}
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return id;
|
||||
return id.GetHashCode();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Conversion.
|
||||
public int ToInt ()
|
||||
public Int64 ToLong()
|
||||
{
|
||||
return ToInt(this);
|
||||
}
|
||||
public Int32 ToInt()
|
||||
{
|
||||
return ToInt(this);
|
||||
}
|
||||
@@ -80,7 +84,11 @@ namespace Sarand.Net.Standard.Base.Bus
|
||||
return ToString(this, invalidValue);
|
||||
}
|
||||
// Null-safe static versions.
|
||||
public static int ToInt (SysId sysId)
|
||||
public static Int32 ToInt(SysId sysId)
|
||||
{
|
||||
return (IsValid(sysId) ? (Int32)sysId.id : 0);
|
||||
}
|
||||
public static Int64 ToLong(SysId sysId)
|
||||
{
|
||||
return (IsValid(sysId) ? sysId.id : 0);
|
||||
}
|
||||
|
||||
@@ -11,24 +11,24 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
{
|
||||
// Ref. https://msdn.microsoft.com/en-us/library/yy6y35y8%28v=vs.110%29.aspx
|
||||
Unknown = -1,
|
||||
VarChar, //SQL_C_CHAR,
|
||||
Bit, // SQL_C_BIT,
|
||||
TinyInt, // SQL_C_TINYINT,
|
||||
SmallInt, // SQL_C_SHORT,
|
||||
Int, //SQL_C_SLONG,
|
||||
BigInt, // SQL_C_SBIGINT,
|
||||
Single, // SQL_C_REAL,
|
||||
Double, // SQL_C_DOUBLE,
|
||||
VarChar, // SQL_C_CHAR,
|
||||
Bit, // SQL_C_BIT,
|
||||
TinyInt, // SQL_C_TINYINT,
|
||||
SmallInt, // SQL_C_SHORT,
|
||||
Int, // SQL_C_SLONG,
|
||||
BigInt, // SQL_C_SBIGINT,
|
||||
Single, // SQL_C_REAL,
|
||||
Double, // SQL_C_DOUBLE,
|
||||
Decimal, // SQL_DECIMAL?,
|
||||
DateTime, // SQL_C_TYPE_TIMESTAMP
|
||||
DateTime, // SQL_C_TYPE_TIMESTAMP
|
||||
Binary,
|
||||
};
|
||||
//[Serializable()]
|
||||
public enum DbColumnNullable
|
||||
{
|
||||
NoNulls = 0, // SQL_NO_NULLS,
|
||||
Nullable = 1, // SQL_NULLABLE,
|
||||
Unknown = 2, // SQL_NULLABLE_UNKNOWN, // Not known whether or not a data type supports null values.
|
||||
NoNulls = 0, // SQL_NO_NULLS,
|
||||
Nullable = 1, // SQL_NULLABLE,
|
||||
Unknown = 2, // SQL_NULLABLE_UNKNOWN, // Not known whether or not a data type supports null values.
|
||||
};
|
||||
//==========================================================================
|
||||
//[Serializable()]
|
||||
@@ -38,8 +38,8 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
// Data members.
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public DbDfnColumn () { }
|
||||
public DbDfnColumn (String schema, String table, short pos, String name)
|
||||
public DbDfnColumn() { }
|
||||
public DbDfnColumn(String schema, String table, short pos, String name)
|
||||
{
|
||||
Schema = schema;
|
||||
Table = table;
|
||||
@@ -65,7 +65,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public String Remarks { get; set; } = String.Empty;
|
||||
//-------------------------------------------------------------------
|
||||
// Variable type and default - used in variable declaration.
|
||||
public String GetVariableTypeName ()
|
||||
public String GetVariableTypeName()
|
||||
{
|
||||
switch (DataType)
|
||||
{
|
||||
@@ -74,7 +74,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
}
|
||||
return GetVariableType();
|
||||
}
|
||||
public String GetVariableType ()
|
||||
public String GetVariableType()
|
||||
{
|
||||
switch (DataType)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
public String GetVariableDefault ()
|
||||
public String GetVariableDefault()
|
||||
{
|
||||
switch (DataType)
|
||||
{
|
||||
@@ -132,7 +132,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
public String GetGetFieldSuffix ()
|
||||
public String GetGetFieldSuffix()
|
||||
{
|
||||
switch (DataType)
|
||||
{
|
||||
@@ -159,7 +159,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public static class DbDfnColumnList
|
||||
{
|
||||
// List of column names.
|
||||
public static List<String> GetNames (this List<DbDfnColumn> columns)
|
||||
public static List<String> GetNames(this List<DbDfnColumn> columns)
|
||||
{
|
||||
List<String> names = new List<String>();
|
||||
foreach (var column in columns)
|
||||
@@ -169,7 +169,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
return names;
|
||||
}
|
||||
// Identity column.
|
||||
public static String GetIdentityColumnName (this List<DbDfnColumn> columns)
|
||||
public static String GetIdentityColumnName(this List<DbDfnColumn> columns)
|
||||
{
|
||||
List<String> names = new List<String>();
|
||||
foreach (var column in columns)
|
||||
@@ -179,8 +179,19 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
public static String GetIdentityColumnVariableTypeName(this List<DbDfnColumn> columns)
|
||||
{
|
||||
List<String> names = new List<String>();
|
||||
foreach (var column in columns)
|
||||
{
|
||||
if (column.IsIdentity)
|
||||
return column.GetVariableTypeName();
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
// Locate the column in the list:
|
||||
public static DbDfnColumn GetColumnByPos (this List<DbDfnColumn> columns, short pos)
|
||||
public static DbDfnColumn GetColumnByPos(this List<DbDfnColumn> columns, short pos)
|
||||
{
|
||||
foreach (var column in columns)
|
||||
{
|
||||
@@ -189,7 +200,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static DbDfnColumn GetColumnByName (this List<DbDfnColumn> columns, String name)
|
||||
public static DbDfnColumn GetColumnByName(this List<DbDfnColumn> columns, String name)
|
||||
{
|
||||
foreach (var column in columns)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly List<DbDfnIndexColumn> columns = new List<DbDfnIndexColumn>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public DbDfnIndex () { }
|
||||
@@ -31,6 +32,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
Name = name;
|
||||
Unique = unique;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Attributes.
|
||||
public String Schema { get; set; } = String.Empty;
|
||||
@@ -44,23 +46,36 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
public int Pages { get; set; } = 0;
|
||||
public int UniqueValues { get; set; } = 0;
|
||||
public bool HasColumns { get; set; } = false;
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public List<DbDfnIndexColumn> Columns
|
||||
{
|
||||
get { return columns; }
|
||||
set { columns.Clear(); columns.AddRange(value); }
|
||||
get
|
||||
{
|
||||
lock (columns)
|
||||
return new List<DbDfnIndexColumn>(columns);
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (columns)
|
||||
columns.Clear(); columns.AddRange(value);
|
||||
}
|
||||
}
|
||||
public void CearColumns ()
|
||||
{
|
||||
columns.Clear();
|
||||
lock (columns)
|
||||
columns.Clear();
|
||||
}
|
||||
public void AddColumn (DbDfnIndexColumn column)
|
||||
{
|
||||
columns.Add(column);
|
||||
lock (columns)
|
||||
columns.Add(column);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// Index list extensions.
|
||||
public static class DbDfnIndexList
|
||||
@@ -92,5 +107,6 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public DbDfnTable () { }
|
||||
public DbDfnTable (String schema, String name, String remarks)
|
||||
public DbDfnTable() { }
|
||||
public DbDfnTable(String schema, String name, String remarks)
|
||||
{
|
||||
this.Schema = schema;
|
||||
this.Name = name;
|
||||
@@ -33,41 +33,53 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Comparison.
|
||||
public bool MatchesSchemaName (String schema, String name)
|
||||
public bool MatchesSchemaName(String schema, String name)
|
||||
{
|
||||
return (this.Schema.EqualsCI(schema) && this.Name.EqualsCI(name));
|
||||
}
|
||||
public bool MatchesName (String name)
|
||||
public bool MatchesName(String name)
|
||||
{
|
||||
return (this.Name.EqualsCI(name));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Columns.
|
||||
public bool HasColumnByName (String columnName)
|
||||
public bool HasColumnByName(String columnName)
|
||||
{
|
||||
return (columns != null && columns.Exists(col => col.Name.EqualsCI(columnName)));
|
||||
lock (columns)
|
||||
return (columns != null && columns.Exists(col => col.Name.EqualsCI(columnName)));
|
||||
}
|
||||
public bool HasColumns ()
|
||||
public bool HasColumns()
|
||||
{
|
||||
return (columns != null && columns.Count > 0);
|
||||
lock (columns)
|
||||
return (columns != null && columns.Count > 0);
|
||||
}
|
||||
public List<DbDfnColumn> Columns
|
||||
{
|
||||
get { return new List<DbDfnColumn>(columns); }
|
||||
set { columns.Clear(); columns.AddRange(value); }
|
||||
get
|
||||
{
|
||||
lock (columns)
|
||||
return new List<DbDfnColumn>(columns);
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (columns)
|
||||
columns.Clear(); columns.AddRange(value);
|
||||
}
|
||||
}
|
||||
public void CearColumns ()
|
||||
public void CearColumns()
|
||||
{
|
||||
columns.Clear();
|
||||
lock (columns)
|
||||
columns.Clear();
|
||||
}
|
||||
public void AddColumn (DbDfnColumn column)
|
||||
public void AddColumn(DbDfnColumn column)
|
||||
{
|
||||
columns.Add(column);
|
||||
lock (columns)
|
||||
columns.Add(column);
|
||||
}
|
||||
public List<String> GetPrimaryColumnNames ()
|
||||
public List<String> GetPrimaryColumnNames()
|
||||
{
|
||||
List<String>primaryColumnNames = new List<string>();
|
||||
List<String> primaryColumnNames = new List<string>();
|
||||
// Identify primary index.
|
||||
var index = Indices.GetPrimaryIndex();
|
||||
if (index == null) index = indices.GetClusteredIndex();
|
||||
@@ -82,26 +94,43 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Indices.
|
||||
public bool HasIndexByName (String indexName)
|
||||
public bool HasIndexByName(String indexName)
|
||||
{
|
||||
return (indices != null && indices.Exists(idx => idx.Name.EqualsCI(indexName)));
|
||||
lock (indices)
|
||||
return (indices != null && indices.Exists(idx => idx.Name.EqualsCI(indexName)));
|
||||
}
|
||||
public bool HasIndices()
|
||||
{
|
||||
lock (indices)
|
||||
return (indices != null && indices.Count > 0);
|
||||
}
|
||||
public List<DbDfnIndex> Indices
|
||||
{
|
||||
get { return new List<DbDfnIndex>(indices); }
|
||||
set { indices.Clear(); indices.AddRange(value); }
|
||||
get
|
||||
{
|
||||
lock (indices)
|
||||
return new List<DbDfnIndex>(indices);
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (indices)
|
||||
indices.Clear(); indices.AddRange(value);
|
||||
}
|
||||
}
|
||||
public DbDfnIndex GetIndexByName (String name)
|
||||
public DbDfnIndex GetIndexByName(String name)
|
||||
{
|
||||
return indices.GetIndexByName(name);
|
||||
lock (indices)
|
||||
return indices.GetIndexByName(name);
|
||||
}
|
||||
public void CearIndices ()
|
||||
public void CearIndices()
|
||||
{
|
||||
indices.Clear();
|
||||
lock (indices)
|
||||
indices.Clear();
|
||||
}
|
||||
public void AddIndex (DbDfnIndex Index)
|
||||
public void AddIndex(DbDfnIndex Index)
|
||||
{
|
||||
indices.Add(Index);
|
||||
lock (indices)
|
||||
indices.Add(Index);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
@@ -112,7 +141,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>List of table names.</summary>
|
||||
public static List<String> GetNames (this List<DbDfnTable> tables)
|
||||
public static List<String> GetNames(this List<DbDfnTable> tables)
|
||||
{
|
||||
List<String> names = new List<String>();
|
||||
foreach (DbDfnTable table in tables)
|
||||
@@ -124,7 +153,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Extract the table definition by schema and table name.</summary>
|
||||
public static DbDfnTable GetTableBySchemaName (this List<DbDfnTable> tables, String schema, String name)
|
||||
public static DbDfnTable GetTableBySchemaName(this List<DbDfnTable> tables, String schema, String name)
|
||||
{
|
||||
foreach (DbDfnTable table in tables)
|
||||
{
|
||||
@@ -134,7 +163,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
return null;
|
||||
}
|
||||
/// <summary>Extract the table definition by table name.</summary>
|
||||
public static DbDfnTable GetTableByName (this List<DbDfnTable> tables, String name)
|
||||
public static DbDfnTable GetTableByName(this List<DbDfnTable> tables, String name)
|
||||
{
|
||||
foreach (DbDfnTable table in tables)
|
||||
{
|
||||
@@ -146,7 +175,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>Get total number of columns for all tables.</summary>
|
||||
public static int GetColumnCount (this List<DbDfnTable> tables)
|
||||
public static int GetColumnCount(this List<DbDfnTable> tables)
|
||||
{
|
||||
int columnCount = 0;
|
||||
foreach (DbDfnTable table in tables)
|
||||
|
||||
@@ -144,10 +144,14 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
type = DbColumnDataType.SmallInt;
|
||||
break;
|
||||
//---------------------------------------------------------------
|
||||
case 4: // SQL_INTEGER: // 4 INTEGER Exact numeric value with precision 10 and scale 0 (signed: –2[31] <= n <= 2[31] – 1, unsigned:0 <= n <= 2[32] – 1)[3].
|
||||
case 4: // SQL_INTEGER: // 4 INTEGER Exact numeric value with precision 10 and scale 0 (signed: –2[31] <= n <= 2[31] – 1, unsigned:0 <= n <= 2[32] – 1)[3].
|
||||
type = DbColumnDataType.Int;
|
||||
break;
|
||||
//---------------------------------------------------------------
|
||||
case -5: // SQL_BIGINT: // -5 BIGINT Exact numeric value with precision 19 (if signed) or 20 (if unsigned) and scale 0 (signed: –2[63] <= n <= 2[63] – 1, unsigned:0 <= n <= 2[64] – 1)[3],[9].
|
||||
type = DbColumnDataType.BigInt;
|
||||
break;
|
||||
//---------------------------------------------------------------
|
||||
case 7: // SQL_REAL: // 7 REAL Signed, approximate, numeric value with a binary precision 24 (zero or absolute value 10[–38] to 10[38]).
|
||||
type = DbColumnDataType.Single;
|
||||
break;
|
||||
@@ -175,7 +179,6 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
type = DbColumnDataType.Binary;
|
||||
break;
|
||||
//---------------------------------------------------------------
|
||||
case -5: // SQL_BIGINT: // -5 BIGINT Exact numeric value with precision 19 (if signed) or 20 (if unsigned) and scale 0 (signed: –2[63] <= n <= 2[63] – 1, unsigned:0 <= n <= 2[64] – 1)[3],[9].
|
||||
case 102: // SQL_INTERVAL_MONTH: // 102 INTERVAL MONTH(p) Number of months between two dates; p is the interval leading precision.
|
||||
case 101: // SQL_INTERVAL_YEAR: // 101 INTERVAL YEAR(p) Number of years between two dates; p is the interval leading precision.
|
||||
case 107: // SQL_INTERVAL_YEAR_TO_MONTH: // 107 INTERVAL YEAR(p) TO MONTH Number of years and months between two dates; p is the interval leading precision.
|
||||
@@ -190,7 +193,7 @@ namespace Sarand.Net.Standard.Base.Dbas
|
||||
case 112: // SQL_INTERVAL_HOUR_TO_SECOND: // 112 INTERVAL HOUR(p) TO SECOND(q) Number of hours/minutes/seconds between two date/times; p is the interval leading precision and q is the interval seconds precision.
|
||||
case 113: // SQL_INTERVAL_MINUTE_TO_SECOND: // 113 INTERVAL MINUTE(p) TO SECOND(q) Number of minutes/seconds between two date/times; p is the interval leading precision and q is the interval seconds precision.
|
||||
case -11: // SQL_GUID: // -11 GUID Fixed length Globally Unique Identifier.
|
||||
break;
|
||||
// break;
|
||||
//---------------------------------------------------------------
|
||||
default:
|
||||
SaLogger.Debug("OdbcUtil.OdbcToDataType Unrecognised native data type: " + dataType);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
@@ -282,6 +283,14 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
catch (Exception) { }
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// SysId.
|
||||
public static SysId ToSysId(this String value)
|
||||
{
|
||||
return new SysId(StringUtil.ToLong(value));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Hex values to integer.
|
||||
/// <summary>Convert hex character to integer value.</summary>
|
||||
@@ -312,6 +321,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
}
|
||||
return intValue;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Floating point values.
|
||||
public static float ToSingle (this string value, float defaultValue = 0)
|
||||
@@ -344,6 +354,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
catch (Exception) { }
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Decimal values.
|
||||
public static decimal ToDecimal (this string value, decimal defaultValue = 0)
|
||||
@@ -368,6 +379,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
catch (Exception) { }
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Boolean values.
|
||||
public static bool ToBool (this string value)
|
||||
|
||||
Reference in New Issue
Block a user