Forum OpenACS Development: Response to Too lazy to code

Collapse
Posted by Tom Jackson on

I will outline the basic steps here to using the query writer. Since it now writes up the pg create script functions and the drop script, I think you can possibly ignore the pkbuilder package. That package will create both oracle and pg packages, but I think the query writer will handle things like function overloading, which is needed in pg when you have more than 16 attributes.

  • Install query-writer version at lease 0.5.1. I manually loaded the data model with i query-writer-create.sql, then I used the apm:
    • Select the Install packages link on the main APM page.
    • Select only the query-writer package.
    • Click on the Next --> button.
    • Unselect the load checkbox next to the data model.
    • Click on the Install Packages button.
    • That should be it, you might have to restart the server to load the bootstrap data.
  • Use the site-map to mount the query-writer package at /qw.
  • Maybe you have to restart after it is mounted, I'm not sure if you need to do this however.
  • Visit the main admin page at /qw/admin
  • Click on the Objects, then the Add/Select Object links.
  • Scroll down the page an see if the query-writer objects are listed in the Current Objects table.
  • Assuming these are there, proceeed, otherwise try to figure out why the bootstrap data didn't load.
  • Create an object by filling out the form at the top of the page. An object is the container for all the attributes in the main table plus any additional attributes for the acs object or other stuff you want to pass to a function.
    • The object_id could be different from the object. But usually it will be the same. For pg functions that end up looking like 'xy__new', the object is 'xy', but the object_id could be anything.
    • The Object Table is the main table, and the Key is the primary key for this table.
    • Eval After is a little complicated. Usually you don't pass every attribute using a form. Sometimes extra attributes need to be set based on the current submission environment. For instance, I usually set the context_id to something useful. Examples of setting the context_id :
             context_id;upvar user_id context_id
             context_id;set context_id [ms_get_customer_id]
             

      An example in query writer using a the db api to select an sequence for insert:

              fn_id;set fn_id [db_string fn_nextval "select  
              nextval('qw_fn_sequence')"]
             
    • Please ignore the perm checks, these are now handled with a new perm check filter. The filter names are 'admin_pemission' , 'write_permission', and 'read_permission', and you can add these to the object attribute filters later on.
    • Right now the operations are set at 'new;set;del', I haven't added any other operations yet. This is the starting name of the form variables, and the names of the arrays used in qw.tcl.
    • The new, set and del function names should correspond to what you wish to call these. I use object__new, object__set_attrs, and object__delete. These should not be in this table, but they are. They are needed, and they do have to match the names of your functions used later on.
    • The permission_p radio allow you to turn the permission_p checking off. Objects don't have to be acs objects, or developers might write a filter to do permission checking in a different way. Don't use permission_p is you have figured out a better way to check this.
    • Click on the Add Object button.
  • Add attributes to the object. Once the object is created, select it from the Current Objects table. There are three links at the top of the 'one' page for the object. The first allows you to add attributes.
    • Usually the attribute and the attribute Id will be the same. If you want to obscure the backend datamodel from the user, you can choose different names for each. Of course, the attribute has to match the backend data model.
    • Datatype. Select one, unfortunately I left out 'text'. If you need the text, type, edit the form. This is a general datatype like what gets fed to a function.
    • Filters, these are the filters just like in ad_page_contract. Unfortunately, or fortunately, not all filters are the same. You cannot use trim, notnull, or some of the other filters. However, all values are trimmed at the array level, so this gets done anyway. The notnull filter is useless with query writer anyway. I use integer on all integer values.
    • Default value is usually set to any default in the table definition. This is not used directly, when you define your functions, each one can have a different default for the same attribute.
    • The maximum length is used for char and varchar attribute types. A separate filter is run if this is set. This avoids many database rejections.
    • Description, is usually limited to a very brief human readable name for the attribute.
    • Help Text further describes the attribute.
    • Click on the Add Attribute button.