Skip to content

Commit

Permalink
Fixes issue #84
Browse files Browse the repository at this point in the history
Found that DbDataReader.GetDataTypeName returns a lenght specifier on
some database (e.g. Postgres 9.6), this breaks things so we remove it.
  • Loading branch information
d4nt committed Oct 13, 2019
1 parent c9dd4bf commit cb9bb21
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Web/Managers/DbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Extensions.Caching.Memory;
using QueryTree.Enums;
using QueryTree.ViewModels;
using System.Text.RegularExpressions;


namespace QueryTree.Managers
Expand Down Expand Up @@ -648,6 +649,14 @@ public static DbCommand CreateCommand(DatabaseType type, DbConnection conn, stri
return cmd;
}

// Sometimes DbDataReader.GetDataTypeName returns a length specifier, which isn't useful
// to QueryTree, is different to the GetDbModel data and breaks things. This removes it
private string RemoveLengthSpecifier(string databaseType)
{
var re = new Regex("\\([0-9]*\\)$");
return re.Replace(databaseType, "");
}

public QueryResponse GetData(DatabaseConnection connection, string nodes, string nodeId, int? startRow, int? rowCount)
{
var data = new QueryResponse() { Status = "ok" };
Expand All @@ -671,7 +680,7 @@ public QueryResponse GetData(DatabaseConnection connection, string nodes, string
for (int i = 0; i < reader.FieldCount; i++)
{
data.Columns.Add(reader.GetName(i));
data.ColumnTypes.Add(reader.GetDataTypeName(i));
data.ColumnTypes.Add(RemoveLengthSpecifier(reader.GetDataTypeName(i)));
}

while (reader.Read())
Expand Down

0 comments on commit cb9bb21

Please sign in to comment.