<commit_before>﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

namespace SQLCover.Gateway
{
    public class DatabaseGateway
    {
        private readonly string _connectionString;
        private readonly string _databaseName;
        private readonly SqlConnectionStringBuilder _connectionStringBuilder;
        public string DataSource { get { return _connectionStringBuilder.DataSource; } }

        public DatabaseGateway()
        {
            //for mocking.
        }
        public DatabaseGateway(string connectionString, string databaseName)
        {
            _connectionString = connectionString;
            _databaseName = databaseName;
            _connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);
        }
        
        public virtual string GetString(string query)
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                conn.ChangeDatabase(_databaseName);
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = query;
                    return cmd.ExecuteScalar().ToString();
                }
            }
        }

        public virtual DataTable GetRecords(string query)
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                conn.ChangeDatabase(_databaseName);
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = query;
                    using (var reader = cmd.ExecuteReader())
                    {
                        var ds = new DataTable();
                        ds.Load(reader);
                        return ds;
                    }
                }
            }<commit_msg>Checking if the query for compatibility_level returns null on GetVersion (#33)<commit_after>﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

namespace SQLCover.Gateway
{
    public class DatabaseGateway
    {
        private readonly string _connectionString;
        private readonly string _databaseName;
        private readonly SqlConnectionStringBuilder _connectionStringBuilder;
        public string DataSource { get { return _connectionStringBuilder.DataSource; } }

        public DatabaseGateway()
        {
            //for mocking.
        }
        public DatabaseGateway(string connectionString, string databaseName)
        {
            _connectionString = connectionString;
            _databaseName = databaseName;
            _connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);
        }
        
        public virtual string GetString(string query)
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                conn.ChangeDatabase(_databaseName);
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = query;

                    var scalarResult = cmd.ExecuteScalar();

                    if (scalarResult != null) return scalarResult.ToString();

                    return null;
                }
            }
        }

        public virtual DataTable GetRecords(string query)
        {
            using (var conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                conn.ChangeDatabase(_databaseName);
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = query;
                    using (var reader = cmd.ExecuteReader())
                    {
                        var ds = new DataTable();
                        ds.Load(reader);
                        return ds;
                    }
                }
            }
{'fraction_non_alphanumeric': 0.06741573033707865, 'fraction_numerical': 0.0005107252298263534, 'mean_word_length': 1.466624685138539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5403', 'n_tokens_mistral': 857, 'n_tokens_neox': 809, 'n_words': 210}