-
Notifications
You must be signed in to change notification settings - Fork 934
DB2 dialect enhancements #2058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
DB2 dialect enhancements #2058
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e08bcd7
Add schema update capability
hazzik 74904ff
Fix generating parameter names
hazzik 3b0f904
Register bit operations
hazzik 661cd0f
Fix substring function registration
hazzik a634fe6
Fix current_timestamp function registration
hazzik 6b780b3
Fix round function registration
hazzik 8675d2d
Fix Timestamp resolution in ticks
hazzik ab0148f
Fix DbType.Guid type registration
hazzik 3edcb5d
Fix DbType.Byte handling
hazzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Common; | ||
|
||
namespace NHibernate.Dialect.Schema | ||
{ | ||
public class DB2MetaData : AbstractDataBaseSchema | ||
{ | ||
public DB2MetaData(DbConnection connection) : base(connection) | ||
{ | ||
} | ||
|
||
public override ITableMetadata GetTableMetadata(DataRow rs, bool extras) | ||
{ | ||
return new DB2TableMetaData(rs, this, extras); | ||
} | ||
|
||
public override DataTable GetIndexColumns(string catalog, string schemaPattern, string tableName, string indexName) | ||
{ | ||
var restrictions = new[] {tableName, indexName}; | ||
return Connection.GetSchema("Indexes", restrictions); | ||
} | ||
|
||
public override ISet<string> GetReservedWords() | ||
{ | ||
var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
var dtReservedWords = Connection.GetSchema(DbMetaDataCollectionNames.ReservedWords); | ||
foreach (DataRow row in dtReservedWords.Rows) | ||
{ | ||
result.Add(row["ReservedWord"].ToString()); | ||
} | ||
|
||
if (IncludeDataTypesInReservedWords) | ||
{ | ||
var dtTypes = Connection.GetSchema(DbMetaDataCollectionNames.DataTypes); | ||
foreach (DataRow row in dtTypes.Rows) | ||
{ | ||
result.Add(row["SQL_TYPE_NAME"].ToString()); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
public class DB2TableMetaData : AbstractTableMetadata | ||
{ | ||
public DB2TableMetaData(DataRow rs, IDataBaseSchema meta, bool extras) : base(rs, meta, extras) | ||
{ | ||
} | ||
|
||
protected override IColumnMetadata GetColumnMetadata(DataRow rs) | ||
{ | ||
return new DB2ColumnMetaData(rs); | ||
} | ||
|
||
protected override string GetColumnName(DataRow rs) | ||
{ | ||
return Convert.ToString(rs["COLUMN_NAME"]); | ||
} | ||
|
||
protected override string GetConstraintName(DataRow rs) | ||
{ | ||
return Convert.ToString(rs["FK_NAME"]); | ||
} | ||
|
||
protected override IForeignKeyMetadata GetForeignKeyMetadata(DataRow rs) | ||
{ | ||
return new DB2ForeignKeyMetaData(rs); | ||
} | ||
|
||
protected override IIndexMetadata GetIndexMetadata(DataRow rs) | ||
{ | ||
return new DB2IndexMetaData(rs); | ||
} | ||
|
||
protected override string GetIndexName(DataRow rs) | ||
{ | ||
return Convert.ToString(rs["INDEX_NAME"]); | ||
} | ||
|
||
protected override void ParseTableInfo(DataRow rs) | ||
{ | ||
Catalog = Convert.ToString(rs["TABLE_CATALOG"]); | ||
Schema = Convert.ToString(rs["TABLE_SCHEMA"]); | ||
if (string.IsNullOrEmpty(Catalog)) Catalog = null; | ||
if (string.IsNullOrEmpty(Schema)) Schema = null; | ||
Name = Convert.ToString(rs["TABLE_NAME"]); | ||
} | ||
} | ||
|
||
public class DB2ColumnMetaData : AbstractColumnMetaData | ||
{ | ||
public DB2ColumnMetaData(DataRow rs) : base(rs) | ||
{ | ||
Name = Convert.ToString(rs["COLUMN_NAME"]); | ||
Nullable = Convert.ToString(rs["IS_NULLABLE"]); | ||
TypeName = Convert.ToString(rs["DATA_TYPE_NAME"]); | ||
} | ||
} | ||
|
||
public class DB2IndexMetaData : AbstractIndexMetadata | ||
{ | ||
public DB2IndexMetaData(DataRow rs) : base(rs) | ||
{ | ||
Name = Convert.ToString(rs["INDEX_NAME"]); | ||
} | ||
} | ||
|
||
public class DB2ForeignKeyMetaData : AbstractForeignKeyMetadata | ||
{ | ||
public DB2ForeignKeyMetaData(DataRow rs) : base(rs) | ||
{ | ||
Name = Convert.ToString(rs["FK_NAME"]); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DB2 does not support byte native (as many other RDBMS) and has a problem handling it. If the value is of type
byte
the provider remaps the parameter asDbType.Binary
. Then it throwsInvalidCastException
trying to cast the value tobyte[]
.