Any ideas would be great. This database gets recreated (when ran locally) when the data model changes. I can see in the future, or on future projects how this might be painful from an initialization / initial load perspective.
It looks like the correct SQL to me, what do you mean by fully qualified? Note you can’t just execute the captured SQL like that, it needs the db parameters as well.
You can enable Logging to see what SQL is being executed:
LogManager.LogFactory = new ConsoleLogFactory(debugEnabled:true);
I see. I guess I was expecting it to work the way I have the create/drop working:
List<string> sqlStatements = new List<string>();
Log.Info("Dropping tables");
using (var captured = new CaptureSqlFilter())
{
db.DropTables(types.Reverse().ToArray());
sqlStatements.AddRange(captured.SqlStatements.ToList());
}
if (sqlStatements.Count > 0)
{
db.ExecuteSql(string.Join("\n\n", sqlStatements));
sqlStatements.Clear();
}
else
{
Log.Info("Tables dropped");
}
Log.Info("Creating tables");
using (var captured = new CaptureSqlFilter())
{
db.CreateTables(true, types.ToArray());
sqlStatements.AddRange(captured.SqlStatements.ToList());
}
if (sqlStatements.Count > 0)
{
db.ExecuteSql(string.Join("\n\n", sqlStatements));
Log.Info("Tables created");
sqlStatements.Clear();
}
else
{
Log.Info("No action required");
}
I guess what confused me the most is that even though I passed in a collection of objects, filled with data, the values did not exist in the generated sql statements. Thanks for letting me know what the issue was.
Oh, and by fully qualified sql I meant the objects having the values that were passed when the collection rendered the insert statements. I was in a hurry when I wrot that, so I guess I could have used better terminology.
Right, but that only works because DDL Statements don’t have any DB params.
It’s not going to help when concatenating sql statements like this since it uses the same db param names, but you can inspect captured db params from captured.SqlCommandHistory[0].Parameters. See the CaptureSqlFilter class for info.