% '====================================================================== ' Main() ' ' Description: Main body of this script ' ' '====================================================================== 'Set showsql to 1 to see the SQL statements -- perhaps the first thing to do in debugging 'Set verbose to 1 for a lot of output -- for more debugging 'Uncomment commented-out Response.write statements that are sprinkled throughout to help identify problems. showsql = 0 verbose = 0 %><% 'Print out all the fields passed in from web form %><% If verbose = 1 Then Response.write "
Request.Form( <%= x %> ) = <%= Request.Form(x) %>
<% Next
End if%><%
If verbose = 1 Then
Response.write "
REMOTE_ADDR = " & Request("REMOTE_ADDR")
End If
If Request("REMOTE_ADDR") <> "134.89.12.163" And _
Request("REMOTE_ADDR") <> "134.89.12.187" And _
Request("REMOTE_ADDR") <> "134.89.11.247" And _
Request("REMOTE_ADDR") <> "134.89.4.103" And _
Request("REMOTE_ADDR") <> "134.89.12.178" Then
Response.write "
Sorry access to host " & Request("REMOTE_HOST") & " is denied." if verbose <> 1 then Response.redirect "/samplesDB/loads/deny.html" 'Warning *** Redirects don't work if debugging statements are turned on end if End if If verbose = 1 Then Response.write "
ConnectionString = " & "dsn=sample1;uid=samdba;pwd=keepme1" End If Set Conn = Server.CreateObject("ADODB.Connection") ' ConnectionString set in global.asa file Conn.Open "dsn=sample1;uid=samdba;pwd=keepme1" If verbose = 1 Then Response.write "
Connection Successful" End If msg="" Action = Left(UCase(Request("Action")),5) If Action = "LOAD " Then 'Read names of the Database columns Dim cols(20) i = 0 For Each col In Request.Form("DBCOLS") i = i + 1 cols(i) = col If col = "TapeTimeCode" Then tc_index = i End if Next If verbose = 1 Then Response.write "tc_index = " & tc_index & "
" 'Read the comments Dim comments(100) i = 0 For Each comment In Request.Form("COMMENTS") i = i + 1 comments(i) = comment 'Response.Write "comments = " & comments(i) & "
" Next 'Build a dictionary for each column & sample to be added to the table Dim D, S, a, samps, scols, keys Set samps = CreateObject("Scripting.Dictionary") Set scols = CreateObject("Scripting.Dictionary") Set S = CreateObject("Scripting.Dictionary") 'Gotta succeed from this point on.... Conn.BeginTrans 'First check for existing CollectionGroup in table, then 'Load CollectionGroup table & get ID to add to sample dictionary ColGrpID = CheckIfInExpd(Request("ROV"), Request("StartDTG")) if ColGrpID <> "" Then Response.Write "
Found and am using ColGrpID = " & ColGrpID else If verbose = 1 Then Response.Write "Loading CollectionGroup table
" End if ColGrpID = LoadCollectionGroup() Response.Write "
ExpdD = " & ColGrpID if ColGrpID < 0 then Response.write "" Response.write "" Response.write "" End if end if 'Read all samples into associative array keyed by TapeTimeCode If verbose = 1 Then Response.Write "
- Must have scientist name in Person table to load samples.
" Response.write "Building dictionary of sample dictionaries keyed by TapeTimeCode
" End if iCount = 0 For Each item In Request.Form("SAMPLES") iCount = iCount + 1 If verbose = 1 Then Response.Write "Sample " & iCount & "
" & item & "
calling ParseSample()..." 'Dictionary of CollectionEvent name-value pairs set D = ParseSample(item,iCount) a = D.Items If verbose = 1 Then Response.Write "Done building sample dictionary for " & a(tc_index - 1) & ":
" 'Dictionary of dictionaries S.add a(tc_index - 1), D If verbose = 1 Then For i = 0 To D.Count - 1 Response.write cols(i+1) & ": " & a(i) & "
" Next End if Next 'Loop thru all the samples and the items within each one. 'This is great;-} Dictionary object items start at 0! If verbose = 1 Then Response.write "The final dictionary of sample dictionaries:
" samps = S.items keys = S.keys For i = 0 To S.Count - 1 If verbose = 1 Then Response.write "Samp " & i + 1 & ":
" scols = samps(i).items For j = 0 To samps(i).Count - 1 If verbose = 1 Then Response.write "j+1. cols(j+1): scols(j) " & j + 1 & "." & cols(j+1) & ": " & scols(j) & "
" Next Next 'Loop through keys passed in via LOAD and pass objects off to be loaded into db Response.write "Loading selected samples into shore-side samples database...
" If showsql = 1 Then Response.write "SQL statements processed:
" For each item in Request.form("LOAD") 'Loop thru all samples For i = 0 To S.count - 1 'Check if it's checked If item = keys(i) Then Response.write "
Sample " & item & ": " 'First Confirm that all required fields have values ret1 = CheckValues(samps(i)) If ret1 <> "" Then Response.write "" Response.write "" Response.write "" End if 'Now check that record is not already in DB use sampleID in all queries If ret1 = "" Then ret2 = CheckIfInDB(samps(i)) If ret2 <> "" Then Response.write "" Response.write "
- Could not be loaded because the following fields are required and must have values:
" Response.write ret1 & "
Cannot load sample because it has the same TapeTimeCode " _ & "and EpochSeconds as SampleID " & ret1 & "." Response.write "" End if If ret1 = "" and ret2 = "" Then If verbose = 1 Then Response.write "Calling LoadIntoDB... " & item id = LoadIntoDB(samps(i)) Response.write "
id = " & id If id < 0 Then Response.write "
Cannot load database. Please fix the problem encountered above." Else Response.write "
Loaded, SampleID " & id & "" End if End if End if Next Next 'All done filling tables, commit the transaction ''Conn.RollBackTrans ' While debugging Conn.CommitTrans Conn.Close 'If we want to service another action with this page Elseif Action = "LOADX" Then End If %>Load samples into database <%Request("VifFile")%> Done processing.
To see the CollectionEvent table click http://dbweb1.mbari.org/samplesDB/sample/sample1.asp
Samples queries available at more queries.