Wednesday, January 21, 2015
Creating a Flex AIR text editor Part 49
In the previous few tutorials weve started working on the snippets system using SQL and XML. Today we will rethink and redesign the structure of the snippet system.Previously, we had the SQL database with 1 table to store all the data values for the snippets. Then we had an XML object generated on the go from these values, and all those values from the database were transferred to the XML. Thus, we just copied the values from one type of database to another. Storing a huge amount of snippets in memory would practically be a bad idea, especially if we keep absolutely all the values of the snippet, including its text value, which could be easily retreived from the SQL database.
We also had a working relocation system, which allowed the user to move the snippets and categories around the tree and place them as the user wanted. We also could add new categories and snippets. Finally, we were able to save all these values back to the SQL database. When we did that, we completely overwrote whatever we had in the SQL before and replaced it with new data generated from the local XML.
This pretty much works and could be used fine, however, there are a few problems in the structure. First of all, the SQL database isnt used as it is supposed to - it is just used as a storage tool right now. Ideally, we would write and read from it only when needed, not all at once.
What we did in the previous few tutorials was intended to help you understand how Tree objects work, as well as how we can use SQL and XML databases together. Now, before we move to features like editing and removing snippets and categories, it is the best time to redesign our structure a little bit. There will be some major changes in the SQL/XML code, however, a lot of things will remain the same. Even though we will get rid of some of the code that we have right now, that code was necessary to get to the point we are right now.
So, what are the structure redesign changes?
First of all, we will use 2 SQL tables instead of one. We will use one to store all snippets, and the second to store categories.
Secondly, we will not write ALL values to the XML - only the ones that will be necessary to ensure the correct name and position of the snippet/category in the tree. This also means that we will have to introduce a few new columns in SQL tables that will hold the position values.
Thirdly, we will have all changes to be applied in real time, no save buttons needed, since we update the SQL and XML at the same time.
It is always a good idea to have a plan for your application structure when using databases.
Heres the structure design plan for the snippets feature:
We will start working on this next time.
Thanks for reading!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.