mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #192: Fix tests for template_sql and better erase method
This commit is contained in:
parent
9086162bbb
commit
82b383878d
@ -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<Attribute *>& values)
|
||||
|
||||
int Template::erase(const string& name)
|
||||
{
|
||||
int removed;
|
||||
int num_attr;
|
||||
vector<Attribute *> attrs;
|
||||
multimap<string, Attribute *>::iterator i;
|
||||
|
||||
// Call remove
|
||||
removed = remove(name, attrs);
|
||||
pair<
|
||||
multimap<string, Attribute *>::iterator,
|
||||
multimap<string, Attribute *>::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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user