1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

feature #206: Tests moved to the new Sql engine

This commit is contained in:
Ruben S. Montero 2010-04-05 23:42:02 +02:00
parent 0d6e4eb723
commit a190d11e14
3 changed files with 23 additions and 52 deletions

View File

@ -39,7 +39,7 @@ const char * TestObjectSQL::db_bootstrap = "CREATE TABLE test_pool ("
/* -------------------------------------------------------------------------- */
int TestObjectSQL::unmarshall(int num, char **names, char ** values)
int TestObjectSQL::unmarshall(void * nil, int num, char **values, char **names)
{
if ((!values[OID]) ||
(!values[NUMBER]) ||
@ -58,38 +58,20 @@ int TestObjectSQL::unmarshall(int num, char **names, char ** values)
/* -------------------------------------------------------------------------- */
extern "C" int user_select_cb (
void * _user,
int num,
char ** values,
char ** names)
{
TestObjectSQL * user;
user = static_cast<TestObjectSQL *>(_user);
if (user == 0)
{
return -1;
}
return user->unmarshall(num,names,values);
};
/* -------------------------------------------------------------------------- */
int TestObjectSQL::select(SqliteDB *db)
int TestObjectSQL::select(SqlDB *db)
{
ostringstream oss;
int rc;
int boid;
set_callback(
static_cast<Callbackable::CallBack>(&TestObjectSQL::unmarshall),0);
oss << "SELECT * FROM " << table << " WHERE oid = " << oid;
boid = oid;
oid = -1;
rc = db->exec(oss, user_select_cb, (void *) this);
rc = db->exec(oss, this);
if ((rc != 0) || (oid != boid ))
{
@ -101,47 +83,37 @@ int TestObjectSQL::select(SqliteDB *db)
/* -------------------------------------------------------------------------- */
int TestObjectSQL::insert(SqliteDB *db)
int TestObjectSQL::insert(SqlDB *db)
{
return update(db);
}
/* -------------------------------------------------------------------------- */
int TestObjectSQL::update(SqliteDB *db)
int TestObjectSQL::update(SqlDB *db)
{
ostringstream oss;
int rc;
char * sql_number;
char * sql_text;
sql_number = sqlite3_mprintf("%d",number);
sql_text = sqlite3_mprintf("%q",text.c_str());
if ( sql_text == 0 )
{
sqlite3_free(sql_number);
return -1;
}
sql_text = db->escape_str(text.c_str());
oss << "INSERT OR REPLACE INTO " << table << " "<< db_names <<" VALUES ("
<< oid << ","
<< sql_number << ","
<< number << ","
<< "'" << sql_text << "')";
rc = db->exec(oss);
sqlite3_free(sql_number);
sqlite3_free(sql_text);
db->free_str(sql_text);
return rc;
}
/* -------------------------------------------------------------------------- */
int TestObjectSQL::drop(SqliteDB * db)
int TestObjectSQL::drop(SqlDB * db)
{
ostringstream oss;
int rc;

View File

@ -21,11 +21,6 @@
#include "PoolSQL.h"
using namespace std;
extern "C" int user_select_cb (void * _host,
int num,
char ** values,
char ** names);
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -44,15 +39,15 @@ public:
string text;
// OBJECTSQL INTERFACE
int unmarshall(int num, char **names, char ** values);
int unmarshall(void * nil, int num, char **names, char ** values);
int select(SqliteDB *db);
int select(SqlDB *db);
int insert(SqliteDB *db);
int insert(SqlDB *db);
int update(SqliteDB *db);
int update(SqlDB *db);
int drop(SqliteDB *db);
int drop(SqlDB *db);
// DATABASE IMPLEMENTATION
enum ColNames
@ -69,9 +64,12 @@ public:
static const char * table;
static void bootstrap(SqliteDB * db)
static void bootstrap(SqlDB * db)
{
db->exec(TestObjectSQL::db_bootstrap);
ostringstream oss;
oss.str(TestObjectSQL::db_bootstrap);
db->exec(oss,0);
};
};
@ -80,7 +78,7 @@ class TestPool : public PoolSQL
{
public:
TestPool(SqliteDB *db):PoolSQL(db,"test_pool"){};
TestPool(SqlDB *db):PoolSQL(db,"test_pool"){};
~TestPool(){};
TestObjectSQL * get(

View File

@ -27,6 +27,7 @@
#include "PoolSQL.h"
#include "TestPoolSQL.h"
#include "SqliteDB.h"
using namespace std;