Dynamicweb 8 Dynamicweb.Database refactoring
18 October 2011
All communication with databases in Dynamicweb solutions goes through Dynamicweb.Database which contains a bunch of static members that are used for creating connections, datareaders, datasets and other database related helper methods, like SqlBool etc.
Background
The current Dynamicweb.Database type has some usability issues that we need to address with Dynamicweb 8 API refactoring.
- Inconsistent naming, “GetConn” vs “getDatareader” (Casing), abbreviations instead of using the whole word (GetConn – should have been GetConnection).
- Messy overloads. Overload members are done using Optional parameters on the members, giving API usability issues especially in C# (Not that big an issue after C# also supports optional paramteres). Also some overloads are missing – like GetConn with no parameters.
- Too many public members that 3rd party developers have no use for, i.e. CreateStatisticCounters, ToggleStatistic and IsolateFromHttpContext. All members that we use internally for various purposes.
All of this can be optimized to the Database API is faster and easier to use.
The change
As part of Dynamicweb 8 API refactoring, this type has been refactored to address the issues mentioned above.
Consistent naming when getting data from the database (Old names in parenthesis)
- CreateConnection (GetConn)
- CreateAdapter (GetAdapter)
- CreateCommandBuilder (GetCommandBuilder)
- CreateDataReader (getDatareader)
- CreateDataSet (getDataset)
- CreateDataTable (New)
- ExecuteScalar (Not renamed)
- ExecuteNonQuery (Not renamed)
New and changed overloads
- CreateConnection (2 overloads, 1 new)
- CreateDataReader (3 overloads, 2 new)
- CreateDataSet (3 overloads, 1 new)
- CreateDataTable (3 overloads, new method)
- ExecuteNonQuery (8 overloads, 4 new)
- ExecuteScalar (2 overloads, 1 new)
Members that is now internal:
- IsolateFromHttpContext
- ToggleStatistic
- CreateStatisticCounters
- RemoveStatisticCounters
- ClearStatistics
- PrintStatistics
- getStack
- IncrementCounter
- GetParam
- SQLEscapeInjectionForbiddenWords
- SQLEscapeInjectionRegexChecks
- SQLInjectionPrevent
- SQLInjectionEndRequest
- SortListByDataSet
- ColumnExists
- SimplifyUpdateCommandText
- BuildUpdateCmd
- GetDbType
- GetDBValue
- GetXMLString
- CopyRow
So what does that mean?
Well, not much for upgrading solutions. Except if you use any of the members that are now internal – they are no longer available.
All your use of i.e. GetConn and getDatareader does not need to change. They are still in the API, but hidden for intellisense and obsoleted so you will get compile warnings – but no errors.
Bottom line: Your code using Dynamicweb.Database does not need any upgrade when upgrading solutions to from Dynamicweb 7 to Dynamicweb 8.
Hope you like the change and will find the database API easier to use. Please leave your comments.
2 Comments
-
-
Imar Spaanjaars 28 October 2011 13:27
@Kevin: +1 for that idea! I really would like to see that dependency removed!
Imar
nicolaipedersen.com
Denmark
Netherlands
Norway
Brazil
Spain
Sweden
UK
Portugal
Dynamicweb global website
Dynamicweb partner network
Dynamicweb developer network







One thing that I have been struggling with is to run unit tests that depend on Dynamicweb API. It is pretty much impossible today to mock Dynamicweb API because it so heavy relies on a HttpContext.
Could you some how take that into consideration that you need to support unit test on 3. party addins it would be great!
Think of having Dynamicweb powering a console app - charming right :)