• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 6237307473

19 Sep 2023 04:02PM UTC coverage: 57.015% (-0.4%) from 57.44%
6237307473

push

github

web-flow
Feature/rc4 (#1570)

* Syntax tidying
* Dependency updates
* Event handling singletons (ThrowImmediately and co)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: James A Sutherland <>
Co-authored-by: James Friel <jfriel001@dundee.ac.uk>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

10734 of 20259 branches covered (0.0%)

Branch coverage included in aggregate %.

5922 of 5922 new or added lines in 565 files covered. (100.0%)

30687 of 52390 relevant lines covered (58.57%)

7361.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Rdmp.Core/DataViewing/ArbitraryTableExtractionUICollection.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using FAnsi;
10
using FAnsi.Discovery;
11
using FAnsi.Discovery.QuerySyntax;
12
using Rdmp.Core.Curation.Data;
13
using Rdmp.Core.Curation.Data.Dashboarding;
14
using Rdmp.Core.ReusableLibraryCode.DataAccess;
15

16
namespace Rdmp.Core.DataViewing;
17

18
/// <summary>
19
/// <see cref="IViewSQLAndResultsCollection"/> for querying samples of arbitrary tables / columns
20
/// </summary>
21
public class ArbitraryTableExtractionUICollection : PersistableObjectCollection, IViewSQLAndResultsCollection,
22
    IDataAccessPoint, IDataAccessCredentials
23
{
24
    private DiscoveredTable _table;
25

26
    public DatabaseType DatabaseType { get; set; }
×
27

28
    private Dictionary<string, string> _arguments = new();
×
29
    private const string DatabaseKey = "Database";
30
    private const string ServerKey = "Server";
31
    private const string TableKey = "Table";
32
    private const string DatabaseTypeKey = "DatabaseType";
33

34
    public string Username { get; set; }
×
35
    public string Password { get; set; }
×
36
    public string GetDecryptedPassword() => Password ?? "";
×
37

38
    public string OverrideSql { get; set; }
×
39

40
    /// <summary>
41
    /// Needed for deserialization
42
    /// </summary>
43
    public ArbitraryTableExtractionUICollection()
×
44
    {
45
    }
×
46

47
    public ArbitraryTableExtractionUICollection(DiscoveredTable table) : this()
×
48
    {
49
        _table = table;
×
50
        _arguments.Add(ServerKey, _table.Database.Server.Name);
×
51
        _arguments.Add(DatabaseKey, _table.Database.GetRuntimeName());
×
52
        _arguments.Add(TableKey, _table.GetRuntimeName());
×
53
        DatabaseType = table.Database.Server.DatabaseType;
×
54

55
        _arguments.Add(DatabaseTypeKey, DatabaseType.ToString());
×
56

57

58
        Username = table.Database.Server.ExplicitUsernameIfAny;
×
59
        Password = table.Database.Server.ExplicitPasswordIfAny;
×
60
    }
×
61

62
    /// <nheritdoc/>
63
    public override string SaveExtraText() => PersistStringHelper.SaveDictionaryToString(_arguments);
×
64

65
    public override void LoadExtraText(string s)
66
    {
67
        _arguments = PersistStringHelper.LoadDictionaryFromString(s);
×
68

69
        DatabaseType = (DatabaseType)Enum.Parse(typeof(DatabaseType), _arguments[DatabaseTypeKey]);
×
70

71
        var server = new DiscoveredServer(Server, Database, DatabaseType, null, null);
×
72
        _table = server.ExpectDatabase(Database).ExpectTable(_arguments[TableKey]);
×
73
    }
×
74

75
    public IEnumerable<DatabaseEntity> GetToolStripObjects()
76
    {
77
        yield break;
×
78
    }
79

80
    public IDataAccessPoint GetDataAccessPoint() => this;
×
81

82
    public string GetSql()
83
    {
84
        if (!string.IsNullOrWhiteSpace(OverrideSql))
×
85
            return OverrideSql;
×
86

87
        var response = _table.GetQuerySyntaxHelper().HowDoWeAchieveTopX(100);
×
88

89
        return response.Location switch
×
90
        {
×
91
            QueryComponent.SELECT => $"Select {response.SQL} * from {_table.GetFullyQualifiedName()}",
×
92
            QueryComponent.WHERE => $"Select * from {_table.GetFullyQualifiedName()} WHERE {response.SQL}",
×
93
            QueryComponent.Postfix => $"Select * from {_table.GetFullyQualifiedName()} {response.SQL}",
×
94
            _ => throw new ArgumentOutOfRangeException()
×
95
        };
×
96
    }
97

98
    public string GetTabName() => $"View {_table.GetRuntimeName()}";
×
99

100
    public void AdjustAutocomplete(IAutoCompleteProvider autoComplete)
101
    {
102
        autoComplete.Add(_table);
×
103
    }
×
104

105
    public string Server
106
    {
107
        get => _arguments[ServerKey];
×
108
        set => _arguments[ServerKey] = value;
×
109
    }
110

111
    public string Database
112
    {
113
        get => _arguments[DatabaseKey];
×
114
        set => _arguments[DatabaseKey] = value;
×
115
    }
116

117

118
    public IDataAccessCredentials GetCredentialsIfExists(DataAccessContext context) =>
119
        //we have our own credentials if we do
120
        string.IsNullOrWhiteSpace(Username) ? null : this;
×
121

122
    public IQuerySyntaxHelper GetQuerySyntaxHelper() => _table.GetQuerySyntaxHelper();
×
123

124
    public bool DiscoverExistence(DataAccessContext context, out string reason)
125
    {
126
        if (_table.Exists())
×
127
        {
128
            reason = null;
×
129
            return true;
×
130
        }
131

132
        reason = $"Table {_table} did not exist";
×
133
        return false;
×
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc