[glom/glom-1-18] Find: Use backend-specific LIKE or ILIKE operator instead of =.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-18] Find: Use backend-specific LIKE or ILIKE operator instead of =.
- Date: Thu, 23 Jun 2011 19:50:50 +0000 (UTC)
commit 7a3dbb26d03bb6d02455e0aab9709a773501b52f
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jun 23 21:17:33 2011 +0200
Find: Use backend-specific LIKE or ILIKE operator instead of =.
* glom/libglom/connectionpool.[h|cc]:
* glom/libglom/connectionpool_backends/backend.h:
* glom/libglom/connectionpool_backends/postgres.h:
* glom/libglom/connectionpool_backends/sqlite.h:
get_string_find_operator(): Return the Gnome::Gda operator enum
instead of the operator as a string.
* glom/libglom/data_structure/field.[h|cc]: sql_find_operator():
Likewise, return the Gnome::Gda operator enum.
* glom/libglom/utils.cc: get_find_where_clause_quick():
* glom/mode_data/box_data.cc: get_find_where_clause():
Use Field::sql_find_operator() and Field::sql_find(), as per
the TODO comments.
This was code that I forgot to change properly when porting to
use Gnome::Gda::SqlBuilder, so this has been broken since
Glom 1.16.
Find still does not work.
Conflicts:
ChangeLog
glom/frame_glom.cc
ChangeLog | 23 +++++++++++++++++
glom/frame_glom.cc | 3 +-
glom/libglom/connectionpool.cc | 2 +-
glom/libglom/connectionpool.h | 2 +-
glom/libglom/connectionpool_backends/backend.h | 2 +-
glom/libglom/connectionpool_backends/postgres.h | 2 +-
glom/libglom/connectionpool_backends/sqlite.h | 2 +-
glom/libglom/data_structure/field.cc | 6 ++--
glom/libglom/data_structure/field.h | 2 +-
glom/libglom/utils.cc | 31 ++++++++++++++---------
glom/mode_data/box_data.cc | 6 ++--
11 files changed, 56 insertions(+), 25 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 7f750b4..6f064ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,27 @@
+2011-06-23 Murray Cumming <murrayc murrayc com>
+
+ Find: Use backend-specific LIKE or ILIKE operator instead of =.
+
+ * glom/libglom/connectionpool.[h|cc]:
+ * glom/libglom/connectionpool_backends/backend.h:
+ * glom/libglom/connectionpool_backends/postgres.h:
+ * glom/libglom/connectionpool_backends/sqlite.h:
+ get_string_find_operator(): Return the Gnome::Gda operator enum
+ instead of the operator as a string.
+ * glom/libglom/data_structure/field.[h|cc]: sql_find_operator():
+ Likewise, return the Gnome::Gda operator enum.
+ * glom/libglom/utils.cc: get_find_where_clause_quick():
+ * glom/mode_data/box_data.cc: get_find_where_clause():
+ Use Field::sql_find_operator() and Field::sql_find(), as per
+ the TODO comments.
+
+ This was code that I forgot to change properly when porting to
+ use Gnome::Gda::SqlBuilder, so this has been broken since
+ Glom 1.16.
+ Find still does not work.
+
1.18.2:
+=======
2011-06-17 Murray Cumming <murrayc murrayc com>
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 8903cfe..c383f05 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -1471,7 +1471,8 @@ void Frame_Glom::on_button_quickfind()
else
{
const Gnome::Gda::SqlExpr where_clause = Utils::get_find_where_clause_quick(get_document(), m_table_name, Gnome::Gda::Value(criteria));
- //std::cout << "Frame_Glom::on_button_quickfind(): where_clause=" << where_clause << std::endl;
+
+ //std::cout << "debug: " << G_STRFUNC << ": where_clause=" << where_clause.serialize() << std::endl;
on_notebook_find_criteria(where_clause);
}
}
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index a3ce2e8..f7f628a 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -514,7 +514,7 @@ const FieldTypes* ConnectionPool::get_field_types() const
return m_pFieldTypes;
}
-Glib::ustring ConnectionPool::get_string_find_operator() const
+Gnome::Gda::SqlOperatorType ConnectionPool::get_string_find_operator() const
{
g_assert(m_backend.get());
return m_backend->get_string_find_operator();
diff --git a/glom/libglom/connectionpool.h b/glom/libglom/connectionpool.h
index b1577b7..88a7550 100644
--- a/glom/libglom/connectionpool.h
+++ b/glom/libglom/connectionpool.h
@@ -191,7 +191,7 @@ public:
Field::sql_format get_sql_format() const;
const FieldTypes* get_field_types() const;
- Glib::ustring get_string_find_operator() const;
+ Gnome::Gda::SqlOperatorType get_string_find_operator() const;
typedef Backend::InitErrors InitErrors;
diff --git a/glom/libglom/connectionpool_backends/backend.h b/glom/libglom/connectionpool_backends/backend.h
index c72cd99..04f6f82 100644
--- a/glom/libglom/connectionpool_backends/backend.h
+++ b/glom/libglom/connectionpool_backends/backend.h
@@ -115,7 +115,7 @@ protected:
* TODO: Maybe we can use libgda to construct the expression, so we don't
* need this function.
*/
- virtual Glib::ustring get_string_find_operator() const = 0;
+ virtual Gnome::Gda::SqlOperatorType get_string_find_operator() const = 0;
/** This specifies the database schema which contains the non-internal
* tables. This is used to speedup the libgda meta store update by only
diff --git a/glom/libglom/connectionpool_backends/postgres.h b/glom/libglom/connectionpool_backends/postgres.h
index d0881a7..36cbdaf 100644
--- a/glom/libglom/connectionpool_backends/postgres.h
+++ b/glom/libglom/connectionpool_backends/postgres.h
@@ -65,7 +65,7 @@ public:
private:
virtual Field::sql_format get_sql_format() const { return Field::SQL_FORMAT_POSTGRES; }
virtual bool supports_remote_access() const { return true; }
- virtual Glib::ustring get_string_find_operator() const { return "ILIKE"; } // ILIKE is a postgres extension for locale-dependent case-insensitive matches.
+ virtual Gnome::Gda::SqlOperatorType get_string_find_operator() const { return Gnome::Gda::SQL_OPERATOR_TYPE_LIKE; } //TODO: Use ILIKE ILIKE is a postgres extension for locale-dependent case-insensitive matches.
virtual const char* get_public_schema_name() const { return "public"; }
virtual bool change_columns(const Glib::RefPtr<Gnome::Gda::Connection>& connection, const Glib::ustring& table_name, const type_vec_const_fields& old_fields, const type_vec_const_fields& new_fields, std::auto_ptr<Glib::Error>& error);
diff --git a/glom/libglom/connectionpool_backends/sqlite.h b/glom/libglom/connectionpool_backends/sqlite.h
index d4ae24b..f9d3b2d 100644
--- a/glom/libglom/connectionpool_backends/sqlite.h
+++ b/glom/libglom/connectionpool_backends/sqlite.h
@@ -40,7 +40,7 @@ public:
private:
virtual Field::sql_format get_sql_format() const { return Field::SQL_FORMAT_SQLITE; }
virtual bool supports_remote_access() const { return false; }
- virtual Glib::ustring get_string_find_operator() const { return "LIKE"; }
+ virtual Gnome::Gda::SqlOperatorType get_string_find_operator() const { return Gnome::Gda::SQL_OPERATOR_TYPE_LIKE; }
virtual const char* get_public_schema_name() const { return "main"; }
bool add_column_to_server_operation(const Glib::RefPtr<Gnome::Gda::ServerOperation>& operation, GdaMetaTableColumn* column, unsigned int i, std::auto_ptr<Glib::Error>& error);
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index 34238b4..ef0e019 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -398,7 +398,7 @@ Glib::ustring Field::sql_find(const Gnome::Gda::Value& value) const
}
}
-Glib::ustring Field::sql_find_operator() const
+Gnome::Gda::SqlOperatorType Field::sql_find_operator() const
{
switch(get_glom_type())
{
@@ -408,7 +408,7 @@ Glib::ustring Field::sql_find_operator() const
if(connection_pool && connection_pool->get_backend())
return connection_pool->get_string_find_operator();
else
- return "LIKE"; // Default
+ return Gnome::Gda::SQL_OPERATOR_TYPE_LIKE; // Default
break;
}
case(TYPE_DATE):
@@ -417,7 +417,7 @@ Glib::ustring Field::sql_find_operator() const
case(TYPE_BOOLEAN):
default:
{
- return "=";
+ return Gnome::Gda::SQL_OPERATOR_TYPE_EQ;
break;
}
}
diff --git a/glom/libglom/data_structure/field.h b/glom/libglom/data_structure/field.h
index bcda5c8..4878464 100644
--- a/glom/libglom/data_structure/field.h
+++ b/glom/libglom/data_structure/field.h
@@ -198,7 +198,7 @@ public:
/** Get a suitable operator to use when finding records.
* For instance, == for numbers, or LIKE for text.
*/
- Glib::ustring sql_find_operator() const;
+ Gnome::Gda::SqlOperatorType sql_find_operator() const;
Glib::ustring get_calculation() const;
void set_calculation(const Glib::ustring& calculation);
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 9879c73..4d5147f 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -1027,6 +1027,10 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(const Document* document,
Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
builder->select_add_target(table_name);
+ //We need to add some fields to select,
+ //because otherwise the SqlBuilder would not contain a valid query.
+ builder->select_add_field("*", table_name);
+
if(!document)
{
std::cerr << G_STRFUNC << ": document was null." << std::endl;
@@ -1036,7 +1040,7 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(const Document* document,
//TODO: Cache the list of all fields, as well as caching (m_Fields) the list of all visible fields:
const Document::type_vec_fields fields = document->get_table_fields(table_name);
- guint previous_and_id = 0;
+ guint previous_id = 0;
typedef std::vector< sharedptr<LayoutItem_Field> > type_vecLayoutFields;
type_vecLayoutFields fieldsToGet;
for(Document::type_vec_fields::const_iterator iter = fields.begin(); iter != fields.end(); ++iter)
@@ -1053,28 +1057,31 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(const Document* document,
if(use_this_field)
{
- const guint eq_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ, //TODO: Ue field->sql_find_operator().
+ //std::cout << "Using field: " << field->get_name() << std::endl;
+ const guint eq_id = builder->add_cond(field->sql_find_operator(),
builder->add_field_id(field->get_name(), table_name),
- builder->add_expr(quick_search)); //Use field->sql_find(quick_search);
+ builder->add_expr( field->sql_find(quick_search) )); //sql_find() modifies the value for the operator.
- guint and_id = 0;
- if(previous_and_id)
+ if(previous_id)
{
- and_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
- previous_and_id, eq_id);
+ const guint or_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_OR,
+ previous_id, eq_id);
+ previous_id = or_id;
}
-
- previous_and_id = and_id;
+ else
+ previous_id = eq_id;
}
}
- if(previous_and_id)
+ if(previous_id)
{
- builder->set_where(previous_and_id); //This might be unnecessary.
- return builder->export_expression(previous_and_id);
+ builder->set_where(previous_id); //This might be unnecessary.
+ //std::cout << G_STRFUNC << ": builder: " << sqlbuilder_get_full_query(builder) << std::endl;
+ return builder->export_expression(previous_id);
}
else
{
+ std::cerr << G_STRFUNC << ": Returning null SqlExpr" << std::endl;
return Gnome::Gda::SqlExpr();
}
}
diff --git a/glom/mode_data/box_data.cc b/glom/mode_data/box_data.cc
index 04bb471..cc5ba76 100644
--- a/glom/mode_data/box_data.cc
+++ b/glom/mode_data/box_data.cc
@@ -112,14 +112,14 @@ Gnome::Gda::SqlExpr Box_Data::get_find_where_clause() const
if(use_this_field)
{
- const guint cond_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ, //TODO: Use field->sql_find_operator()
+ const guint cond_id = builder->add_cond(field->sql_find_operator(),
builder->add_field_id(field->get_name(), m_table_name),
- builder->add_expr(data));
+ builder->add_expr( field->sql_find(data) ));
//And with previous condition, if any:
if(where_cond_id)
{
- where_cond_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND, //TODO: Use field->sql_find_operator()
+ where_cond_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
where_cond_id,
cond_id);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]