Here's a simple help function which should assist you cleaning the boxset table from orphaned entries (I think):
<!doctype html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="ie=edge">
<script type="text/vbScript">
'
' ------------------------------------------------------------
' set path values
' ===============
'
' set this values accordingly
'
currentPath = "Z:\my\xmm\dbfolder"
currentDBname = "myxmmdatabasenamewithoutextension"
'
' ------------------------------------------------------------
'
' Local MS Access DB connection string
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & currentPath & "\" & currentDBname & ".mdb"
'
' ------------------------------------------------------------
'
' Cleanup BoxsetID
'
Function clrBoxID(boxID)
'
Set connWrite = CreateObject("ADODB.Connection")
' Connect to the database
connWrite.Open strConnect
' delete records from table "boxsetlink"
StrSQLDelBoxsetLinks = "DELETE FROM BoxsetLink WHERE BoxsetID =" & CInt(boxID) & ";"
' do it now
connWrite.Execute(StrSQLDelBoxsetLinks)
connWrite.close
'
location.reload(true)
'
End Function
'
' ------------------------------------------------------------
'
' Get Boxsets and associated Movies
'
Set conn = CreateObject("ADODB.Connection")
' Connect to the database
conn.Open strConnect
StrSQLListBoxSets = "SELECT BoxsetLink.BoxsetID, Movies_1.Title, Movies.MovieID, Movies.Title FROM (Movies RIGHT JOIN BoxsetLink ON Movies.MovieID = BoxsetLink.MovieID) LEFT JOIN Movies AS Movies_1 ON BoxsetLink.BoxsetID = Movies_1.MovieID ORDER BY Movies_1.Title, Movies.Title;"
Set rsListing = conn.Execute(StrSQLListBoxsets)
if not rsListing.EOF then
arrBoxsets = rsListing.GetRows()
countRows = UBound(arrBoxsets,2)+1
else
noarrBoxsets = "Nothing found"
countRows = 0
end if
rsListing.close
conn.close
'
</script>
<title>Database Helper</title>
<style type="text/css">
body {
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
color: #FFF;
background-color: #000;
}
.headerbox {
border: thin solid #F30;
border-radius: 6px;
padding: 3px;
}
.btn-danger {
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
background-color: #da4f49;
border-color: #bd362f #bd362f #802420;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
}
.missing {
font-weight: bold;
color: #C00;
}
.boxid {
color: #CF0;
}
.warning {
line-height: 20px;
color: #F00;
}
</style>
</head>
<body>
<header class="headerbox">
<h1>Simple DB Helper Function</h1>
</header>
<section class="main_1">
<h2>Boxset Listing:</h2>
<p>The following items are listed as boxsets:</p>
<p><span class="boxid"><b>Boxset ID</b></span><b> | Boxset Title</b> | (associated) Movie: ID | Title</p>
<script type="text/vbscript">
if countRows > 0 then
for i=0 to (CountRows-1)
document.write("<p>")
document.write("<em class='boxid'>" & arrBoxsets(0,i) & "</em> | " )
if IsNull(arrBoxsets(1,i)) OR IsEmpty(arrBoxsets(1,i)) then
document.write("<em class='missing'>There seems to be no boxset anymore in the db for this item</em>")
else
document.write(arrBoxsets(1,i))
end if
document.write(" | " & arrBoxsets(2,i) & " | " & arrBoxsets(3,i))
document.write("</p>")
next
else
document.write(noarrBoxsets)
end if
</script>
</section>
<section class="main_2">
<h2>Delete Boxsets</h2>
<p>Enter the ID of a boxset you want to delete (if everything goes well it will be gone forever ...):</p>
<p>
<input type="text" name="enteredboxID" id="textfield">
</p>
<p class="warning"><em>Note: There will be no check whatsoever if this is a valid ID nor if it is really a boxset. Right?</em></p>
<p>
<input name="button" type="button" class="btn-danger" id="button" onclick="clrBoxID(enteredboxID.value)" value="Delete this ID">
</p>
</section>
<footer class="warning"><strong>Unsupported educational material - not part of any product / production release. Use at your own risk.</strong></footer>
</body>
</html>
- Save the code (everything between and including the html tags above) as a htm-file.
- Adapt the values marked red (path to database, name of database).
- Run it in Internet Explorer.
- It will probably complain about some active components. Those are the ADO functions (active x objects) used to access the db. If you are sure, allow it. It will not work in any other browser than IE on windows.
- [Edit] Forgot to mention: the listing should highlight items which are no longer associated to a boxset because the boxset does not exist. But: if there's a movie with an ID formerly known as associated to a boxset the listing will not mark it because it's just a stupid SELECT statement (won't matter if you have A. I. (tt0212720) in your movie db).
- Also the function will only alter the boxsetlink table (where the movie to boxset associations are stored). It will not delete Boxsets from the main movie table. This is something which should be done in XMM.
Before you use it: back up your database. Twice.
Note: the little function will not try to correct invalid user input. Not at all.
BTW: if we had referential integrity = primary keys this would not be needed.