[glom] libglom: sqlbuilder_get_full_query(): Improve the result.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] libglom: sqlbuilder_get_full_query(): Improve the result.
- Date: Mon, 31 Oct 2011 08:37:15 +0000 (UTC)
commit a61a23dc0ecd83c8251ff34727597734bff0f25e
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Oct 31 09:37:00 2011 +0100
libglom: sqlbuilder_get_full_query(): Improve the result.
* glom/libglom/utils.cc: Use the GdaConnection's statement_to_sql()
instead of just GdaStatement's to_sql() so we a) have correct quoting,
and b) use the server's specific SQL dialect.
ChangeLog | 8 +++++++
glom/libglom/db_utils.cc | 1 -
glom/libglom/utils.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 56 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2bb6e54..dd78045 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-10-31 Murray Cumming <murrayc murrayc com>
+
+ libglom: sqlbuilder_get_full_query(): Improve the result.
+
+ * glom/libglom/utils.cc: Use the GdaConnection's statement_to_sql()
+ instead of just GdaStatement's to_sql() so we a) have correct quoting,
+ and b) use the server's specific SQL dialect.
+
2011-10-29 Murray Cumming <murrayc murrayc com>
Image fields test: Load data from a file and check setting and getting.
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index a8d7dc9..dee76d5 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -43,7 +43,6 @@ namespace DbUtils
static Glib::RefPtr<Gnome::Gda::Connection> get_connection()
{
-
sharedptr<SharedConnection> sharedconnection;
try
{
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index d5adbbd..e9429cb 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -1015,6 +1015,31 @@ bool Utils::file_exists(const Glib::RefPtr<Gio::File>& file)
}
}
+//TODO: This is a duplicate of the one in db_utils.cc:
+//Merge all db utilities into db_utils in glom 1.22:
+static Glib::RefPtr<Gnome::Gda::Connection> get_connection()
+{
+ sharedptr<SharedConnection> sharedconnection;
+ try
+ {
+ sharedconnection = ConnectionPool::get_and_connect();
+ }
+ catch (const Glib::Error& error)
+ {
+ std::cerr << G_STRFUNC << ": " << error.what() << std::endl;
+ }
+
+ if(!sharedconnection)
+ {
+ std::cerr << G_STRFUNC << ": No connection yet." << std::endl;
+ return Glib::RefPtr<Gnome::Gda::Connection>(0);
+ }
+
+ Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();
+
+ return gda_connection;
+}
+
std::string Utils::sqlbuilder_get_full_query(
const Glib::RefPtr<Gnome::Gda::Connection>& connection,
const Glib::ustring& query,
@@ -1029,7 +1054,10 @@ std::string Utils::sqlbuilder_get_full_query(
{
Glib::RefPtr<Gnome::Gda::Statement> stmt = parser->parse_string(query);
if(stmt)
- result = stmt->to_sql(params);
+ {
+ result = connection->statement_to_sql(stmt, params,
+ Gnome::Gda::STATEMENT_SQL_PARAMS_AS_VALUES | Gnome::Gda::STATEMENT_SQL_PRETTY);
+ }
}
}
catch(const Glib::Exception& ex)
@@ -1053,12 +1081,30 @@ std::string Utils::sqlbuilder_get_full_query(
std::string Utils::sqlbuilder_get_full_query(
const Glib::RefPtr<const Gnome::Gda::SqlBuilder>& builder)
{
+ Glib::RefPtr<Gnome::Gda::Connection> connection = get_connection();
+ if(!connection)
+ {
+ //TODO: Just use the correct provider, without an actual connection?
+ std::cerr << G_STRFUNC << ": There is no connection, so the SQL statement might not be created correctly." << std::endl;
+ }
+
Glib::ustring result = "glom_query_not_parsed";
try
{
Glib::RefPtr<Gnome::Gda::Statement> stmt = builder->get_statement();
- if(stmt)
+ if(!stmt)
+ {
+ std::cerr << G_STRFUNC << ": builder->get_statement() failed." << std::endl;
+ return result;
+ }
+
+ if(connection)
+ {
+ result = connection->statement_to_sql(stmt,
+ Gnome::Gda::STATEMENT_SQL_PARAMS_AS_VALUES | Gnome::Gda::STATEMENT_SQL_PRETTY);
+ }
+ else
result = stmt->to_sql();
}
catch(const Gnome::Gda::SqlError& ex)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]