Skip to content

Commit 41f9d2b

Browse files
committed
Initial commit
0 parents  commit 41f9d2b

9 files changed

+1113
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin/
2+
obj/
3+
.vs/

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SQLClient")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SQLClient")]
13+
[assembly: AssemblyCopyright("Copyright © 2023")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("4d5b580e-1a19-4bf8-8d08-0d745821ba7b")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

QueryResults.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.SqlClient;
4+
5+
namespace SQLClient
6+
{
7+
public class QueryResults
8+
{
9+
10+
public string[] Headers { get; private set; }
11+
public int[] LongestValues { get; private set; }
12+
public List<string[]> Rows { get; private set; }
13+
14+
public QueryResults(SqlDataReader reader)
15+
{
16+
this.ExtractData(reader);
17+
reader.Close();
18+
}
19+
20+
private void ExtractData(SqlDataReader reader)
21+
{
22+
if (reader == null) throw new Exception("ERROR! Can't print table - reader is null");
23+
if (reader.IsClosed) throw new Exception("ERROR! Can't print table - reader is closed");
24+
if (!reader.HasRows)
25+
{
26+
this.Headers = new string[0];
27+
this.LongestValues = new int[0];
28+
this.Rows = new List<string[]>();
29+
return;
30+
}
31+
32+
// Set up the vars for data extraction
33+
this.Headers = new string[reader.FieldCount];
34+
this.LongestValues = new int[reader.FieldCount];
35+
this.Rows = new List<string[]>();
36+
37+
bool parsedHeaders = false;
38+
39+
// Read the data from the reader
40+
while (reader.Read())
41+
{
42+
if (!parsedHeaders)
43+
{
44+
// Parse the headers
45+
for (int i = 0; i < reader.FieldCount; i++)
46+
{
47+
string header = reader.GetName(i);
48+
this.Headers[i] = header;
49+
this.LongestValues[i] = header.Length;
50+
}
51+
parsedHeaders = true;
52+
}
53+
54+
// Extract each row
55+
string[] row = new string[reader.FieldCount];
56+
for (int i = 0; i < reader.FieldCount; i++)
57+
{
58+
row[i] = reader.GetValue(i).ToString();
59+
if (row[i].Length > this.LongestValues[i]) this.LongestValues[i] = row[i].Length;
60+
}
61+
// Add the row
62+
this.Rows.Add(row);
63+
}
64+
}
65+
66+
}
67+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SQLClient
2+
A C# console utility for interacting with MSSQL servers

SQLClient.cs

Lines changed: 889 additions & 0 deletions
Large diffs are not rendered by default.

SQLClient.csproj

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>SQLClient</RootNamespace>
10+
<AssemblyName>SQLClient</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
36+
<DebugSymbols>true</DebugSymbols>
37+
<OutputPath>bin\x64\Debug\</OutputPath>
38+
<DefineConstants>DEBUG;TRACE</DefineConstants>
39+
<DebugType>full</DebugType>
40+
<PlatformTarget>x64</PlatformTarget>
41+
<LangVersion>7.3</LangVersion>
42+
<ErrorReport>prompt</ErrorReport>
43+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
44+
<Prefer32Bit>true</Prefer32Bit>
45+
</PropertyGroup>
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
47+
<OutputPath>bin\x64\Release\</OutputPath>
48+
<DefineConstants>TRACE</DefineConstants>
49+
<Optimize>true</Optimize>
50+
<DebugType>pdbonly</DebugType>
51+
<PlatformTarget>x64</PlatformTarget>
52+
<LangVersion>7.3</LangVersion>
53+
<ErrorReport>prompt</ErrorReport>
54+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
55+
<Prefer32Bit>true</Prefer32Bit>
56+
</PropertyGroup>
57+
<ItemGroup>
58+
<Reference Include="System" />
59+
<Reference Include="System.Configuration.Install" />
60+
<Reference Include="System.Core" />
61+
<Reference Include="System.Xml.Linq" />
62+
<Reference Include="System.Data.DataSetExtensions" />
63+
<Reference Include="Microsoft.CSharp" />
64+
<Reference Include="System.Data" />
65+
<Reference Include="System.Net.Http" />
66+
<Reference Include="System.Xml" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<Compile Include="QueryResults.cs" />
70+
<Compile Include="SQLClient.cs" />
71+
<Compile Include="Properties\AssemblyInfo.cs" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<None Include="App.config" />
75+
</ItemGroup>
76+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77+
</Project>

SQLClient.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.34407.143
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SQLClient", "SQLClient.csproj", "{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Release|Any CPU = Release|Any CPU
13+
Release|x64 = Release|x64
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Debug|x64.ActiveCfg = Debug|x64
19+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Debug|x64.Build.0 = Debug|x64
20+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Release|x64.ActiveCfg = Release|x64
23+
{4D5B580E-1A19-4BF8-8D08-0D745821BA7B}.Release|x64.Build.0 = Release|x64
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {96D86483-CF42-42F2-8306-88D0849D317B}
30+
EndGlobalSection
31+
EndGlobal

0 commit comments

Comments
 (0)