Index: openacs-4/packages/acs-templating/tcl/list-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/list-procs.tcl,v
diff -u -N -r1.60 -r1.61
--- openacs-4/packages/acs-templating/tcl/list-procs.tcl 22 Jun 2015 21:03:13 -0000 1.60
+++ openacs-4/packages/acs-templating/tcl/list-procs.tcl 17 Nov 2015 23:33:01 -0000 1.61
@@ -555,14 +555,19 @@
set last_row [expr {$first_row + ($groupsize + 1) * $page_size - 1}]
set page_offset [expr {($page_group - 1) * $groupsize}]
- # Obtain query which retrieves records count
- set list_properties(count_query) [db_map count_query]
+ # Antonio Pisano 2015-11-17: From now on, the original query
+ # will be tampered with the limit information, so this is our
+ # last chance to save it and use it to get the full row count in
+ # the paginator.
+ set list_properties(page_query_original) $list_properties(page_query_substed)
# Now wrap the provided query with the limit information
set list_properties(page_query_substed) [db_map pagination_query]
- # Generate a paginator name which includes the page group we're in all the
- # filter values, so the paginator cahing works properly
+ # Generate a paginator name which includes the page group we're in
+ # and all the filter values, so the paginator cahing works properly
+ # Antonio Pisano 2015-11-17: it is important that the paginator_name starts with the list's
+ # name, because we count on this in template::paginator::create to retrieve the count_query
set paginator_name $list_properties(name)
foreach filter $list_properties(filters) {
@@ -590,7 +595,6 @@
--dummy--query--name-- \
$list_properties(paginator_name) \
$list_properties(page_query_substed) \
- $list_properties(count_query) \
-pagesize $list_properties(page_size) \
-groupsize $list_properties(page_groupsize) \
-page_offset $page_offset \
Index: openacs-4/packages/acs-templating/tcl/list-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/Attic/list-procs.xql,v
diff -u -N
--- openacs-4/packages/acs-templating/tcl/list-procs.xql 27 Apr 2015 15:28:18 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,10 +0,0 @@
-
-
-
-
-
- select count(*) from ($list_properties(page_query_substed)) t
-
-
-
-
Index: openacs-4/packages/acs-templating/tcl/paginator-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/paginator-procs.tcl,v
diff -u -N -r1.22 -r1.23
--- openacs-4/packages/acs-templating/tcl/paginator-procs.tcl 22 Jun 2015 21:03:13 -0000 1.22
+++ openacs-4/packages/acs-templating/tcl/paginator-procs.tcl 17 Nov 2015 23:33:00 -0000 1.23
@@ -53,10 +53,6 @@
@param query The actual query that returns the IDs of all rows in
the results. Bind variables may be used.
- @param count_query Query returning the total number of records retrieved by
- the original paginator query. This is the full number of
- records, possibly exceeding number_of_pages * rows_per_page.
-
@option timeout The lifetime of a query result in seconds, after which
the query must be refreshed (if not reset).
@@ -148,7 +144,7 @@
ns_write [ns_adp_parse -file $header_file]
}
ns_write [lindex $opts(printing_prefs) 6]
- init $statement_name $name $query $count_query 1
+ init $statement_name $name $query 1
ns_write [lindex $opts(printing_prefs) 7]
set footer_file [lindex $opts(printing_prefs) 4]
if { $footer_file ne "" } {
@@ -171,7 +167,7 @@
}
ad_script_abort
} else {
- init $statement_name $name $query $count_query
+ init $statement_name $name $query
}
} else {
set opts(row_ids) $row_ids
@@ -184,7 +180,7 @@
set opts(group_count) [get_group $name $opts(page_count)]
}
-ad_proc -private template::paginator::init { statement_name name query count_query {print_p 0} } {
+ad_proc -private template::paginator::init { statement_name name query {print_p 0} } {
Initialize a paginated query. Only called by create.
} {
get_reference
@@ -194,17 +190,42 @@
upvar 2 __paginator_ids ids
set ids [list]
+
+ set full_statement_name [uplevel 2 "db_qd_get_fullname $statement_name"]
+
+ # Antonio Pisano 2015-11-17: to get the full rowcount of the records,
+ # we need to wrap the original query into a count(*). The problem comes
+ # with template::list, that builds the paginator query tampering with
+ # the original one, so if we come here from a template::list we cannot
+ # retrieve the real count anymore. I had to come out with a solution
+ # that wouldn't break existing contract for public procs, or this would
+ # have caused unpredictable regressions. Below is the strategy to get
+ # the original query.
+
+ # If query comes from an xql we get it from there...
+ set original_query [db_map $full_statement_name]
+ # ...otherwise we try to see if we come from a template::list...
+ if {$original_query eq ""} {
+ # ...which was slightly modified to keep the original query untampered.
+ set list_name [lindex [split $name ,] 0]
+ if {![catch {template::list::get_reference -name $list_name}]} {
+ set original_query $list_properties(page_query_original)
+ }
+ }
+ # If any of the previous fail, we go for the explicit query
+ if {$original_query eq ""} {
+ set original_query $query
+ }
+
if { [info exists properties(contextual)] } {
# query contains two columns, one for ID and one for context cue
uplevel 2 "
- set full_statement_name \[db_qd_get_fullname $statement_name\]
-
# Can't use db_foreach here, since we need to use the ns_set directly.
db_with_handle db {
- set selection \[db_exec select \$db \$full_statement_name {$query}\]
+ set selection \[db_exec select \$db $full_statement_name {$query}\]
set __paginator_ids \[list\]
set total_so_far 1
@@ -292,7 +313,7 @@
}
# Get full number of rows retrieved by original paginator query
- set full_row_count [uplevel 3 [list db_string query $count_query]]
+ set full_row_count [uplevel 3 [list db_string query [db_map count_query]]]
set properties(full_row_count) $full_row_count
cache set $name:$query:full_row_count $full_row_count $properties(timeout)
}
Index: openacs-4/packages/acs-templating/tcl/paginator-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/paginator-procs.xql,v
diff -u -N
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-templating/tcl/paginator-procs.xql 17 Nov 2015 23:33:00 -0000 1.1
@@ -0,0 +1,10 @@
+
+
+
+
+
+ select count(*) from ($original_query) t
+
+
+
+