[glom] libglom: Restore the Util::build_sql_select_count_row() API.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] libglom: Restore the Util::build_sql_select_count_row() API.
- Date: Thu, 20 Oct 2011 11:54:16 +0000 (UTC)
commit 01d6d6e53c9303ea78427c286db0c1ce76b91e40
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Oct 20 13:53:54 2011 +0200
libglom: Restore the Util::build_sql_select_count_row() API.
* glom/libglom/db_utils.cc: move it back to:
* glom/libglom/utils.[h|cc]: because it is needed by java-libglom.
ChangeLog | 7 +++++++
glom/libglom/db_utils.cc | 33 +--------------------------------
glom/libglom/utils.cc | 30 ++++++++++++++++++++++++++++++
glom/libglom/utils.h | 11 +++++++++++
4 files changed, 49 insertions(+), 32 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c8768d4..f80351a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2011-10-20 Murray Cumming <murrayc murrayc com>
+ libglom: Restore the Util::build_sql_select_count_row() API.
+
+ * glom/libglom/db_utils.cc: move it back to:
+ * glom/libglom/utils.[h|cc]: because it is needed by java-libglom.
+
+2011-10-20 Murray Cumming <murrayc murrayc com>
+
Self-hosting tests: Test with sqlite too.
* tests/test_selfhosting_utils.[h|cc]: test_create_and_selfhost():
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index cc194e4..3b9a2f5 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1813,37 +1813,6 @@ Glib::ustring get_unused_database_name(const Glib::ustring& base_name)
return Glib::ustring();
}
-/** Build a SQL query to discover how many rows a SQL query would return if it was run.
- *
- * This uses a COUNT * on a the @a sql_query as a sub-statement.
- * Be careful not to include ORDER BY clauses in the supplied SQL query, because that would make it unnecessarily slow.
- *
- * @sql_query A SQL query.
- * @result The number of rows.
- */
-static Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_count_rows(const Glib::RefPtr<const Gnome::Gda::SqlBuilder>& sql_query)
-{
- Glib::RefPtr<Gnome::Gda::SqlBuilder> result;
-
- if(!sql_query)
- {
- std::cerr << G_STRFUNC << ": sql_query was null." << std::endl;
- return result;
- }
-
- result = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
-
- //Note that the alias is just because the SQL syntax requires it - we get an error if we don't use it.
- //Be careful not to include ORDER BY clauses in this, because that would make it unnecessarily slow:
- const guint target_id = result->add_sub_select( sql_query->get_sql_statement() );
- result->select_add_target_id(target_id, "glomarbitraryalias");
-
- const Gnome::Gda::SqlBuilder::Id id_function = result->add_function("COUNT", result->add_id("*"));
- result->add_field_value_id(id_function);
-
- return result;
-}
-
int count_rows_returned_by(const Glib::RefPtr<const Gnome::Gda::SqlBuilder>& sql_query)
{
if(!sql_query)
@@ -1853,7 +1822,7 @@ int count_rows_returned_by(const Glib::RefPtr<const Gnome::Gda::SqlBuilder>& sql
}
const Glib::RefPtr<const Gnome::Gda::SqlBuilder> builder =
- build_sql_select_count_rows(sql_query);
+ Utils::build_sql_select_count_rows(sql_query);
int result = 0;
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 6d10dc6..792f8fb 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -216,6 +216,36 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_with_where_clause(c
return build_sql_select_with_where_clause(table_name, constFieldsToGet, where_clause, extra_join, sort_clause, limit);
}
+/** Build a SQL query to discover how many rows a SQL query would return if it was run.
+ *
+ * This uses a COUNT * on a the @a sql_query as a sub-statement.
+ * Be careful not to include ORDER BY clauses in the supplied SQL query, because that would make it unnecessarily slow.
+ *
+ * @sql_query A SQL query.
+ * @result The number of rows.
+ */
+Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_count_rows(const Glib::RefPtr<const Gnome::Gda::SqlBuilder>& sql_query)
+{
+ Glib::RefPtr<Gnome::Gda::SqlBuilder> result;
+
+ if(!sql_query)
+ {
+ std::cerr << G_STRFUNC << ": sql_query was null." << std::endl;
+ return result;
+ }
+
+ result = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
+
+ //Note that the alias is just because the SQL syntax requires it - we get an error if we don't use it.
+ //Be careful not to include ORDER BY clauses in this, because that would make it unnecessarily slow:
+ const guint target_id = result->add_sub_select( sql_query->get_sql_statement() );
+ result->select_add_target_id(target_id, "glomarbitraryalias");
+
+ const Gnome::Gda::SqlBuilder::Id id_function = result->add_function("COUNT", result->add_id("*"));
+ result->add_field_value_id(id_function);
+
+ return result;
+}
typedef std::list< sharedptr<const UsesRelationship> > type_list_relationships;
diff --git a/glom/libglom/utils.h b/glom/libglom/utils.h
index 6f46c2e..b3f6c39 100644
--- a/glom/libglom/utils.h
+++ b/glom/libglom/utils.h
@@ -113,6 +113,17 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_with_key(
const type_sort_clause& sort_clause = type_sort_clause(),
guint limit = 0);
+//Note: This is not used by glom itself, but it is used by java-libglom.
+/** Build a SQL query to discover how many rows a SQL query would return if it was run.
+ *
+ * This uses a COUNT * on a the @a sql_query as a sub-statement.
+ * Be careful not to include ORDER BY clauses in the supplied SQL query, because that would make it unnecessarily slow.
+ *
+ * @sql_query A SQL query.
+ * @result The number of rows.
+ */
+Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_count_rows(const Glib::RefPtr<const Gnome::Gda::SqlBuilder>& sql_query);
+
Gnome::Gda::SqlExpr get_find_where_clause_quick(const Document* document, const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search);
typedef std::list<Gnome::Gda::Value> type_list_values;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]