1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

feature #206: Isolation of INSERT and REPLACE SQL queries for History objects

This commit is contained in:
Constantino Vázquez Blanco 2010-05-03 19:13:37 +02:00
parent f91f9de99c
commit 56e49136e0
2 changed files with 51 additions and 14 deletions

View File

@ -173,24 +173,28 @@ private:
* @return 0 on success.
*/
int select(SqlDB * db);
/**
* Removes the all history records from the DB
* @param db pointer to the database.
* @return 0 on success.
*/
int drop(SqlDB * db);
/**
* Updates the history record
* @param db pointer to the database.
* @return 0 on success.
*/
int update(SqlDB * db)
{
return insert(db);
}
int update(SqlDB * db);
/**
* Removes the all history records from the DB
* @param db pointer to the database.
* @return 0 on success.
*/
int drop(SqlDB * db);
/**
* Execute an INSERT or REPLACE Sql query.
* @param db The SQL DB
* @param replace Execute an INSERT or a REPLACE
* @return 0 on success
*/
int insert_replace(SqlDB *db, bool replace);
/**
* Callback function to unmarshall a history object (History::select)

View File

@ -135,6 +135,30 @@ void History::non_persistent_data()
/* -------------------------------------------------------------------------- */
int History::insert(SqlDB * db)
{
int rc;
rc = insert_replace(db, false);
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int History::update(SqlDB * db)
{
int rc;
rc = insert_replace(db, true);
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int History::insert_replace(SqlDB *db, bool replace)
{
ostringstream oss;
@ -177,8 +201,17 @@ int History::insert(SqlDB * db)
{
goto error_tm;
}
if(replace)
{
oss << "REPLACE";
}
else
{
oss << "INSERT";
}
oss << "INSERT OR REPLACE INTO " << table << " "<< db_names <<" VALUES ("<<
oss << " INTO " << table << " "<< db_names <<" VALUES ("<<
oid << "," <<
seq << "," <<
"'" << sql_hostname << "',"<<