Skip to content

Commit c587bb7

Browse files
committed
fix inserts on empty lists ;(
1 parent 81f7acb commit c587bb7

11 files changed

+44
-0
lines changed

db/insert_clusters.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ const insertCluster = `
6262
// Insert into database
6363
func (b *Backend) InsertClusters(clusters []common.Cluster) (err error) {
6464

65+
if len(clusters) == 0 {
66+
return
67+
}
68+
6569
// exit if there is no database connection
6670
err = b.checkDB()
6771
if err != nil {

db/insert_datacenters.go

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const insertDatacenter = `
3232
// InsertVMs inserts a vm into database
3333
func (b *Backend) InsertDatacenters(dcs []common.Datacenter) (err error) {
3434

35+
if len(dcs) == 0 {
36+
return
37+
}
38+
3539
// exit if there is no database connection
3640
err = b.checkDB()
3741
if err != nil {

db/insert_datastores.go

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ const insertDatastore = `
4343

4444
func (b *Backend) InsertDatastores(dss []common.Datastore) (err error) {
4545

46+
if len(dss) == 0 {
47+
return
48+
}
49+
4650
// exit if there is no database connection
4751
err = b.checkDB()
4852
if err != nil {

db/insert_esxi.go

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ const insertEsxi = `
9292
// Insert into database
9393
func (b *Backend) InsertEsxi(esxis []common.Esxi) (err error) {
9494

95+
if len(esxis) == 0 {
96+
return
97+
}
98+
9599
// exit if there is no database connection
96100
err = b.checkDB()
97101
if err != nil {

db/insert_folders.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const insertFolders = `
4242
// Insert into database
4343
func (b *Backend) InsertFolders(folders []common.Folder) (err error) {
4444

45+
if len(folders) == 0 {
46+
return
47+
}
48+
4549
// exit if there is no database connection
4650
err = b.checkDB()
4751
if err != nil {

db/insert_portgroups.go

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const insertPortgroup = `
3838
// Insert into database
3939
func (b *Backend) InsertPortgroups(portgroups []common.Portgroup) (err error) {
4040

41+
if len(portgroups) == 0 {
42+
return
43+
}
44+
4145
// exit if there is no database connection
4246
err = b.checkDB()
4347
if err != nil {

db/insert_resourcepools.go

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ const insertResourcepool = `
6464
// Insert into database
6565
func (b *Backend) InsertResourcepools(resourcepools []common.ResourcePool) (err error) {
6666

67+
if len(resourcepools) == 0 {
68+
return
69+
}
70+
6771
// exit if there is no database connection
6872
err = b.checkDB()
6973
if err != nil {

db/insert_vdisks.go

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const insertVDisk = `
5050
// Insert into database
5151
func (b *Backend) InsertVDisks(vdisks []common.VDisk) (err error) {
5252

53+
if len(vdisks) == 0 {
54+
return
55+
}
56+
5357
// exit if there is no database connection
5458
err = b.checkDB()
5559
if err != nil {

db/insert_virtualmachine.go

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ const insertVm = `
9898
// InsertVirtualmachines inserts a vm into database
9999
func (b *Backend) InsertVirtualmachines(vms []common.VirtualMachine) (err error) {
100100

101+
if len(vms) == 0 {
102+
return
103+
}
104+
101105
// exit if there is no database connection
102106
err = b.checkDB()
103107
if err != nil {

db/insert_vnics.go

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const insertVNics = `
4444
// Insert into database
4545
func (b *Backend) InsertVNics(vnics []common.VNic) (err error) {
4646

47+
if len(vnics) == 0 {
48+
return
49+
}
50+
4751
// exit if there is no database connection
4852
err = b.checkDB()
4953
if err != nil {

db/insert_vswitch.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ const insertDVS = `
6767
// Insert into database
6868
func (b *Backend) InsertVSwitch(vswitches []common.VSwitch) (err error) {
6969

70+
if len(vswitches) == 0 {
71+
return
72+
}
73+
7074
// exit if there is no database connection
7175
err = b.checkDB()
7276
if err != nil {

0 commit comments

Comments
 (0)