Commit e0e6e9b2 authored by Murray Cumming's avatar Murray Cumming
Browse files

libglom: Added build_sql_update_with_where_clause().

	* glom/libglom/utils.[h|cc]: Added build_sql_update_with_where_clause().
	* glom/base_db.cc: set_field_value_in_database(): use it here instead
	of manually creating a SqlBuilder.
parent a16f1ffa
2011-10-29 Murray Cumming <murrayc@murrayc.com>
libglom: Added build_sql_update_with_where_clause().
* glom/libglom/utils.[h|cc]: Added build_sql_update_with_where_clause().
* glom/base_db.cc: set_field_value_in_database(): use it here instead
of manually creating a SqlBuilder.
2011-10-28 Murray Cumming <murrayc@murrayc.com>
Add a test for Image fields.
* Makefile_tests.am:
* tests/test_selfhosting_new_then_image.cc: Add a test to read an image field
value, though this currently fails.
I will later add a write-then-read test.
2011-10-28 Murray Cumming <murrayc@murrayc.com>
Add a test for Image fields.
......
......@@ -1148,13 +1148,12 @@ bool Base_DB::set_field_value_in_database(const LayoutFieldInRecord& layoutfield
const Glib::ustring field_name = field_in_record.m_field->get_name();
if(!field_name.empty()) //This should not happen.
{
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
builder->set_table(field_in_record.m_table_name);
builder->add_field_value_as_value(field_in_record.m_field->get_name(), field_value);
builder->set_where(
builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
builder->add_field_id(field_in_record.m_key->get_name(), field_in_record.m_table_name),
builder->add_expr_as_value(field_in_record.m_key_value)));
const Gnome::Gda::SqlExpr where_clause =
Utils::build_simple_where_expression(field_in_record.m_table_name,
field_in_record.m_key, field_in_record.m_key_value);
const Glib::RefPtr<const Gnome::Gda::SqlBuilder> builder =
Utils::build_sql_update_with_where_clause(field_in_record.m_table_name,
field_in_record.m_field, field_value, where_clause);
try //TODO: The exceptions are probably already handled by query_execute(
{
......
......@@ -1148,6 +1148,48 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(const Document* document,
}
}
Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_update_with_where_clause(
const Glib::ustring& table_name,
const sharedptr<const Field>& field, const Gnome::Gda::Value& value,
const Gnome::Gda::SqlExpr& where_clause)
{
Glib::RefPtr<Gnome::Gda::SqlBuilder> builder;
if(!field || field->get_name().empty())
{
std::cerr << "field was null or its name was empty." << std::endl;
return builder;
}
if(table_name.empty())
{
std::cerr << "table_name was empty." << std::endl;
return builder;
}
//Build the whole SQL statement:
try
{
builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
builder->set_table(table_name);
builder->add_field_value_as_value(field->get_name(), value);
//Add the WHERE clause:
if(!where_clause.empty())
{
const int id = builder->import_expression(where_clause);
builder->set_where(id);
}
}
catch(const Glib::Error& ex)
{
std::cerr << G_STRFUNC << ": Exception: " << ex.what() << std::endl;
}
return builder;
}
bool Utils::delete_directory(const Glib::RefPtr<Gio::File>& directory)
{
if(!(directory->query_exists()))
......
......@@ -126,6 +126,13 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_select_count_rows(const Glib::Ref
Gnome::Gda::SqlExpr get_find_where_clause_quick(const Document* document, const Glib::ustring& table_name, const Gnome::Gda::Value& quick_search);
/** Generate a SQL statement to UPDATE field values,
*/
Glib::RefPtr<Gnome::Gda::SqlBuilder> build_sql_update_with_where_clause(
const Glib::ustring& table_name,
const sharedptr<const Field>& field, const Gnome::Gda::Value& value,
const Gnome::Gda::SqlExpr& where_clause);
typedef std::list<Gnome::Gda::Value> type_list_values;
typedef std::list< std::pair<Gnome::Gda::Value, type_list_values> > type_list_values_with_second; //TODO: Rename this now that we have more than just 1 extra field.
type_list_values_with_second get_choice_values_all(const Document* document, const sharedptr<const LayoutItem_Field>& field);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment