Skip to content

Commit cb9bb21

Browse files
committed
Fixes issue #84
Found that DbDataReader.GetDataTypeName returns a lenght specifier on some database (e.g. Postgres 9.6), this breaks things so we remove it.
1 parent c9dd4bf commit cb9bb21

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Web/Managers/DbManager.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.Extensions.Caching.Memory;
1313
using QueryTree.Enums;
1414
using QueryTree.ViewModels;
15+
using System.Text.RegularExpressions;
1516

1617

1718
namespace QueryTree.Managers
@@ -648,6 +649,14 @@ public static DbCommand CreateCommand(DatabaseType type, DbConnection conn, stri
648649
return cmd;
649650
}
650651

652+
// Sometimes DbDataReader.GetDataTypeName returns a length specifier, which isn't useful
653+
// to QueryTree, is different to the GetDbModel data and breaks things. This removes it
654+
private string RemoveLengthSpecifier(string databaseType)
655+
{
656+
var re = new Regex("\\([0-9]*\\)$");
657+
return re.Replace(databaseType, "");
658+
}
659+
651660
public QueryResponse GetData(DatabaseConnection connection, string nodes, string nodeId, int? startRow, int? rowCount)
652661
{
653662
var data = new QueryResponse() { Status = "ok" };
@@ -671,7 +680,7 @@ public QueryResponse GetData(DatabaseConnection connection, string nodes, string
671680
for (int i = 0; i < reader.FieldCount; i++)
672681
{
673682
data.Columns.Add(reader.GetName(i));
674-
data.ColumnTypes.Add(reader.GetDataTypeName(i));
683+
data.ColumnTypes.Add(RemoveLengthSpecifier(reader.GetDataTypeName(i)));
675684
}
676685

677686
while (reader.Read())

0 commit comments

Comments
 (0)