Hi Paolo, in Empire-db an instance of DBRecord can hold a single row of a table which you may read or update. In order to read a record into a DBRecord object, you must supply it's primary key to the read() method.
A DBReader on the other side is used to obtain and iterate through information about objects (or records) and usually does not correspond to the record of a table - like with a query that contains only selected columns as well as joins to other tables. Hence a DBReader only provides read only access to the underlying data (through the RecordData interface which both DBReader and DBRecord implement). A typcial real world situation is that a user enters search criteria for which a list of matching items is presented to him. He then selects the item (record) he is looking for and changes some of its values. In this case you work with a DBCommand in conjunction with a DBReader to provide the list that you display to the user. The list should contain the primary key of the underlying records. When the user selects a particular record it is read using the primary key into a DBRecord object then changed and updated. The same procedure is repeated for all other records. Although this is the most common approach, there is a second solution that might be more efficient in some cases: You may use a DBReader to query and iterate though a set of records and then upgrade the current row to a full DBRecord object which you can update. To achive this, all you need to do is to call the initRecord() method on the DBReader and supply the DBRecord object you with the use and the Table you want to work on. This will only work however if the query also contains the primary key column(s). You can find an example for this in the bulkProcessRecords() method of the advanced example (DBSampleAdv) from line 442. >From you description however I thinks that the first approach is more suitable >for your problem. What is your problem with reading the record using the primary key that you obtained from the query? You probably need the primary key anyway in order to identify the right amount for a particular person, don't you? For a complete solution that shows how to work with Empire-db in an interactive application I recommend running the Struts2 web example. Has this been of any help to you? Regards Rainer Paolo Predonzani wrote: > re: reading and updating records > > Hi, > I'm starting to learn empire-db. I have a problem with the following > situation. > My goal is to: > 1- Select some records from the database (e.g., all employees where > department = X) > 2- Change some values on those records (e.g., add an amount to the > salary) > 3- Save those records back to the database > > Step 2 is done interactively by the user, so I cannot do steps 1,2,3 in > a single UPDATE statement. > > My question is: if I build the query using a DBCommand, how do I get > its results as a list of DBRecords? > I believe I need DBRecords in step 3 to run the update. > > I see how: > - a DBReader can give me a list of beans, but not a list of DBRecords? > - a DBReader can return an iterator of DBRecordData, but I'm not sure I > know how to use that. > - I can wrap a DBCommand using a DBQuery, but from there I can only > read records of which I can provide the primary key (readRecord() > method), which I can't since I don't know what the result of my query > contains. > > > Have I missed anything in the docs? > > Thank you for any help > Regards > > > Paolo
