From 82b383878df1d7785b9b33e38639f2ef03796b99 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 11 Jun 2010 18:56:25 +0200 Subject: [PATCH] feature #192: Fix tests for template_sql and better erase method --- src/template/Template.cc | 36 +++++++++++++++---------------- src/template/test/template_sql.cc | 9 ++++++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/template/Template.cc b/src/template/Template.cc index d13aab59bd..0ab226040f 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -45,7 +45,7 @@ pthread_mutex_t Template::mutex = PTHREAD_MUTEX_INITIALIZER; extern "C" { typedef struct yy_buffer_state * YY_BUFFER_STATE; - + extern FILE *template_in, *template_out; int template_parse(Template * tmpl, char ** errmsg); @@ -207,26 +207,26 @@ int Template::remove(const string& name, vector& values) int Template::erase(const string& name) { - int removed; - int num_attr; - vector attrs; + multimap::iterator i; - // Call remove - removed = remove(name, attrs); + pair< + multimap::iterator, + multimap::iterator + > index; + int j; - // Clear attrs - if ((num_attr = (int) attrs.size()) > 0) + index = attributes.equal_range(name); + + for ( i = index.first,j=0 ; i != index.second ; i++,j++ ) { - for (int i = 0; i < num_attr ; i++) - { - if (attrs[i] != 0) - { - delete attrs[i]; - } - } + Attribute * attr = i->second; + delete attr; } - return removed; + attributes.erase(index.first,index.second); + + return j; + } /* -------------------------------------------------------------------------- */ @@ -382,9 +382,9 @@ string& Template::to_str(string& str) const ostream& operator << (ostream& os, const Template& t) { string str; - + os << t.to_str(str); - + return os; } diff --git a/src/template/test/template_sql.cc b/src/template/test/template_sql.cc index 6965304441..208d927f1f 100644 --- a/src/template/test/template_sql.cc +++ b/src/template/test/template_sql.cc @@ -206,9 +206,14 @@ public: string att_name = "NEW_ATT"; string value = ""; + ostringstream db_bs( + "CREATE TABLE IF NOT EXISTS template_replace (id INTEGER, " + "name VARCHAR(256), type INTEGER, value TEXT, PRIMARY KEY(id,name))"); - TSQL t ("template",0); - TSQL t2("template",0); + CPPUNIT_ASSERT(db->exec(db_bs) == 0); + + TSQL t ("template_replace",0); + TSQL t2("template_replace",0); // Insert template t into the DB t.insert(db);