[glom/glom-1-18] DbUtils: Add some parameter checks to the autoincrement methods.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-18] DbUtils: Add some parameter checks to the autoincrement methods.
- Date: Thu, 13 Oct 2011 18:16:56 +0000 (UTC)
commit 0bdbbb0c8658f288cd3b775d939ee44a20070070
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Oct 13 19:47:48 2011 +0200
DbUtils: Add some parameter checks to the autoincrement methods.
* glom/libglom/db_utils.cc: Otherwise we risk having an empty where clause,
and doing unwanted things to the entire table.
ChangeLog | 7 ++++++
glom/libglom/db_utils.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c524ae2..2852d7a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2011-10-13 Murray Cumming <murrayc murrayc com>
+ DbUtils: Add some parameter checks to the autoincrement methods.
+
+ * glom/libglom/db_utils.cc: Otherwise we risk having an empty where clause,
+ and doing unwanted things to the entire table.
+
+2011-10-13 Murray Cumming <murrayc murrayc com>
+
DbUtils: Avoid some repeated code.
* glom/libglom/db_utils.cc: Add a utility function for adding the where
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index d380ee4..a4064ef 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1376,6 +1376,18 @@ bool drop_column(const Glib::ustring& table_name, const Glib::ustring& field_nam
static void builder_set_where_autoincrement(const Glib::RefPtr<Gnome::Gda::SqlBuilder>& builder, const Glib::ustring& table_name, const Glib::ustring& field_name)
{
+ if(table_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": table_name is empty" << std::endl;
+ return;
+ }
+
+ if(field_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": field_name is empty" << std::endl;
+ return;
+ }
+
builder->set_where(builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
@@ -1387,6 +1399,18 @@ static void builder_set_where_autoincrement(const Glib::RefPtr<Gnome::Gda::SqlBu
Gnome::Gda::Value get_next_auto_increment_value(const Glib::ustring& table_name, const Glib::ustring& field_name)
{
+ if(table_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": table_name is empty" << std::endl;
+ return Gnome::Gda::Value();
+ }
+
+ if(field_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": field_name is empty" << std::endl;
+ return Gnome::Gda::Value();
+ }
+
const Gnome::Gda::Value result = DbUtils::auto_increment_insert_first_if_necessary(table_name, field_name);
double num_result = Conversions::get_double_for_gda_value_numeric(result);
@@ -1408,6 +1432,18 @@ Gnome::Gda::Value get_next_auto_increment_value(const Glib::ustring& table_name,
Gnome::Gda::Value auto_increment_insert_first_if_necessary(const Glib::ustring& table_name, const Glib::ustring& field_name)
{
+ if(table_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": table_name is empty" << std::endl;
+ return Gnome::Gda::Value();
+ }
+
+ if(field_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": field_name is empty" << std::endl;
+ return Gnome::Gda::Value();
+ }
+
Gnome::Gda::Value value;
//Check that the user is allowd to view and edit this table:
@@ -1470,6 +1506,18 @@ Gnome::Gda::Value auto_increment_insert_first_if_necessary(const Glib::ustring&
*/
static void recalculate_next_auto_increment_value(const Glib::ustring& table_name, const Glib::ustring& field_name)
{
+ if(table_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": table_name is empty" << std::endl;
+ return;
+ }
+
+ if(field_name.empty())
+ {
+ std::cerr << G_STRFUNC << ": field_name is empty" << std::endl;
+ return;
+ }
+
//Make sure that the row exists in the glom system table:
auto_increment_insert_first_if_necessary(table_name, field_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]