Chapter 16: ADO Scripts for Posting
All news stories are processed by the editor when they come from authors. After the complete processing phase, the editor must persist on a data storage. In previous chapters, you saw how to save and load data into a local database like Microsoft Access. In an enterprise, you normally have a database server such as Microsoft SQL Server. In this chapter, you see how to save all stories to a database like SQL Server.
Persistency Strategy
Software engineering provides several ways to store data in a database. You can, for example, map each XML element to a data table and each leaf node and attribute to a field of the data table. This is obviously not a general solution, since the two data structures, XML and database, are not always comparable on a one-to-one basis. In fact, the XML structure is hierarchical, whereas the database is relational. In our case, we have an exception, since the XML structure adapts very well to the relational one. The only problem is that we have to write a lot of code to save the news.Another solution consists of saving the whole XML document in a single data table BLOB (Binary Large Object) field. This approach simplifies the programming code to write but involves several complications for searching algorithms used by customers. How do you retrieve all stories of a given category or status? You should open all documents and load inside in order to retrieve the information required.A possible alternative to the preceding approaches is to have a hybrid solution, then save only sensitive data and the remaining as a BLOB field. In this way, the indexed values are then saved as single field values and the remainder as a single file containing the whole XML story. This is the approach we will pursue in this case study.