From 83d392af47eb3cc276befb849fc0a64b6962d853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 18 May 2018 09:50:16 +0200 Subject: [PATCH] added informix dbadapter --- Respawn/DbAdapter.cs | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/Respawn/DbAdapter.cs b/Respawn/DbAdapter.cs index 74f90d4..d00a518 100644 --- a/Respawn/DbAdapter.cs +++ b/Respawn/DbAdapter.cs @@ -20,7 +20,102 @@ public static class DbAdapter public static readonly IDbAdapter Postgres = new PostgresDbAdapter(); public static readonly IDbAdapter MySql = new MySqlAdapter(); public static readonly IDbAdapter Oracle = new OracleDbAdapter(); + public static readonly IDbAdapter Informix = new InformixDbAdapter(); + private class InformixDbAdapter : IDbAdapter + { + private const char QuoteCharacter = '"'; + + public string BuildTableCommandText(Checkpoint checkpoint) + { + string commandText = @"SELECT t.owner, t.tabname + FROM 'informix'.systables t + WHERE t.tabtype = 'T' + AND t.tabid >= 100"; + + if (checkpoint.TablesToIgnore.Any()) + { + var args = string.Join(",", checkpoint.TablesToIgnore.Select(t => $"'{t}'")); + + commandText += " AND t.tabname NOT IN (" + args + ")"; + } + if (checkpoint.SchemasToExclude.Any()) + { + var args = string.Join(",", checkpoint.SchemasToExclude.Select(t => $"'{t}'")); + + commandText += " AND t.owner NOT IN (" + args + ")"; + } + else if (checkpoint.SchemasToInclude.Any()) + { + var args = string.Join(",", checkpoint.SchemasToInclude.Select(t => $"'{t}'")); + + commandText += " AND t.owner IN (" + args + ")"; + } + + return commandText; + } + + public string BuildRelationshipCommandText(Checkpoint checkpoint) + { + string commandText = @"SELECT T2.owner, T2.tabname, T1.owner, T1.tabname, C.constrname + FROM sysreferences R + INNER JOIN sysconstraints C + ON R.constrid = C.constrid + INNER JOIN systables T1 + ON (T1.tabid = R.ptabid) + INNER JOIN systables T2 + ON T2.tabid = C.tabid + WHERE C.constrtype = 'R' + AND (T1.tabtype = 'T' AND T1.tabid >= 100) + AND (T2.tabtype = 'T' AND T2.tabid >= 100)"; + + if (checkpoint.TablesToIgnore.Any()) + { + var args = string.Join(",", checkpoint.TablesToIgnore.Select(t => $"'{t}'")); + + commandText += " AND T2.tabname NOT IN (" + args + ")"; + } + if (checkpoint.SchemasToExclude.Any()) + { + var args = string.Join(",", checkpoint.SchemasToExclude.Select(t => $"'{t}'")); + + commandText += " AND T2.owner NOT IN (" + args + ")"; + } + else if (checkpoint.SchemasToInclude.Any()) + { + var args = string.Join(",", checkpoint.SchemasToInclude.Select(t => $"'{t}'")); + + commandText += " AND T2.owner IN (" + args + ")"; + } + + return commandText; + } + + public string BuildDeleteCommandText(GraphBuilder graph) + { + var builder = new StringBuilder(); + + foreach (var table in graph.CyclicalTableRelationships) + { + builder.AppendLine($"SET CONSTRAINTS {QuoteCharacter}{table.Name}{QuoteCharacter} DISABLED;"); + } + foreach (var table in graph.ToDelete) + { + builder.AppendLine($"DELETE FROM {table.GetFullName(QuoteCharacter)};"); + } + foreach (var table in graph.CyclicalTableRelationships) + { + builder.AppendLine($"SET CONSTRAINTS {QuoteCharacter}{table.Name}{QuoteCharacter} ENABLED;"); + } + + return builder.ToString(); + } + + public string BuildReseedSql(IEnumerable tablesToDelete) + { + throw new System.NotImplementedException(); + } + } private class SqlServerDbAdapter : IDbAdapter { private const char QuoteCharacter = '"';