Rearrange some files, add SqlReadData
This commit is contained in:
parent
0b3c5df2b8
commit
d76a389b9e
@ -1,4 +1,7 @@
|
|||||||
namespace TeamHobby.HobbyProjectGenerator.Archive
|
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||||
{
|
{
|
||||||
public class ArchiveController
|
public class ArchiveController
|
||||||
{
|
{
|
||||||
|
|||||||
@ -13,4 +13,12 @@
|
|||||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Implementations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
|
{
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,8 +4,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
//namespace TeamHobby.HobbyProjectGenerator.Archive.Contracts
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.Archive
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
{
|
{
|
||||||
public interface IDataSource<T>
|
public interface IDataSource<T>
|
||||||
{
|
{
|
||||||
@ -6,34 +6,41 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
|
||||||
|
namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
||||||
namespace TeamHobby.HobbyProjectGenerator.Archive
|
|
||||||
{
|
{
|
||||||
public class SQLSource : IDataSource<string>
|
public class SqlDAO : IDataSource<string>
|
||||||
{
|
{
|
||||||
//private SqlConnection conn;
|
private OdbcConnection _conn;
|
||||||
|
|
||||||
//public SQLSource(string info)
|
public SqlDAO(string info)
|
||||||
//{
|
{
|
||||||
// // Do I put using here to make sure the connection closed once the object is gone?
|
try {
|
||||||
// conn = new SqlConnection(info);
|
Console.WriteLine("Establising Connection");
|
||||||
// // Perhaps open the connection here?
|
_conn = new OdbcConnection(info);
|
||||||
// // conn.Open();
|
Console.WriteLine("Connection established");
|
||||||
//}
|
}
|
||||||
|
catch {
|
||||||
|
//conn = null;
|
||||||
|
Console.WriteLine("Error when creating a connection");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter and setter for Odbc
|
||||||
|
public OdbcConnection Connection { get; set; }
|
||||||
|
|
||||||
// Makre sure to Check for instanceof() before casting to a SQLReader in the controller
|
// Makre sure to Check for instanceof() before casting to a SQLReader in the controller
|
||||||
public Object ReadData(string cmd)
|
public Object? ReadData(string cmd)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//conn.Open();
|
_conn.Open();
|
||||||
//SqlCommand command = new SqlCommand(null, conn);
|
OdbcCommand command = new OdbcCommand(cmd, _conn);
|
||||||
//SqlCommand command = new SqlCommand(cmd, conn);
|
|
||||||
|
|
||||||
// conn.Execute();
|
OdbcDataReader reader = command.ExecuteReader();
|
||||||
Console.WriteLine("Access a SQL database");
|
|
||||||
Console.WriteLine("Select * from archive");
|
|
||||||
|
|
||||||
// Execute the command to query the data
|
// Execute the command to query the data
|
||||||
//using SqlDataReader sqlReader = command.ExecuteReader();
|
//using SqlDataReader sqlReader = command.ExecuteReader();
|
||||||
@ -43,7 +50,7 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
|||||||
//conn.Close();
|
//conn.Close();
|
||||||
//conn.Dispose();
|
//conn.Dispose();
|
||||||
//return sqlReader;
|
//return sqlReader;
|
||||||
return new SqlConnection();
|
return reader;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TeamHobby.HobbyProjectGenerator.Archive;
|
using TeamHobby.HobbyProjectGenerator.Archive;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.Archive
|
namespace TeamHobby.HobbyProjectGenerator.Archive
|
||||||
{
|
{
|
||||||
@ -16,7 +17,7 @@ namespace TeamHobby.HobbyProjectGenerator.Archive
|
|||||||
{
|
{
|
||||||
if (String.Equals(name, "SQL", StringComparison.OrdinalIgnoreCase))
|
if (String.Equals(name, "SQL", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return new SQLSource();
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Data.Odbc" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.UserManagement.Tests", "..\TeamHobby.UserManagement.Tests\TeamHobby.UserManagement.Tests.csproj", "{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.DAL", "..\TeamHobby.HobbyProjectGenerator.DAL\TeamHobby.HobbyProjectGenerator.DAL.csproj", "{DCB0E160-1F6D-406E-8633-489CD564479B}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGenerator.Models", "..\TeamHobby.HobbyProjectGenerator.Models\TeamHobby.HobbyProjectGenerator.Models.csproj", "{75DED6C2-D404-4E71-A58B-0F616DB5C062}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "main", "..\main\main.csproj", "{30C7EBF3-3957-46E5-86C1-C13356841ECA}"
|
||||||
@ -17,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.HobbyProjectGener
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamHobby.Main", "..\TeamHobby.Main\TeamHobby.Main.csproj", "{ED126EFB-B337-42F9-BE4B-65A5AE90503B}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamHobby.HobbyProjectGenerator.DataAccess", "..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj", "{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -29,9 +29,6 @@ Global
|
|||||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5C5A44B4-EC3C-44F2-8F39-F917F8ED932F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{DCB0E160-1F6D-406E-8633-489CD564479B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{DCB0E160-1F6D-406E-8633-489CD564479B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{DCB0E160-1F6D-406E-8633-489CD564479B}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU
|
{75DED6C2-D404-4E71-A58B-0F616DB5C062}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
@ -47,6 +44,10 @@ Global
|
|||||||
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{ED126EFB-B337-42F9-BE4B-65A5AE90503B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AA48A66C-FA36-4AF9-A782-CEC22838EB8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class HobbyMain
|
|||||||
|
|
||||||
string connString = "user id=root;" + "password=Teamhobby;server=localhost;" + "Trusted_Connection=yes;" + "database=Alatreon; " + "connection timeout=5";
|
string connString = "user id=root;" + "password=Teamhobby;server=localhost;" + "Trusted_Connection=yes;" + "database=Alatreon; " + "connection timeout=5";
|
||||||
string connMariaDB = "server=localhost;port=3306;uid=root;pwd=Teamhobby;connection timeout=5";
|
string connMariaDB = "server=localhost;port=3306;uid=root;pwd=Teamhobby;connection timeout=5";
|
||||||
var conn = new SqlConnection(connString);
|
//var conn = new SqlConnection(connString);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
Source Code/TeamHobby/Class1.cs
Normal file
7
Source Code/TeamHobby/Class1.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace TeamHobby
|
||||||
|
{
|
||||||
|
public class Class1
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Source Code/TeamHobby/TeamHobby.csproj
Normal file
9
Source Code/TeamHobby/TeamHobby.csproj
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,5 +1,7 @@
|
|||||||
using main;
|
using main;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Data.Odbc;
|
||||||
|
using TeamHobby.HobbyProjectGenerator.DataAccess;
|
||||||
|
|
||||||
|
|
||||||
namespace TeamHobby.HobbyProjectGenerator.Main
|
namespace TeamHobby.HobbyProjectGenerator.Main
|
||||||
@ -31,6 +33,39 @@ namespace TeamHobby.HobbyProjectGenerator.Main
|
|||||||
|
|
||||||
Console.WriteLine(value: $"username is {username}\npassword is {password}");
|
Console.WriteLine(value: $"username is {username}\npassword is {password}");
|
||||||
|
|
||||||
|
// Testing Data Access Layer
|
||||||
|
string dbInfo = "DRIVER={MariaDB ODBC 3.1 Driver};" +
|
||||||
|
"SERVER=localhost;" +
|
||||||
|
"DATABASE=hobby;" +
|
||||||
|
"UID=root;" +
|
||||||
|
"PASSWORD=Teamhobby;" +
|
||||||
|
"OPTION=3";
|
||||||
|
IDataSource<string> datasource = new SqlDAO(dbInfo);
|
||||||
|
|
||||||
|
string sqlQuery = "Select * from log;";
|
||||||
|
Object result = datasource.ReadData(sqlQuery);
|
||||||
|
Console.WriteLine("type of Result: " + result.GetType());
|
||||||
|
OdbcDataReader reader = null;
|
||||||
|
|
||||||
|
if (result.GetType() == typeof(OdbcDataReader))
|
||||||
|
{
|
||||||
|
reader = (OdbcDataReader)result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Reading from the database");
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
Console.WriteLine("Date={0} {1} {2} {3} {4} {5}", reader[0], reader[1], reader[2], reader[3], reader[4], reader[5]);
|
||||||
|
//Console.WriteLine("Col A: {0} ", reader[0]);
|
||||||
|
//Console.WriteLine("Column: " + reader.FieldCount);
|
||||||
|
//Console.WriteLine("Column={1}", reader[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ExampleDAO z = new ExampleDAO();
|
/* ExampleDAO z = new ExampleDAO();
|
||||||
z.UserData("Tomato");
|
z.UserData("Tomato");
|
||||||
Console.Read();*/
|
Console.Read();*/
|
||||||
|
|||||||
@ -11,4 +11,8 @@
|
|||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TeamHobby.HobbyProjectGenerator.DataAccess\TeamHobby.HobbyProjectGenerator.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user