<participant>
     <quickSearch><![CDATA[MM_insert]]></quickSearch>
     <insertText location="aboveHTML+30">
<![CDATA[
<%
// *** Insert Record: construct a sql insert statement and execute it

if (request.getParameter("MM_insert") != null) {

  // create the insert sql statement
  StringBuffer MM_tableValues = new StringBuffer(), MM_dbValues = new StringBuffer();
  String[] MM_dbValues_prep = new String[MM_fields.length/2];
  for (int i=0; i+1 < MM_fields.length; i+=2) {
    String formVal = MM_fields[i+1];
    String elem;
    java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_columns[i+1],",");
    elem = (String)tokens.nextToken(); // consume the delim
    String altVal   = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
    String emptyVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
    if (formVal.length() == 0) {
        if(emptyVal.equals("NULL")) {
            formVal = null;
        } else if(emptyVal.charAt(0) == '\'') {
            formVal = emptyVal.substring(1, emptyVal.length()-1);
        } else {
            formVal = emptyVal;
        }
    } else if (altVal.length() != 0) {
        if(altVal.charAt(0) == '\'') {
            formVal = altVal.substring(1, altVal.length()-1);
        } else {
            formVal = altVal;
        }
    }
    MM_dbValues_prep[i/2] = formVal;
    MM_tableValues.append((i!=0)?",":"").append(MM_columns[i]);
    MM_dbValues.append((i!=0)?",":"").append('?');
  }
  MM_editQuery = new StringBuffer("insert into " + MM_editTable);
  MM_editQuery.append(" (").append(MM_tableValues.toString()).append(") values (");
  MM_editQuery.append(MM_dbValues.toString()).append(")");
  
  if (!MM_abortEdit) {
    // finish the sql and execute it
    Driver MM_driver = (Driver)Class.forName(MM_editDriver).newInstance();
    Connection MM_connection = DriverManager.getConnection(MM_editConnection,MM_editUserName,MM_editPassword);
    PreparedStatement MM_editStatement = MM_connection.prepareStatement(MM_editQuery.toString());
    for(int i=0; i<MM_dbValues_prep.length; i++) {
        MM_editStatement.setObject(i+1, MM_dbValues_prep[i]);
    }
    MM_editStatement.executeUpdate();
    MM_connection.close();

    // redirect with URL parameters
    if (MM_editRedirectUrl.length() != 0) {
      response.sendRedirect(response.encodeRedirectURL(MM_editRedirectUrl));
      return;
    }
  }
}
%>
]]>
     </insertText>
     <searchPatterns whereToSearch="directive">
       <searchPattern><![CDATA[/request\.getParameter\("MM_insert"\)/]]></searchPattern>
       <searchPattern><![CDATA[/if\s*\(!MM_abortEdit\)\s*\{/]]></searchPattern>
       <searchPattern><![CDATA[/MM_editQuery\s*=\s*new\s+StringBuffer\s*\("insert into "/]]></searchPattern>
     </searchPatterns>
</participant>
