Skip to content

Commit cccf5ee

Browse files
FransBoumacincuranet
authored andcommitted
Changes for DNET-784: schema update for identity (#7)
1 parent 7607beb commit cccf5ee

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/Schema/FbColumns.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ protected override StringBuilder GetCommandText(string[] restrictions)
6464
null AS COLLATION_CATALOG,
6565
null AS COLLATION_SCHEMA,
6666
coll.rdb$collation_name AS COLLATION_NAME,
67-
rfr.rdb$description AS DESCRIPTION
67+
rfr.rdb$description AS DESCRIPTION");
68+
if (MajorVersionNumber >= 3)
69+
{
70+
sql.Append(@",
71+
rfr.rdb$identity_type as IDENTITY_TYPE");
72+
}
73+
sql.Append(@"
6874
FROM rdb$relation_fields rfr
6975
LEFT JOIN rdb$fields fld ON rfr.rdb$field_source = fld.rdb$field_name
7076
LEFT JOIN rdb$character_sets cs ON cs.rdb$character_set_id = fld.rdb$character_set_id
@@ -117,6 +123,10 @@ protected override DataTable ProcessResult(DataTable schema)
117123
schema.BeginLoadData();
118124
schema.Columns.Add("IS_NULLABLE", typeof(bool));
119125
schema.Columns.Add("IS_ARRAY", typeof(bool));
126+
if (MajorVersionNumber >= 3)
127+
{
128+
schema.Columns.Add("IS_IDENTITY", typeof(bool));
129+
}
120130

121131
foreach (DataRow row in schema.Rows)
122132
{
@@ -175,6 +185,11 @@ protected override DataTable ProcessResult(DataTable schema)
175185
{
176186
row["DOMAIN_NAME"] = null;
177187
}
188+
189+
if (MajorVersionNumber >= 3)
190+
{
191+
row["IS_IDENTITY"] = (row["IDENTITY_TYPE"] != DBNull.Value);
192+
}
178193
}
179194

180195
schema.EndLoadData();
@@ -185,6 +200,10 @@ protected override DataTable ProcessResult(DataTable schema)
185200
schema.Columns.Remove("COLUMN_ARRAY");
186201
schema.Columns.Remove("FIELD_TYPE");
187202
schema.Columns.Remove("CHARACTER_MAX_LENGTH");
203+
if (MajorVersionNumber >= 3)
204+
{
205+
schema.Columns.Remove("IDENTITY_TYPE");
206+
}
188207

189208
return schema;
190209
}

Provider/src/FirebirdSql.Data.FirebirdClient/Schema/FbSchema.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,14 @@
2424

2525
using FirebirdSql.Data.FirebirdClient;
2626
using FirebirdSql.Data.Common;
27+
using FirebirdSql.Data.Services;
2728

2829
namespace FirebirdSql.Data.Schema
2930
{
3031
#warning New datatypes
3132

3233
internal abstract class FbSchema
3334
{
34-
#region Constructors
35-
36-
public FbSchema()
37-
{
38-
}
39-
40-
#endregion
41-
4235
#region Abstract Methods
4336

4437
protected abstract StringBuilder GetCommandText(string[] restrictions);
@@ -74,6 +67,7 @@ public DataTable GetSchema(FbConnection connection, string collectionName, strin
7467

7568
protected FbCommand BuildCommand(FbConnection connection, string collectionName, string[] restrictions)
7669
{
70+
SetMajorVersionNumber(connection);
7771
var filter = string.Format("CollectionName='{0}'", collectionName);
7872
var builder = GetCommandText(restrictions);
7973
var restriction = connection.GetSchema(DbMetaDataCollectionNames.Restrictions).Select(filter);
@@ -103,6 +97,7 @@ protected FbCommand BuildCommand(FbConnection connection, string collectionName,
10397
return command;
10498
}
10599

100+
106101
protected virtual DataTable ProcessResult(DataTable schema)
107102
{
108103
return schema;
@@ -115,6 +110,19 @@ protected virtual string[] ParseRestrictions(string[] restrictions)
115110

116111
#endregion
117112

113+
#region Private Methods
114+
/// <summary>
115+
/// Determines the major version number from the Serverversion on the inner connection.
116+
/// </summary>
117+
/// <param name="connection">an open connection, which is used to determine the version number of the connected database server</param>
118+
private void SetMajorVersionNumber(FbConnection connection)
119+
{
120+
var serverVersion = FbServerProperties.ParseServerVersion(connection.ServerVersion);
121+
MajorVersionNumber = serverVersion.Major;
122+
}
123+
#endregion
124+
125+
118126
#region Private Static Methods
119127

120128
private static void TrimStringFields(DataTable schema)
@@ -138,5 +146,12 @@ private static void TrimStringFields(DataTable schema)
138146
}
139147

140148
#endregion
149+
150+
#region Properties
151+
/// <summary>
152+
/// The major version of the connected Firebird server
153+
/// </summary>
154+
protected int MajorVersionNumber { get; private set; }
155+
#endregion
141156
}
142157
}

0 commit comments

Comments
 (0)