Changeset 216
- Timestamp:
- 11/12/08 15:33:14 (8 weeks ago)
- Location:
- one/branches/DEVELOPMENT/VirtualNetworkManager
- Files:
-
- 3 modified
-
include/Attribute.h (modified) (3 diffs)
-
include/TemplateSQL.h (modified) (1 diff)
-
src/template/TemplateSQL.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
one/branches/DEVELOPMENT/VirtualNetworkManager/include/Attribute.h
r110 r216 34 34 public: 35 35 36 Attribute( string& aname):attribute_name(aname)36 Attribute(const string& aname):attribute_name(aname) 37 37 { 38 38 transform ( … … 105 105 public: 106 106 107 SingleAttribute( string& name):Attribute(name){};108 109 SingleAttribute( string& name,string& value):107 SingleAttribute(const string& name):Attribute(name){}; 108 109 SingleAttribute(const string& name, const string& value): 110 110 Attribute(name),attribute_value(value){}; 111 111 112 SingleAttribute(const char * name, string& value):112 SingleAttribute(const char * name, const string& value): 113 113 Attribute(name),attribute_value(value){}; 114 114 … … 170 170 public: 171 171 172 VectorAttribute( string& name):Attribute(name){};173 174 VectorAttribute( string& name,map<string,string>& value):172 VectorAttribute(const string& name):Attribute(name){}; 173 174 VectorAttribute(const string& name,const map<string,string>& value): 175 175 Attribute(name),attribute_value(value){}; 176 176 -
one/branches/DEVELOPMENT/VirtualNetworkManager/include/TemplateSQL.h
r65 r216 93 93 * @param value of the new attribute. 94 94 */ 95 int replace_attribute(SqliteDB * db, string& name, string& value); 95 int replace_attribute(SqliteDB * db, const string& name, const string& value); 96 97 /** 98 * Inserts single attribute 99 * @param db pointer to the database. 100 * @param name of the attribute. 101 * @param value of the attribute. 102 */ 103 int insert_attribute(SqliteDB * db, const string& name, const string& value); 104 105 /** 106 * Inserts vector attribute 107 * @param db pointer to the database. 108 * @param name of the attribute. 109 * @param values of the attribute. 110 */ 111 int insert_attribute(SqliteDB * db, 112 const string& name, 113 const map<string, string>& values); 114 115 /** 116 * Removes all occurences of a given attribute (SINGLE OR VECTOR) 117 * @param db pointer to the database. 118 * @param name of the attribute. 119 */ 120 int delete_attribute(SqliteDB * db, const string& name); 96 121 }; 97 122 -
one/branches/DEVELOPMENT/VirtualNetworkManager/src/template/TemplateSQL.cc
r65 r216 245 245 int TemplateSQL::replace_attribute( 246 246 SqliteDB * db, 247 string&name,248 string&value)247 const string& name, 248 const string& value) 249 249 { 250 250 ostringstream oss; … … 253 253 multimap<string, Attribute *>::const_iterator i; 254 254 Attribute * attribute; 255 256 string _name = name; 257 string _value = value; 255 258 256 259 if ( id == -1 || name.empty() || name.empty() ) … … 288 291 } 289 292 290 attribute = new SingleAttribute( name,value);293 attribute = new SingleAttribute(_name,_value); 291 294 292 295 attributes.insert(make_pair(attribute->name(),attribute)); … … 303 306 /* -------------------------------------------------------------------------- */ 304 307 /* -------------------------------------------------------------------------- */ 308 309 int TemplateSQL::insert_attribute(SqliteDB * db, 310 const string& name, 311 const string& value) 312 { 313 ostringstream oss; 314 315 Attribute * attribute; 316 317 318 attribute = new SingleAttribute(name,value); 319 320 attributes.insert(make_pair(attribute->name(),attribute)); 321 322 oss.str(""); 323 324 oss << "INSERT INTO " << table << " " << db_names 325 << " VALUES (" << id << ",'" << name << "'," << 326 Attribute::SIMPLE <<",'" << value << "')"; 327 328 return db->exec(oss); 329 } 330 331 /* -------------------------------------------------------------------------- */ 332 /* -------------------------------------------------------------------------- */ 333 334 int TemplateSQL::insert_attribute(SqliteDB * db, 335 const string& name, 336 const map<string, string>& values) 337 { 338 ostringstream oss; 339 340 Attribute * attribute; 341 string * attr; 342 343 attribute = new VectorAttribute(name,values); 344 345 attributes.insert(make_pair(attribute->name(),attribute)); 346 347 oss.str(""); 348 349 attr = attribute->marshall(); 350 351 if ( attr == 0 ) 352 { 353 return -1; 354 } 355 356 oss << "INSERT OR REPLACE INTO " << table << " " << db_names 357 << " VALUES (" << id << ",'" << name << "',"<< Attribute::VECTOR <<",'" 358 << *attr << "')"; 359 360 return db->exec(oss); 361 } 362 363 /* -------------------------------------------------------------------------- */ 364 /* -------------------------------------------------------------------------- */ 365 366 int TemplateSQL::delete_attribute(SqliteDB * db, const string& name) 367 { 368 ostringstream oss; 369 int rc; 370 371 multimap<string, Attribute *>::const_iterator i; 372 373 i = attributes.find(name); 374 375 if ( i != attributes.end() ) //attribute exists 376 { 377 oss << "DELETE FROM " << table << " WHERE id=" << id 378 << " AND name='" << name << "'"; 379 380 rc = db->exec(oss); 381 382 if ( rc != 0 ) 383 { 384 return rc; 385 } 386 387 attributes.erase(name); 388 } 389 390 return 0; 391 }
