| 359 | |
| 360 | |
| 361 | |
| 362 | === 1/8/2010 === |
| 363 | |
| 364 | I've added the sql_query method to the main component class. All child classes will query sql the same way. The connect and disconncet methods are also component class Methods. I though previously I had added a discussion about various connections models. The two competeing ideas were: |
| 365 | * Let each child handle their own connections |
| 366 | * Let the main program handle the connection. |
| 367 | I decided to put the connection task in the main function because less connection attempts would be made (this should be more stable) and I can use a single begin/rescue/ensure block to make sure the connection closes. |
| 368 | |
| 369 | I've added an abstract method (see [http://groups.google.com/group/ruby-talk-google/browse_thread/thread/521f4588e3b24285 here])in the component called update (in the parent it raises a NotImplemented error). This forces all children to have an update method (which should then be implemented). |
| 370 | |
| 371 | I used an interesting construction in the sql_query method, thats worth mentioning. If given an array of parameters to glue together, I can string them with out a trailing separator like so A=[A,B,C,D] A.first(A.length-1).map{|a| a + ","} + A.last. This gets the the elements as a string with separators (join might also take a separator argument which might be cleaner, but doesn't work in the case if some elements are nil). |
| 372 | |
| 373 | I also started using Array.zip to iterate two arrays with map. If I have A and B arrays and I need to do something to both. I can do |
| 374 | C = A.zip(B).map{|x| f(x[0],x[1])}. I'm doing this with the individual data elements that need to be pushed back into the Tables, that way I can just zip the indvidual data arrays into one big one later. See the kind construct. |
| 375 | |
| 376 | Finally, the sql_query method has a .flatten in the last statmenet now since the row and query operations return a nested array. I've made it a policy that the query should return a flat array of answers. |
| 377 | |
| 378 | |