From ebfd201bdc1022f5763c348757f67b38f2e853ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 6 May 2010 12:31:09 +0200 Subject: [PATCH] feature #206: SQL Table creation queries modified to include IF NOT EXISTS --- src/host/Host.cc | 2 +- src/host/HostShare.cc | 4 ++-- src/host/HostTemplate.cc | 4 ++-- src/um/User.cc | 2 +- src/vm/History.cc | 5 +++-- src/vm/VirtualMachine.cc | 3 ++- src/vm/VirtualMachineTemplate.cc | 4 ++-- src/vnm/Leases.cc | 2 +- src/vnm/VirtualNetwork.cc | 3 ++- src/vnm/VirtualNetworkTemplate.cc | 4 ++-- 10 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/host/Host.cc b/src/host/Host.cc index 303cbbaaba..dc559a642d 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -55,7 +55,7 @@ const char * Host::table = "host_pool"; const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad," "tm_mad,last_mon_time)"; -const char * Host::db_bootstrap = "CREATE TABLE host_pool (" +const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool (" "oid INTEGER PRIMARY KEY,host_name VARCHAR(512), state INTEGER," "im_mad VARCHAR(128),vm_mad VARCHAR(128),tm_mad VARCHAR(128)," "last_mon_time INTEGER, UNIQUE(host_name, im_mad, vm_mad, tm_mad) )"; diff --git a/src/host/HostShare.cc b/src/host/HostShare.cc index 12c715280f..eb1cbf9e51 100644 --- a/src/host/HostShare.cc +++ b/src/host/HostShare.cc @@ -63,8 +63,8 @@ const char * HostShare::db_names = "(hid," "used_disk, used_mem, used_cpu," "running_vms)"; -const char * HostShare::db_bootstrap = "CREATE TABLE host_shares (" - "hid INTEGER PRIMARY KEY," +const char * HostShare::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_shares(" + "hid INTEGER PRIMARY KEY," "disk_usage INTEGER, mem_usage INTEGER, cpu_usage INTEGER," "max_disk INTEGER, max_mem INTEGER, max_cpu INTEGER," "free_disk INTEGER, free_mem INTEGER, free_cpu INTEGER," diff --git a/src/host/HostTemplate.cc b/src/host/HostTemplate.cc index e5bc474ca5..0f5c6ccfa1 100644 --- a/src/host/HostTemplate.cc +++ b/src/host/HostTemplate.cc @@ -18,7 +18,7 @@ const char * HostTemplate::table = "host_attributes"; -const char * HostTemplate::db_bootstrap = "CREATE TABLE host_attributes" - " (id INTEGER, name VARCHAR(256), type INTEGER, value TEXT, " +const char * HostTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS " + "host_attributes (id INTEGER, name VARCHAR(256), type INTEGER, value TEXT, " "PRIMARY KEY(id,name))"; diff --git a/src/um/User.cc b/src/um/User.cc index 0d7706ff61..fbf9768dbf 100644 --- a/src/um/User.cc +++ b/src/um/User.cc @@ -52,7 +52,7 @@ const char * User::table = "user_pool"; const char * User::db_names = "(oid,user_name,password,enabled)"; -const char * User::db_bootstrap = "CREATE TABLE user_pool (" +const char * User::db_bootstrap = "CREATE TABLE IF NOT EXISTS user_pool (" "oid INTEGER PRIMARY KEY, user_name VARCHAR(256), password TEXT," "enabled INTEGER, UNIQUE(user_name))"; diff --git a/src/vm/History.cc b/src/vm/History.cc index 90d527ef8e..d73ab00927 100644 --- a/src/vm/History.cc +++ b/src/vm/History.cc @@ -28,11 +28,12 @@ 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_bootstrap = "CREATE TABLE history (vid INTEGER," +const char * History::db_bootstrap = "CREATE TABLE IF NOT EXISTS " + "history (vid INTEGER," "seq INTEGER,host_name TEXT,vm_dir TEXT,hid INTEGER,vm_mad TEXT,tm_mad TEXT," "stime INTEGER,etime INTEGER,pstime INTEGER,petime INTEGER,rstime INTEGER," "retime INTEGER,estime INTEGER,eetime INTEGER,reason INTEGER," - "PRIMARY KEY(vid,seq))"; + "PRIMARY KEY(vid,seq))"; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 4377192e13..97089edb89 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -85,7 +85,8 @@ const char * VirtualMachine::db_names = "(oid,uid,name,last_poll,template_id,sta ",lcm_state,stime,etime,deploy_id" ",memory,cpu,net_tx,net_rx)"; -const char * VirtualMachine::db_bootstrap = "CREATE TABLE vm_pool (" +const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS " + "vm_pool (" "oid INTEGER PRIMARY KEY,uid INTEGER,name TEXT," "last_poll INTEGER, template_id INTEGER,state INTEGER,lcm_state INTEGER," "stime INTEGER,etime INTEGER,deploy_id TEXT,memory INTEGER,cpu INTEGER," diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc index 1c8375a95b..1612f03afb 100644 --- a/src/vm/VirtualMachineTemplate.cc +++ b/src/vm/VirtualMachineTemplate.cc @@ -18,6 +18,6 @@ const char * VirtualMachineTemplate::table = "vm_attributes"; -const char * VirtualMachineTemplate::db_bootstrap = "CREATE TABLE vm_attributes" - " (id INTEGER, name TEXT, type INTEGER, value TEXT)"; +const char * VirtualMachineTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS" + " vm_attributes (id INTEGER, name TEXT, type INTEGER, value TEXT)"; diff --git a/src/vnm/Leases.cc b/src/vnm/Leases.cc index 35c0d7f073..d2478b3ecf 100644 --- a/src/vnm/Leases.cc +++ b/src/vnm/Leases.cc @@ -250,7 +250,7 @@ const char * Leases::table = "leases"; const char * Leases::db_names = "(oid,ip,mac_prefix,mac_suffix,vid,used)"; -const char * Leases::db_bootstrap = "CREATE TABLE leases (" +const char * Leases::db_bootstrap = "CREATE TABLE IF NOT EXISTS leases (" "oid INTEGER,ip BIGINT, mac_prefix INTEGER,mac_suffix INTEGER," "vid INTEGER, used INTEGER, PRIMARY KEY(oid,ip))"; diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index dec67554ea..9b9efeb734 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -53,7 +53,8 @@ const char * VirtualNetwork::table = "network_pool"; const char * VirtualNetwork::db_names = "(oid,uid,name,type,bridge)"; -const char * VirtualNetwork::db_bootstrap = "CREATE TABLE network_pool (" +const char * VirtualNetwork::db_bootstrap = "CREATE TABLE IF NOT EXISTS" + " network_pool (" "oid INTEGER PRIMARY KEY, uid INTEGER, name VARCHAR(256), type INTEGER, " "bridge TEXT, UNIQUE(name))"; diff --git a/src/vnm/VirtualNetworkTemplate.cc b/src/vnm/VirtualNetworkTemplate.cc index 63622f9995..790de8eebf 100644 --- a/src/vnm/VirtualNetworkTemplate.cc +++ b/src/vnm/VirtualNetworkTemplate.cc @@ -18,6 +18,6 @@ const char * VirtualNetworkTemplate::table = "vn_template"; -const char * VirtualNetworkTemplate::db_bootstrap = "CREATE TABLE vn_template" - " (id INTEGER, name TEXT, type INTEGER, value TEXT)"; +const char * VirtualNetworkTemplate::db_bootstrap = "CREATE TABLE IF NOT EXISTS" + " vn_template (id INTEGER, name TEXT, type INTEGER, value TEXT)";