feat: Implementa gestione intelligente della chiave sorgente con rilevamento PK
- Aggiunge rilevamento automatico Primary Key per connessioni database - Rimuove completamente il fallback automatico per lato sorgente - Implementa selezione manuale obbligatoria per file e sorgenti non-DB - Migliora UI con suggerimenti intelligenti e feedback visivo - Aggiunge validazione multi-livello (UI, pre-transfer, runtime) - Introduce metodo GetPrimaryKeyFieldAsync in IDatabaseManager - Modifica GenerateSourceKey per richiedere sempre campo specifico - Implementa controllo IsTransferButtonEnabled per validazione form Breaking changes: - La generazione automatica delle chiavi sorgente è stata rimossa - Il campo chiave sorgente è ora obbligatorio quando si usa il sistema associazioni Fixes: Risolve problema di discovery schema vuoto con selezione database
This commit is contained in:
@@ -17,13 +17,24 @@ public class SqlServerSchemaProvider : IDatabaseSchemaProvider
|
||||
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"[DEBUG] SqlServerSchemaProvider - Connection string: {connectionString?.Substring(0, Math.Min(50, connectionString?.Length ?? 0))}...");
|
||||
|
||||
using (var connection = new SqlConnection(connectionString))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
Console.WriteLine($"[DEBUG] SqlServerSchemaProvider - Connessione aperta");
|
||||
|
||||
// Prima verifichiamo se ci sono tabelle utente con una query semplice
|
||||
string testSql = "SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0";
|
||||
using (var testCommand = new SqlCommand(testSql, connection))
|
||||
{
|
||||
var scalarResult = await testCommand.ExecuteScalarAsync();
|
||||
var tableCount = scalarResult != null ? (int)scalarResult : 0;
|
||||
|
||||
if (tableCount == 0)
|
||||
{
|
||||
return new Dictionary<string, IEnumerable<DbColumnInfo>>(); // Restituisce dizionario vuoto
|
||||
}
|
||||
}
|
||||
|
||||
// Se ci sono tabelle, procediamo con la query completa
|
||||
// Query per ottenere la struttura delle tabelle in SQL Server
|
||||
string sql = @"
|
||||
SELECT
|
||||
@@ -71,8 +82,8 @@ public class SqlServerSchemaProvider : IDatabaseSchemaProvider
|
||||
|
||||
using (var reader = await command.ExecuteReaderAsync())
|
||||
{
|
||||
string currentTable = null;
|
||||
List<DbColumnInfo> columns = null;
|
||||
string? currentTable = null;
|
||||
List<DbColumnInfo>? columns = null;
|
||||
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
@@ -117,12 +128,6 @@ public class SqlServerSchemaProvider : IDatabaseSchemaProvider
|
||||
{
|
||||
result[currentTable] = columns;
|
||||
}
|
||||
|
||||
Console.WriteLine($"[DEBUG] SqlServerSchemaProvider - Query completata. Trovate {result.Count} tabelle");
|
||||
foreach (var table in result.Take(3))
|
||||
{
|
||||
Console.WriteLine($"[DEBUG] SqlServerSchemaProvider - Tabella: {table.Key}, Colonne: {table.Value?.Count() ?? 0}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user