64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
|
|
using EonaCat.Json.Linq;
|
|
using EonaCat.Sql.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace EonaCat.Sql
|
|
{
|
|
public static class SqlTest
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
SqlHelper.IsWebSafe("SELECT * FROM alert('x');", out string errors);
|
|
var test = new EonaCat.Logger.Managers.LogManager();
|
|
test.Write("test", EonaCat.Logger.ELogType.ERROR);
|
|
Console.WriteLine(errors);
|
|
|
|
TestsqlServer();
|
|
}
|
|
|
|
private static async void TestsqlServer()
|
|
{
|
|
var customerId = 2;
|
|
var result = SqlHelper.ExecuteQuery(
|
|
@"Server=EONACATLAPTOP\SQLEXPRESS;Database=AdventureWorks2019;User Id=sa;Password=jeroen;TrustServerCertificate=Yes;",
|
|
$"SELECT * FROM Person.Person WHERE BusinessEntityID = @id AND rowguid = @guid",
|
|
new Dictionary<string, object>
|
|
{
|
|
{ "id", customerId },
|
|
{ "guid", "D8763459-8AA8-47CC-AFF7-C9079AF79033" },
|
|
}
|
|
);
|
|
|
|
if (result.HasResult && result.HasRows)
|
|
{
|
|
Console.WriteLine($"Found '{result.TotalRows}' " + ((result.TotalRows > 1) ? "rows" : "row"));
|
|
Console.WriteLine(string.Empty);
|
|
foreach (var record in result.DataSet)
|
|
{
|
|
Console.WriteLine($"{record.FirstName} {record.MiddleName} lives in the database");
|
|
Console.WriteLine($"Say hello to '{record.FirstName} {record.MiddleName}'");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!result.HasResult)
|
|
{
|
|
Console.WriteLine("No valid result!");
|
|
}
|
|
|
|
if (!result.HasRows)
|
|
{
|
|
Console.WriteLine("No rows found");
|
|
}
|
|
if (result.HasException)
|
|
{
|
|
Console.WriteLine(result.Exception);
|
|
}
|
|
}
|
|
Console.Read();
|
|
}
|
|
}
|
|
} |