Fix long strings in import

This commit is contained in:
Carsten Larsen 2016-12-21 21:49:19 +01:00
parent 006b0f090a
commit 994af48594
1 changed files with 37 additions and 20 deletions

View File

@ -128,6 +128,25 @@ protected override TimeServer FetchExternal(int id)
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
protected override void Insert(TimeServer item)
{
string countryCode = item.Country?.Substring(0, 7);
string hostName = item.Name?.Substring(0, 50);
string ip = item.Address?.ToString().Substring(0, 15);
string ip6 = item.V6Address?.Substring(0, 30);
string location = item.Location?.Substring(0, 100);
string displayLocation = item.DisplayLocation?.Substring(0, 60);
string organization = item.Organization?.Substring(0, 50);
string coordinates = item.Geo?.Substring(0, 50);
string synchronization = item.Server?.Substring(0, 255);
string serviceArea = item.ServiceArea?.Substring(0, 100);
string accessPolicy = item.AccessPolicy?.Substring(0, 255);
string accessDetails = item.AccessDetails?.Substring(0, 512);
string autoKeyUrl = item.AutoKey?.Substring(0, 255);
string symmetricKeyType = item.SymKey?.Substring(0, 100);
string symmetricKeyUrl = item.SymUrl?.Substring(0, 100);
string serverContact = item.Contact?.Substring(0, 255);
string providerPage = item.ProviderPage?.Substring(0, 100);
string providerUrl = item.ProviderUrl?.Substring(0, 255);
lock (MapperLocker)
{
try
@ -136,29 +155,27 @@ protected override void Insert(TimeServer item)
Command.CommandText = PrepareInsertSql(InsertSql);
Command.Parameters.Add(CreateParameter("@id", item.Id));
Command.Parameters.Add(CreateParameter("@stratum", item.Stratum));
Command.Parameters.Add(CreateParameter("@countryCode", item.Country));
Command.Parameters.Add(CreateParameter("@hostName", item.Name));
Command.Parameters.Add(CreateParameter("@ip",
item.Address != null ? (object) item.Address.ToString() : DBNull.Value));
Command.Parameters.Add(CreateParameter("@ip6",
(object) item.V6Address ?? DBNull.Value));
Command.Parameters.Add(CreateParameter("@countryCode", countryCode));
Command.Parameters.Add(CreateParameter("@hostName", hostName));
Command.Parameters.Add(CreateParameter("@ip", ip));
Command.Parameters.Add(CreateParameter("@ip6", ip6));
Command.Parameters.Add(CreateParameter("@useDns", item.ShouldUseDns));
Command.Parameters.Add(CreateParameter("@poolMember", item.IsPoolMember));
Command.Parameters.Add(CreateParameter("@location", item.Location));
Command.Parameters.Add(CreateParameter("@displayLocation", item.DisplayLocation));
Command.Parameters.Add(CreateParameter("@organization", item.Organization));
Command.Parameters.Add(CreateParameter("@coordinates", item.Geo));
Command.Parameters.Add(CreateParameter("@synchronization", item.Server));
Command.Parameters.Add(CreateParameter("@serviceArea", item.ServiceArea));
Command.Parameters.Add(CreateParameter("@accessPolicy", item.AccessPolicy));
Command.Parameters.Add(CreateParameter("@accessDetails", item.AccessDetails));
Command.Parameters.Add(CreateParameter("@location", location));
Command.Parameters.Add(CreateParameter("@displayLocation", displayLocation));
Command.Parameters.Add(CreateParameter("@organization", organization));
Command.Parameters.Add(CreateParameter("@coordinates", coordinates));
Command.Parameters.Add(CreateParameter("@synchronization", synchronization));
Command.Parameters.Add(CreateParameter("@serviceArea", serviceArea));
Command.Parameters.Add(CreateParameter("@accessPolicy", accessPolicy));
Command.Parameters.Add(CreateParameter("@accessDetails", accessDetails));
Command.Parameters.Add(CreateParameter("@notification", item.ShouldNotify));
Command.Parameters.Add(CreateParameter("@autoKeyUrl", item.AutoKey));
Command.Parameters.Add(CreateParameter("@symmetricKeyType", item.SymKey));
Command.Parameters.Add(CreateParameter("@symmetricKeyURL", item.SymUrl));
Command.Parameters.Add(CreateParameter("@serverContact", item.Contact));
Command.Parameters.Add(CreateParameter("@providerPage", item.ProviderPage));
Command.Parameters.Add(CreateParameter("@providerUrl", item.ProviderUrl));
Command.Parameters.Add(CreateParameter("@autoKeyUrl", autoKeyUrl));
Command.Parameters.Add(CreateParameter("@symmetricKeyType", symmetricKeyType));
Command.Parameters.Add(CreateParameter("@symmetricKeyURL", symmetricKeyUrl));
Command.Parameters.Add(CreateParameter("@serverContact", serverContact));
Command.Parameters.Add(CreateParameter("@providerPage", providerPage));
Command.Parameters.Add(CreateParameter("@providerUrl", providerUrl));
Command.Parameters.Add(CreateParameter("@updated", item.Updated));
Command.Prepare();
Log.SqlExecute(Command.CommandText, Command.Parameters);