diff --git a/include/History.h b/include/History.h index c6bf8da437..fd9fdd0d40 100644 --- a/include/History.h +++ b/include/History.h @@ -103,6 +103,8 @@ private: static const char * db_names; + static const char * extended_db_names; + static const char * db_bootstrap; void non_persistent_data(); diff --git a/include/Image.h b/include/Image.h index b6f84cb7d7..ef49565214 100644 --- a/include/Image.h +++ b/include/Image.h @@ -479,6 +479,8 @@ protected: LIMIT = 11 }; + static const char * extended_db_names; + static const char * db_names; static const char * db_bootstrap; diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 38333c1fad..1dae2a5ab0 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1013,6 +1013,8 @@ protected: static const char * db_names; + static const char * extended_db_names; + static const char * db_bootstrap; /** diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 33172da74e..d73b60c80b 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -365,6 +365,8 @@ protected: static const char * db_names; + static const char * extended_db_names; + static const char * db_bootstrap; /** diff --git a/src/host/Host.cc b/src/host/Host.cc index bd44089dce..a37d8c478c 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -52,8 +52,8 @@ Host::~Host(){} const char * Host::table = "host_pool"; -const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad," - "tm_mad,last_mon_time, cluster, template)"; +const char * Host::db_names = "oid,host_name,state,im_mad,vm_mad," + "tm_mad,last_mon_time, cluster, template"; const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool (" "oid INTEGER PRIMARY KEY,host_name VARCHAR(256), state INTEGER," @@ -109,7 +109,7 @@ int Host::select(SqlDB *db) set_callback(static_cast(&Host::select_cb)); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; + oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid; boid = oid; oid = -1; @@ -275,7 +275,7 @@ int Host::insert_replace(SqlDB *db, bool replace) // Construct the SQL statement to Insert or Replace - oss <<" INTO "<< table <<" "<< db_names <<" VALUES (" + oss <<" INTO "<< table <<" ("<< db_names <<") VALUES (" << oid << "," << "'" << sql_hostname << "'," << state << "," diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index 1a889c3d74..59990790a4 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -265,7 +265,8 @@ int HostPool::dump(ostringstream& oss, const string& where) set_callback(static_cast(&HostPool::dump_cb), static_cast(&oss)); - cmd << "SELECT * FROM " << Host::table << " JOIN " << HostShare::table + cmd << "SELECT " << Host::db_names << " , " << HostShare::db_names + << " FROM " << Host::table << " JOIN " << HostShare::table << " ON " << Host::table << ".oid = " << HostShare::table << ".hid"; if ( !where.empty() ) diff --git a/src/host/HostShare.cc b/src/host/HostShare.cc index 825536a652..9a2c2ed25d 100644 --- a/src/host/HostShare.cc +++ b/src/host/HostShare.cc @@ -56,12 +56,12 @@ HostShare::HostShare( const char * HostShare::table = "host_shares"; -const char * HostShare::db_names = "(hid," +const char * HostShare::db_names = "hid," "disk_usage, mem_usage, cpu_usage," "max_disk, max_mem, max_cpu," "free_disk, free_mem, free_cpu," "used_disk, used_mem, used_cpu," - "running_vms)"; + "running_vms"; const char * HostShare::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_shares(" "hid INTEGER PRIMARY KEY," @@ -177,7 +177,7 @@ int HostShare::select(SqlDB * db) set_callback(static_cast(&HostShare::select_cb)); - oss << "SELECT * FROM " << table << " WHERE hid = " << hsid; + oss << "SELECT "<< db_names << " FROM " << table << " WHERE hid = " << hsid; bhsid = hsid; hsid = -1; @@ -240,7 +240,7 @@ int HostShare::insert_replace(SqlDB *db, bool replace) oss << "INSERT"; } - oss << " INTO " << table << " "<< db_names <<" VALUES (" + oss << " INTO " << table << " ("<< db_names <<") VALUES (" << hsid << "," << disk_usage <<","<< mem_usage <<","<< cpu_usage<< "," << max_disk <<","<< max_mem <<","<< max_cpu << "," diff --git a/src/image/Image.cc b/src/image/Image.cc index 3924c389b2..7351500e56 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -66,8 +66,13 @@ Image::~Image() const char * Image::table = "image_pool"; -const char * Image::db_names = "(oid, uid, name, type, public, persistent, regtime, " - "source, state, running_vms, template)"; +const char * Image::db_names = "oid, uid, name, type, public, persistent, regtime, " + "source, state, running_vms, template"; + +const char * Image::extended_db_names = "image_pool.oid, image_pool.uid, " + "image_pool.name, image_pool.type, image_pool.public, " + "image_pool.persistent, image_pool.regtime, image_pool.source, " + "image_pool.state, image_pool.running_vms, image_pool.template"; const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool (" "oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(128), " @@ -127,7 +132,7 @@ int Image::select(SqlDB *db) set_callback(static_cast(&Image::select_cb)); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; + oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid; boid = oid; oid = -1; @@ -332,7 +337,7 @@ int Image::insert_replace(SqlDB *db, bool replace) // Construct the SQL statement to Insert or Replace - oss <<" INTO "<< table <<" "<< db_names <<" VALUES (" + oss <<" INTO "<< table <<" ("<< db_names <<") VALUES (" << oid << "," << uid << "," << "'" << sql_name << "'," diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index e85a563e4b..e0542d157b 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -144,7 +144,7 @@ int ImagePool::dump(ostringstream& oss, const string& where) set_callback(static_cast(&ImagePool::dump_cb), static_cast(&oss)); - cmd << "SELECT " << Image::table << ".*, user_pool.user_name FROM " + cmd << "SELECT "<< Image::extended_db_names << ", user_pool.user_name FROM " << Image::table << " LEFT OUTER JOIN (SELECT oid, user_name FROM user_pool) " << "AS user_pool ON " << Image::table << ".uid = user_pool.oid"; diff --git a/src/um/User.cc b/src/um/User.cc index 52a70f6bc1..a54d9a404b 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -50,7 +50,7 @@ User::~User(){}; const char * User::table = "user_pool"; -const char * User::db_names = "(oid,user_name,password,enabled)"; +const char * User::db_names = "oid,user_name,password,enabled"; const char * User::db_bootstrap = "CREATE TABLE IF NOT EXISTS user_pool (" "oid INTEGER PRIMARY KEY, user_name VARCHAR(256), password TEXT," @@ -91,7 +91,7 @@ int User::select(SqlDB *db) set_callback(static_cast(&User::select_cb)); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; + oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid; boid = oid; oid = -1; @@ -183,7 +183,7 @@ int User::insert_replace(SqlDB *db, bool replace) oss << "INSERT"; } - oss << " INTO " << table << " "<< db_names <<" VALUES (" + oss << " INTO " << table << " ("<< db_names <<") VALUES (" << oid << "," << "'" << sql_username << "'," << "'" << sql_password << "'," diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 1ed8d183d5..fb43aa8dcf 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -343,7 +343,7 @@ int UserPool::dump(ostringstream& oss, const string& where) set_callback(static_cast(&UserPool::dump_cb), static_cast(&oss)); - cmd << "SELECT * FROM " << User::table; + cmd << "SELECT " << User::db_names << " FROM " << User::table; if ( !where.empty() ) { diff --git a/src/vm/History.cc b/src/vm/History.cc index ca1c0ccff4..e2d7a05013 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -25,8 +25,14 @@ const char * History::table = "history"; -const char * History::db_names = "(vid,seq,host_name,vm_dir,hid,vm_mad,tm_mad,stime," - "etime,pstime,petime,rstime,retime,estime,eetime,reason)"; +const char * History::db_names = "vid,seq,host_name,vm_dir,hid,vm_mad,tm_mad,stime," + "etime,pstime,petime,rstime,retime,estime,eetime,reason"; + +const char * History::extended_db_names = + "history.vid, history.seq, history.host_name, history.vm_dir, history.hid, " + "history.vm_mad, history.tm_mad, history.stime, history.etime, " + "history.pstime, history.petime, history.rstime, history.retime, " + "history.estime, history.eetime, history.reason"; const char * History::db_bootstrap = "CREATE TABLE IF NOT EXISTS " "history (vid INTEGER," @@ -212,7 +218,7 @@ int History::insert_replace(SqlDB *db, bool replace) oss << "INSERT"; } - oss << " INTO " << table << " "<< db_names <<" VALUES ("<< + oss << " INTO " << table << " ("<< db_names <<") VALUES ("<< oid << "," << seq << "," << "'" << sql_hostname << "',"<< @@ -359,12 +365,13 @@ int History::select(SqlDB * db) if ( seq == -1) { - oss << "SELECT * FROM history WHERE vid = "<< oid << + oss << "SELECT " << db_names << " FROM history WHERE vid = "<< oid << " AND seq=(SELECT MAX(seq) FROM history WHERE vid = " << oid << ")"; } else { - oss << "SELECT * FROM history WHERE vid = "<< oid <<" AND seq = "<< seq; + oss << "SELECT " << db_names << " FROM history WHERE vid = " << oid + << " AND seq = " << seq; } set_callback(static_cast(&History::select_cb)); diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 6e0d37ed89..b69262176d 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -95,8 +95,14 @@ VirtualMachine::~VirtualMachine() const char * VirtualMachine::table = "vm_pool"; const char * VirtualMachine::db_names = - "(oid,uid,name,last_poll, state,lcm_state,stime,etime,deploy_id" - ",memory,cpu,net_tx,net_rx,last_seq, template)"; + "oid,uid,name,last_poll, state,lcm_state,stime,etime,deploy_id" + ",memory,cpu,net_tx,net_rx,last_seq, template"; + +const char * VirtualMachine::extended_db_names = + "vm_pool.oid, vm_pool.uid, vm_pool.name, vm_pool.last_poll, vm_pool.state, " + "vm_pool.lcm_state, vm_pool.stime, vm_pool.etime, vm_pool.deploy_id, " + "vm_pool.memory, vm_pool.cpu, vm_pool.net_tx, vm_pool.net_rx, " + "vm_pool.last_seq, vm_pool.template"; const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS " "vm_pool (" @@ -174,7 +180,7 @@ int VirtualMachine::select(SqlDB * db) set_callback( static_cast(&VirtualMachine::select_cb)); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; + oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid; boid = oid; oid = -1; @@ -598,7 +604,7 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace) oss << "INSERT"; } - oss << " INTO " << table << " "<< db_names <<" VALUES (" + oss << " INTO " << table << " ("<< db_names <<") VALUES (" << oid << "," << uid << "," << "'" << sql_name << "'," diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 19060e7140..5ad3355ecc 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -278,13 +278,14 @@ int VirtualMachinePool::dump( ostringstream& oss, &VirtualMachinePool::dump_extended_cb), static_cast(&oss)); - cmd << "SELECT " << VirtualMachine::table << ".*, user_pool.user_name, " - << History::table << ".* FROM " << VirtualMachine::table + cmd << "SELECT " << VirtualMachine::extended_db_names + << ", user_pool.user_name, " + << History::extended_db_names << " FROM " << VirtualMachine::table << " LEFT OUTER JOIN " << History::table << " ON " << VirtualMachine::table << ".oid = " << History::table << ".vid AND " << History::table << ".seq = " << VirtualMachine::table << ".last_seq LEFT OUTER JOIN (SELECT oid,user_name FROM user_pool) " - << "AS user_pool ON " << VirtualMachine::table << ".uid = user_pool.oid"; + << "AS user_pool ON "<< VirtualMachine::table << ".uid = user_pool.oid"; } else { @@ -292,7 +293,8 @@ int VirtualMachinePool::dump( ostringstream& oss, static_cast(&VirtualMachinePool::dump_cb), static_cast(&oss)); - cmd << "SELECT * FROM " << VirtualMachine::table; + cmd << "SELECT " << VirtualMachine::db_names << " FROM " + << VirtualMachine::table; } if ( state != -1 ) diff --git a/src/vnm/FixedLeases.cc b/src/vnm/FixedLeases.cc index 107b5af16b..3ef35e82bc 100644 --- a/src/vnm/FixedLeases.cc +++ b/src/vnm/FixedLeases.cc @@ -72,7 +72,7 @@ int FixedLeases::add(const string& ip, const string& mac, int vid, bool used) goto error_mac; } - oss << "INSERT INTO " << table << " "<< db_names <<" VALUES (" << + oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES (" << oid << "," << _ip << "," << _mac[Lease::PREFIX] << "," << diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index 60332c82b1..4fb52351d1 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -248,7 +248,7 @@ string& Leases::Lease::to_xml(string& str) const const char * Leases::table = "leases"; -const char * Leases::db_names = "(oid,ip,mac_prefix,mac_suffix,vid,used)"; +const char * Leases::db_names = "oid,ip,mac_prefix,mac_suffix,vid,used"; const char * Leases::db_bootstrap = "CREATE TABLE IF NOT EXISTS leases (" "oid INTEGER, ip BIGINT, mac_prefix BIGINT, mac_suffix BIGINT," @@ -310,7 +310,7 @@ int Leases::select(SqlDB * db) set_callback(static_cast(&Leases::select_cb)); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; + oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid; rc = db->exec(oss,this); diff --git a/src/vnm/RangedLeases.cc b/src/vnm/RangedLeases.cc index 0e2a49ce18..ef76145e96 100644 --- a/src/vnm/RangedLeases.cc +++ b/src/vnm/RangedLeases.cc @@ -136,7 +136,7 @@ int RangedLeases::add( int rc; //Insert the lease in the database - oss << "INSERT INTO " << table << " "<< db_names <<" VALUES ("<< + oss << "INSERT INTO " << table << " ("<< db_names <<") VALUES ("<< oid << "," << ip << "," << mac[Lease::PREFIX] << "," << diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 6b758f4740..2318d33c9e 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -70,7 +70,11 @@ VirtualNetwork::~VirtualNetwork() const char * VirtualNetwork::table = "network_pool"; const char * VirtualNetwork::db_names = - "(oid,uid,name,type,bridge,public,template)"; + "oid,uid,name,type,bridge,public,template"; + +const char * VirtualNetwork::extended_db_names = + "network_pool.oid, network_pool.uid, network_pool.name, network_pool.type, " + "network_pool.bridge, network_pool.public, network_pool.template"; const char * VirtualNetwork::db_bootstrap = "CREATE TABLE IF NOT EXISTS" " network_pool (" @@ -130,7 +134,7 @@ int VirtualNetwork::select(SqlDB * db) set_callback( static_cast(&VirtualNetwork::select_cb)); - oss << "SELECT * FROM " << table << " WHERE oid = " << oid; + oss << "SELECT " << db_names << " FROM " << table << " WHERE oid = " << oid; boid = oid; oid = -1; @@ -492,7 +496,7 @@ int VirtualNetwork::insert_replace(SqlDB *db, bool replace) oss << "INSERT"; } - oss << " INTO " << table << " "<< db_names <<" VALUES (" + oss << " INTO " << table << " (" << db_names << ") VALUES (" << oid << "," << uid << "," << "'" << sql_name << "'," diff --git a/src/vnm/VirtualNetworkPool.cc b/src/vnm/VirtualNetworkPool.cc index 217459c191..19c8a7513e 100644 --- a/src/vnm/VirtualNetworkPool.cc +++ b/src/vnm/VirtualNetworkPool.cc @@ -171,7 +171,7 @@ int VirtualNetworkPool::dump(ostringstream& oss, const string& where) static_cast(&VirtualNetworkPool::dump_cb), static_cast(&oss)); - cmd << "SELECT " << VirtualNetwork::table << ".*,COUNT(" + cmd << "SELECT " << VirtualNetwork::extended_db_names << ",COUNT(" << Leases::table << ".used), user_pool.user_name FROM " << VirtualNetwork::table << " LEFT OUTER JOIN " << Leases::table << " ON "