SqlServer & Database Refactoring
PostPosted: Thu Jul 14, 2016 4:26 pm
Hello, I was working on a SQL Server implementation about a year ago. I had it working pretty solid, the only piece remaining was adding UI support to the windows form & testing. I ran into an incident that rendered my laptop unusable. I didn’t take any backups and my only option was to re-image it so I lost everything. I was too upset to rewrite it from scratch, but now, a year later I’m ready to get back on it. One thing I noticed, the code based changed significantly. It looks so much better now! Good work Leodagan & Kypdurron, it is much cleaner and intuitive! Is the refactoring complete? It looks complete but I want to eventually pitch the SQL Server implementation as a contribution but I don’t want to get too carried away if it still has work that needs to be done to it. I’m trying to keep everything in the same style/pattern as SqlLiteObjectDatabase & MySqlObjectDatabase.
One concern I have is I don’t want to bastardize SqlObjectDatabase by littering it with a bunch of if (connectionType == ConnectionType.DATABASE_MYSQL) do this, if (connectionType == ConnectionType.DATABASE_SQLSERVER) do that like the old way. It looks like a lot of that mess was cleaned up. I noticed this was everywhere in the old version so I wasn’t too concerned. However, now it’s been cleaned up, do you guys have any recommendations for keeping it clean? Because unfortunately, the only way around something like this is to check the connection type and fire off a completely new block, eg:

One concern I have is I don’t want to bastardize SqlObjectDatabase by littering it with a bunch of if (connectionType == ConnectionType.DATABASE_MYSQL) do this, if (connectionType == ConnectionType.DATABASE_SQLSERVER) do that like the old way. It looks like a lot of that mess was cleaned up. I noticed this was everywhere in the old version so I wasn’t too concerned. However, now it’s been cleaned up, do you guys have any recommendations for keeping it clean? Because unfortunately, the only way around something like this is to check the connection type and fire off a completely new block, eg:
- Code: Select all
var command = string.Format("UPDATE `{0}` SET {1} WHERE {2}", tableHandler.TableName, string.Join(", ", columns.Select(col => string.Format("{0} = {1}", col.ColumnName, col.ParamName))), string.Join(" AND ", primary.Select(col => string.Format("{0} = {1}", col.ColumnName, col.ParamName))));
- Code: Select all
var command = string.Empty; if(connectionType == ConnectionType.DATABASE_MYSQL || connectionType == ConnectionType.DATABASE_SQLITE)) { command = string.Format("UPDATE `{0}` SET {1} WHERE {2}", tableHandler.TableName, string.Join(", ", columns.Select(col => string.Format("{0} = {1}", col.ColumnName, col.ParamName))), string.Join(" AND ", primary.Select(col => string.Format("{0} = {1}", col.ColumnName, col.ParamName)))); } else { command = string.Format("UPDATE {0} SET {1} WHERE {2}", tableHandler.TableName, string.Join(", ", columns.Select(col => string.Format("{0} = {1}", col.ColumnName, col.ParamName))), string.Join(" AND ", primary.Select(col => string.Format("{0} = {1}", col.ColumnName, col.ParamName)))); }