Skip to content

Commit c2fab55

Browse files
committed
Firebird improvements
Correct datetime forman string and column default value extraction fix
1 parent 3c6f503 commit c2fab55

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2011-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Csaba Beer
55
// Created: 2011.01.08
66

@@ -12,6 +12,7 @@ internal static class Constants
1212
{
1313
public const string DefaultSchemaName = ""; // "Firebird";
1414

15-
public const string DateTimeFormatString = @"''\'yyyy\.MM\.dd HH\:mm\:ss\:FFF\'''";
15+
// cannot use "FFF" cause it may lead to empty string for fractions part.
16+
public const string DateTimeFormatString = @"''\'yyyy\.MM\.dd HH\:mm\:ss\.fff\'''";
1617
}
1718
}

Orm/Xtensive.Orm.Firebird/Sql.Drivers.Firebird/v2_5/Extractor.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2011-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Csaba Beer
55
// Created: 2011.01.13
66

@@ -84,11 +84,10 @@ private void ExtractTables()
8484

8585
private void ExtractTableColumns()
8686
{
87-
using (
88-
var reader = Connection.CreateCommand(GetExtractTableColumnsQuery()).ExecuteReader(CommandBehavior.SingleResult)
89-
) {
87+
using (var command = Connection.CreateCommand(GetExtractTableColumnsQuery()))
88+
using (var reader = command.ExecuteReader(CommandBehavior.SingleResult)) {
9089
Table table = null;
91-
int lastColumnId = int.MaxValue;
90+
var lastColumnId = int.MaxValue;
9291
while (reader.Read()) {
9392
int columnSeq = reader.GetInt16(2);
9493
if (columnSeq <= lastColumnId) {
@@ -99,8 +98,16 @@ private void ExtractTableColumns()
9998
column.DataType = CreateValueType(reader, 4, 5, 7, 8, 9);
10099
column.IsNullable = ReadBool(reader, 10);
101100
var defaultValue = ReadStringOrNull(reader, 11);
102-
if (!string.IsNullOrEmpty(defaultValue))
103-
column.DefaultValue = SqlDml.Native(defaultValue);
101+
if (!string.IsNullOrEmpty(defaultValue)) {
102+
defaultValue = defaultValue.TrimStart(' ');
103+
if (defaultValue.StartsWith("DEFAULT", StringComparison.OrdinalIgnoreCase)) {
104+
defaultValue = defaultValue.Substring(7).TrimStart(' ');
105+
}
106+
if (!string.IsNullOrEmpty(defaultValue)) {
107+
column.DefaultValue = SqlDml.Native(defaultValue);
108+
}
109+
}
110+
104111
lastColumnId = columnSeq;
105112
}
106113
}

0 commit comments

Comments
 (0)