home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / PFRONT98 / DATA.Z / DB_StartBotASP.txt < prev    next >
Encoding:
Text File  |  1997-09-26  |  3.2 KB  |  88 lines

  1. <%
  2. ' Substitute in form parameters into the query string
  3. fp_sQry = "[*]InsertSqlQuery[*]"
  4. fp_sDefault = "[*]InsertDefaultFields[*]"
  5. fp_sNoRecords = "[*]InsertNoRecordsFound[*]"
  6. fp_iMaxRecords = 0[*]InsertMaxRecords[*]
  7. fp_iTimeout = 0[*]InsertScriptTimeout[*]
  8. fp_iCurrent = 1
  9. fp_fError = False
  10. fp_bBlankField = False
  11. If fp_iTimeout <> 0 Then Server.ScriptTimeout = fp_iTimeout
  12. Do While (Not fp_fError) And (InStr(fp_iCurrent, fp_sQry, "%%") <> 0)
  13.     ' found a opening quote, find the close quote
  14.     fp_iStart = InStr(fp_iCurrent, fp_sQry, "%%")
  15.     fp_iEnd = InStr(fp_iStart + 2, fp_sQry, "%%")
  16.     If fp_iEnd = 0 Then
  17.         fp_fError = True
  18.         Response.Write "<B>Database Region Error: mismatched parameter delimiters</B>"
  19.     Else
  20.         fp_sField = Mid(fp_sQry, fp_iStart + 2, fp_iEnd - fp_iStart - 2)
  21.         If Mid(fp_sField,1,1) = "%" Then
  22.             fp_sWildcard = "%"
  23.             fp_sField = Mid(fp_sField, 2)
  24.         Else
  25.             fp_sWildCard = ""
  26.         End If
  27.         fp_sValue = Request.Form(fp_sField)
  28.  
  29.         ' if the named form field doesn't exist, make a note of it
  30.         If (len(fp_sValue) = 0) Then
  31.             fp_iCurrentField = 1
  32.             fp_bFoundField = False
  33.             Do While (InStr(fp_iCurrentField, fp_sDefault, fp_sField) <> 0) _
  34.                 And Not fp_bFoundField
  35.                 fp_iCurrentField = InStr(fp_iCurrentField, fp_sDefault, fp_sField)
  36.                 fp_iStartField = InStr(fp_iCurrentField, fp_sDefault, "=")
  37.                 If fp_iStartField = fp_iCurrentField + len(fp_sField) Then
  38.                     fp_iEndField = InStr(fp_iCurrentField, fp_sDefault, "&")
  39.                     If (fp_iEndField = 0) Then fp_iEndField = len(fp_sDefault) + 1
  40.                     fp_sValue = Mid(fp_sDefault, fp_iStartField+1, fp_iEndField-1)
  41.                     fp_bFoundField = True
  42.                 Else
  43.                     fp_iCurrentField = fp_iCurrentField + len(fp_sField) - 1
  44.                 End If
  45.             Loop
  46.         End If
  47.  
  48.         ' this next finds the named form field value, and substitutes in
  49.         ' doubled single-quotes for all single quotes in the literal value
  50.         ' so that SQL doesn't get confused by seeing unpaired single-quotes
  51.         If (Mid(fp_sQry, fp_iStart - 1, 1) = """") Then
  52.             fp_sValue = Replace(fp_sValue, """", """""")
  53.         ElseIf (Mid(fp_sQry, fp_iStart - 1, 1) = "'") Then
  54.             fp_sValue = Replace(fp_sValue, "'", "''")
  55.         ElseIf Not IsNumeric(fp_sValue) Then
  56.             fp_sValue = ""
  57.         End If
  58.  
  59.         If (len(fp_sValue) = 0) Then fp_bBlankField = True
  60.  
  61.         fp_sQry = Left(fp_sQry, fp_iStart - 1) + fp_sWildCard + fp_sValue + _
  62.             Right(fp_sQry, Len(fp_sQry) - fp_iEnd - 1)
  63.         
  64.         ' Fixup the new current position to be after the substituted value
  65.         fp_iCurrent = fp_iStart + Len(fp_sValue) + Len(fp_sWildCard)
  66.     End If
  67. Loop
  68.  
  69. If Not fp_fError Then
  70.     ' Use the connection string directly as entered from the wizard
  71.     On Error Resume Next
  72.     set fp_rs = CreateObject("ADODB.Recordset")
  73.     If fp_iMaxRecords <> 0 Then fp_rs.MaxRecords = fp_iMaxRecords
  74.     fp_rs.Open fp_sQry, "[*]InsertConnString[*]"
  75.     If Err.Description <> "" Then
  76.         Response.Write "<B>Database Error: " + Err.Description + "</B>"
  77.         if fp_bBlankField Then
  78.             Response.Write "  One or more form fields were empty."
  79.         End If
  80.     Else
  81.         ' Check for the no-record case
  82.         If fp_rs.EOF And fp_rs.BOF Then
  83.             Response.Write fp_sNoRecords
  84.         Else
  85.             ' Start a while loop to fetch each record in the result set
  86.             Do Until fp_rs.EOF
  87. %>
  88.