feat: team4 added select author and publisher
This commit is contained in:
parent
335e464055
commit
4a7491756a
70
src/team4.cs
70
src/team4.cs
@ -250,6 +250,76 @@ namespace Team4
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public static List<Dictionary<int, string[]>> GetAuthorNameId(SqliteConnection conn)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var command = conn.CreateCommand())
|
||||
{
|
||||
command.CommandText = @"
|
||||
SELECT author.ID, author.Name, author.Surname
|
||||
FROM Authors author";
|
||||
|
||||
var authors = new List<Dictionary<int, string[]>>();
|
||||
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
int id = reader.GetInt32(0);
|
||||
string name = reader.IsDBNull(1) ? "" : reader.GetString(1);
|
||||
string surname = reader.IsDBNull(2) ? "" : reader.GetString(2);
|
||||
|
||||
authors.Add(new Dictionary<int, string[]>
|
||||
{
|
||||
{ id, new[] { name, surname } }
|
||||
});
|
||||
}
|
||||
}
|
||||
return authors;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error in GetAuthorNameId: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Dictionary<int, string>> GetPublisherNameId(SqliteConnection conn)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var command = conn.CreateCommand())
|
||||
{
|
||||
command.CommandText = @"
|
||||
SELECT publisher.ID, publisher.Name
|
||||
FROM Publisher publisher";
|
||||
|
||||
var publishers = new List<Dictionary<int, string>>();
|
||||
|
||||
using (var reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
int id = reader.GetInt32(0);
|
||||
string name = reader.IsDBNull(1) ? "" : reader.GetString(1);
|
||||
|
||||
publishers.Add(new Dictionary<int, string>
|
||||
{
|
||||
{ id, name }
|
||||
});
|
||||
}
|
||||
}
|
||||
return publishers;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error in GetAuthorNameId: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetBooksBy(SqliteConnection conn)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user