Forum OpenACS Development: Re: xotcl object and adp pages

Collapse
Posted by Gustaf Neumann on
Dear Andrei,

Are you aware of the interface between xotcl and the acs object system?

You might check out the following links:

Some answer to your questions:

  1. How to fetch sql content into a single object:

    xotcl-core defines already for all objects a method db_1row. By using this method, the variables returned by the sql query are set a instance variables in the used object.

    Example (try it e.g. in the developer support in the ds/shell):

       Object o
       o db_1row . {select * from acs_objects where object_id = 0}
       o set title
    
  2. How to output variables easy in adp-files:

    Well, adp is defined to work within a single namespace. So it has no predefined support for xotcl instance variables. However, it is not very complicated to extend the adp-compiler to recognize it. This way, one could resolve instance variables in ADP similarly to array variables with the syntax @table.entry@ e.g. with the new syntax @object->instance_variable@. But that is not standard. For now, you have to export the variables to the appropriate scope. For the example above for a single variable one can use

       o instvar title
    
    or for all instvars of the object
       eval o instvar [o info vars]
    
  3. How to fetch multiple tuples into multiple objects:

    xotcl-core defines instantiate_objects, which accepts an arbitrary SQL query and returns an ordered composite with the results OrderedComposite. Example (try it e.g. in the developer support in the ds/shell):

       # fetch results into an ordered composite
       set s [::xo::db::Object instantiate_objects -sql {select * from acs_objects limit 10}]
    
       # iterate over the ordered composite
       foreach x [$s children] { append _ [$x set object_id] \n}
    
       # show result
       set _
    
Hope this helps,

Best regards
-gustaf neumann