xo::db::CrFolder proc instance_select_query (public)
xo::db::CrFolder instance_select_query \ [ -select_attributes select_attributes ] [ -orderby orderby ] \ [ -where_clause where_clause ] [ -from_clause from_clause ] \ [ -with_subtypes on|off ] [ -with_children on|off ] \ [ -publish_status publish_status ] [ -count on|off ] \ [ -folder_id folder_id ] [ -parent_id parent_id ] \ [ -page_size page_size ] [ -page_number page_number ] \ [ -base_table base_table ]
Defined in /var/www/openacs.org/packages/xotcl-core/tcl/cr-procs.tcl
returns the SQL-query to select the CrItems of the specified object_type
- Switches:
- -select_attributes (optional)
- attributes for the SQL query to be retrieved, in addition to item_id, name, publish_status, object_type which are always returned
- -orderby (optional)
- for ordering the solution set
- -where_clause (optional)
- clause for restricting the answer set
- -from_clause (optional)
- -with_subtypes (optional, boolean, defaults to
"true"
)- return subtypes as well
- -with_children (optional, boolean, defaults to
"true"
)- return immediate child objects of all objects as well
- -publish_status (optional)
- one of 'live', 'ready', or 'production'
- -count (optional, boolean, defaults to
"false"
)- return the query for counting the solutions
- -folder_id (optional)
- parent_id
- -parent_id (optional)
- -page_size (optional, defaults to
"20"
)- -page_number (optional)
- -base_table (optional, defaults to
"cr_folders"
)- typically automatic view, must contain title and revision_id
- Returns:
- SQL query
- Testcases:
- No testcase defined.
Source code: if {![info exists folder_id]} {set folder_id ${:folder_id}} if {![info exists parent_id]} {set parent_id $folder_id} if {$base_table eq "cr_folders"} { set attributes [list ci.item_id ci.name ci.publish_status acs_objects.object_type] } else { set attributes [list bt.item_id ci.name ci.publish_status bt.object_type] } foreach a $select_attributes { # if {$a eq "title"} {set a bt.title} lappend attributes $a } # FIXME: This is dirty: We "fake" the base table for this function, so we can reuse the code set type_selection_clause [:type_selection_clause -base_table cr_revisions -with_subtypes false] # :log "type_selection_clause -with_subtypes $with_subtypes returns $type_selection_clause" if {$count} { set attribute_selection "count(*)" set orderby "" ;# no need to order when we count set page_number "" ;# no pagination when count is used } else { set attribute_selection [join $attributes ,] } set cond [list] if {$type_selection_clause ne ""} {lappend cond $type_selection_clause} if {$where_clause ne ""} {lappend cond $where_clause} if {[info exists publish_status]} {lappend cond "ci.publish_status = :publish_status"} if {$base_table eq "cr_folders"} { lappend cond "acs_objects.object_id = cf.folder_id and ci.item_id = cf.folder_id" set acs_objects_table "acs_objects, cr_items ci, " } else { lappend cond "ci.item_id = bt.item_id" set acs_objects_table "" } if {$parent_id ne ""} { set parent_clause "ci.parent_id = :parent_id" if {$with_children} { lappend cond "ci.item_id in ( select children.item_id from cr_items parent, cr_items children where children.tree_sortkey between parent.tree_sortkey and tree_right(parent.tree_sortkey) and parent.item_id = $parent_id and parent.tree_sortkey <> children.tree_sortkey)" } else { lappend cond $parent_clause } } if {$page_number ne ""} { set limit $page_size set offset [expr {$page_size*($page_number-1)}] } else { set limit "" set offset "" } set sql [::xo::dc select -vars $attribute_selection -from "$acs_objects_table cr_folders cf $from_clause" -where [join $cond " and "] -orderby $orderby -limit $limit -offset $offset] return $sqlXQL Not present: Generic, PostgreSQL, Oracle