Compile function Copy_RDS_LAYER_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given RDS_LAYER record to the MSSQL database.
	
	History
	-------
	05/24/2012    KRF   Original Programmer
\*****************************************************************************/

$insert RDS_LAYER_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(66)
MatParse Record into Rec
					    
// List of key names and their values
Keys  = "RDS_NO":@VM:SQL_Format(Field(Key, "*", 1), "INT"):@FM
Keys := "LS_ID" :@VM:SQL_Format(Field(Key, "*", 2), "STR")

// List of data fields and their values
DataFields  = "DOPANT"           :@VM:SQL_Format(Rec(RDS_LAYER_DOPANT$),            "STR"):@FM
DataFields := "EPI_DILUENT"      :@VM:SQL_Format(Rec(RDS_LAYER_EPI_DILUENT$),       "DEC", "2"):@FM
DataFields := "RECIPE_NO"        :@VM:SQL_Format(Rec(RDS_LAYER_RECIPE_NO$),         "INT"):@FM
DataFields := "EPI_TIME"         :@VM:SQL_Format(Rec(RDS_LAYER_EPI_TIME$),          "DEC", "1"):@FM
DataFields := "DILUENT_ADJ_PARAM":@VM:SQL_Format(Rec(RDS_LAYER_DILUENT_ADJ_PARAM$), "DEC", "2"):@FM
DataFields := "DOPANT_FLOW"      :@VM:SQL_Format(Rec(RDS_LAYER_DOPANT_FLOW$),       "DEC", "2"):@FM
DataFields := "HCL_FLOW"         :@VM:SQL_Format(Rec(RDS_LAYER_HCL_FLOW$),          "DEC", "2"):@FM
DataFields := "BAKE_TIME"        :@VM:SQL_Format(Rec(RDS_LAYER_BAKE_TIME$),         "INT"):@FM
DataFields := "EPI_H2_FLOW"      :@VM:SQL_Format(Rec(RDS_LAYER_EPI_H2_FLOW$),       "INT"):@FM
DataFields := "TCS_FLOW"         :@VM:SQL_Format(Rec(RDS_LAYER_TCS_FLOW$),          "DEC", "1"):@FM
DataFields := "DCS_FLOW"         :@VM:SQL_Format(Rec(RDS_LAYER_DCS_FLOW$),          "INT"):@FM
DataFields := "AUX1"             :@VM:SQL_Format(Rec(RDS_LAYER_AUX1$),              "DEC", "2"):@FM
DataFields := "AUX2"             :@VM:SQL_Format(Rec(RDS_LAYER_AUX2$),              "DEC", "2"):@FM
DataFields := "F_OFFSET"         :@VM:SQL_Format(Rec(RDS_LAYER_F_OFFSET$),          "INT"):@FM
DataFields := "S_OFFSET"         :@VM:SQL_Format(Rec(RDS_LAYER_S_OFFSET$),          "INT"):@FM
DataFields := "R_OFFSET"         :@VM:SQL_Format(Rec(RDS_LAYER_R_OFFSET$),          "INT"):@FM
DataFields := "ETCH1"            :@VM:SQL_Format(Rec(RDS_LAYER_ETCH1$),             "INT"):@FM
DataFields := "ETCH2"            :@VM:SQL_Format(Rec(RDS_LAYER_ETCH2$),             "INT"):@FM
DataFields := "OVERGROW_REQ"     :@VM:SQL_Format(Rec(RDS_LAYER_OVERGROW_REQ$),      "BIT"):@FM
DataFields := "EPI_TIME_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_EPI_TIME_MIN$),      "DEC", "1"):@FM
DataFields := "EPI_TIME_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_EPI_TIME_MAX$),      "DEC", "1"):@FM
DataFields := "DILUENT_MIN"      :@VM:SQL_Format(Rec(RDS_LAYER_DILUENT_MIN$),       "DEC", "2"):@FM
DataFields := "DILUENT_MAX"      :@VM:SQL_Format(Rec(RDS_LAYER_DILUENT_MAX$),       "DEC", "2"):@FM
DataFields := "DOPANT_FLOW_MIN"  :@VM:SQL_Format(Rec(RDS_LAYER_DOPANT_FLOW_MIN$),   "DEC", "2"):@FM
DataFields := "DOPANT_FLOW_MAX"  :@VM:SQL_Format(Rec(RDS_LAYER_DOPANT_FLOW_MAX$),   "DEC", "2"):@FM
DataFields := "HCL_FLOW_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_HCL_FLOW_MIN$),      "DEC", "2"):@FM
DataFields := "HCL_FLOW_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_HCL_FLOW_MAX$),      "DEC", "2"):@FM
DataFields := "BAKE_TIME_MIN"    :@VM:SQL_Format(Rec(RDS_LAYER_BAKE_TIME_MIN$),     "STR"):@FM
DataFields := "BAKE_TIME_MAX"    :@VM:SQL_Format(Rec(RDS_LAYER_BAKE_TIME_MAX$),     "STR"):@FM
DataFields := "EPI_H2_FLOW_MIN"  :@VM:SQL_Format(Rec(RDS_LAYER_EPI_H2_FLOW_MIN$),   "DEC", "0"):@FM
DataFields := "EPI_H2_FLOW_MAX"  :@VM:SQL_Format(Rec(RDS_LAYER_EPI_H2_FLOW_MAX$),   "DEC", "0"):@FM
DataFields := "TCS_FLOW_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_TCS_FLOW_MIN$),      "DEC", "1"):@FM
DataFields := "TCS_FLOW_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_TCS_FLOW_MAX$),      "DEC", "1"):@FM
DataFields := "DCS_FLOW_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_DCS_FLOW_MIN$),      "DEC", "0"):@FM
DataFields := "DCS_FLOW_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_DCS_FLOW_MAX$),      "DEC", "0"):@FM
DataFields := "AUX1_MIN"         :@VM:SQL_Format(Rec(RDS_LAYER_AUX1_MIN$),          "DEC", "2"):@FM
DataFields := "AUX1_MAX"         :@VM:SQL_Format(Rec(RDS_LAYER_AUX1_MAX$),          "DEC", "2"):@FM
DataFields := "AUX2_MIN"         :@VM:SQL_Format(Rec(RDS_LAYER_AUX2_MIN$),          "DEC", "2"):@FM
DataFields := "AUX2_MAX"         :@VM:SQL_Format(Rec(RDS_LAYER_AUX2_MAX$),          "DEC", "2"):@FM
DataFields := "F_OFFSET_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_F_OFFSET_MIN$),      "DEC", "0"):@FM
DataFields := "F_OFFSET_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_F_OFFSET_MAX$),      "DEC", "0"):@FM
DataFields := "S_OFFSET_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_S_OFFSET_MIN$),      "DEC", "0"):@FM
DataFields := "S_OFFSET_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_S_OFFSET_MAX$),      "DEC", "0"):@FM
DataFields := "R_OFFSET_MIN"     :@VM:SQL_Format(Rec(RDS_LAYER_R_OFFSET_MIN$),      "DEC", "0"):@FM
DataFields := "R_OFFSET_MAX"     :@VM:SQL_Format(Rec(RDS_LAYER_R_OFFSET_MAX$),      "DEC", "0"):@FM
DataFields := "ETCH1_MIN"        :@VM:SQL_Format(Rec(RDS_LAYER_ETCH1_MIN$),         "STR"):@FM
DataFields := "ETCH1_MAX"        :@VM:SQL_Format(Rec(RDS_LAYER_ETCH1_MAX$),         "STR"):@FM
DataFields := "ETCH2_MIN"        :@VM:SQL_Format(Rec(RDS_LAYER_ETCH2_MIN$),         "STR"):@FM
DataFields := "ETCH2_MAX"        :@VM:SQL_Format(Rec(RDS_LAYER_ETCH2_MAX$),         "STR"):@FM
DataFields := "UL_TEMP_MIN"      :@VM:SQL_Format(Rec(RDS_LAYER_UL_TEMP_MIN$),       "INT"):@FM
DataFields := "UL_TEMP_MAX"      :@VM:SQL_Format(Rec(RDS_LAYER_UL_TEMP_MAX$),       "INT"):@FM
DataFields := "UL_TEMP"          :@VM:SQL_Format(Rec(RDS_LAYER_UL_TEMP$),           "INT"):@FM
DataFields := "ETCH3_MIN"        :@VM:SQL_Format(Rec(RDS_LAYER_ETCH3_MIN$),         "INT"):@FM
DataFields := "ETCH3_MAX"        :@VM:SQL_Format(Rec(RDS_LAYER_ETCH3_MAX$),         "INT"):@FM
DataFields := "ETCH3"            :@VM:SQL_Format(Rec(RDS_LAYER_ETCH3$),             "INT"):@FM

// Symbolics
DataFields := "PS_NO"      :@VM:SQL_Format({PS_NO},       "STR"):@FM
DataFields := "RECIPE_NAME":@VM:SQL_Format({RECIPE_NAME}, "STR")

// Write the data to the SQL database
Ans = SQL_Write(Connection, "RDS_LAYER", Keys, DataFields)

//-------------------------------------------------------------------------------------------------
// Multi-valued Fields

// RDS_LAYER_RDS_TEST_KEYS
If Ans EQ "" AND Rec(RDS_LAYER_RDS_TEST_KEYS$) NE "" then
    
    // List of data fields and their values
    MvFields  = "RDS_TEST_KEYS"      :@FM:SQL_Format(Rec(RDS_LAYER_RDS_TEST_KEYS$), "STR"):@RM
    MvFields := "TEST_ZONE"          :@FM:SQL_Format({TEST_ZONE},                   "STR"):@RM
    MvFields := "TEST_THICK_AVG"     :@FM:SQL_Format({TEST_THICK_AVG},              "STR"):@RM
    MvFields := "TEST_THICK_STDV"    :@FM:SQL_Format({TEST_THICK_STDV},             "STR"):@RM
    MvFields := "TEST_RES_AVG"       :@FM:SQL_Format({TEST_RES_AVG},                "STR"):@RM
    MvFields := "TEST_RES_STDV"      :@FM:SQL_Format({TEST_RES_STDV},               "STR"):@RM
    MvFields := "TEST_SPEC_RES_UNITS":@FM:SQL_Format({TEST_SPEC_RES_UNITS},         "STR"):@RM
    MvFields := "TEST_OUT_OF_SPEC"   :@FM:SQL_Format({TEST_OUT_OF_SPEC},            "BIT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_LAYER_RDS_TEST_KEYS", Keys, MvFields);
    
end

// RDS_LAYER_MODIFY_USER
If Ans EQ "" AND Rec(RDS_LAYER_MODIFY_USER$) NE "" then
    
    // List of data fields and their values
    MvFields  = "MODIFY_USER":@FM:SQL_Format(Rec(RDS_LAYER_MODIFY_USER$), "STR"):@RM
    MvFields := "MODIFY_DTM" :@FM:SQL_Format(Rec(RDS_LAYER_MODIFY_DTM$),  "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_LAYER_MODIFY_USER", Keys, MvFields);
    
end

// RDS_LAYER_OVERRIDE_USER
If Ans EQ "" AND Rec(RDS_LAYER_OVERRIDE_USER$) NE "" then
    
    // List of data fields and their values
    MvFields  = "OVERRIDE_USER"  :@FM:SQL_Format(Rec(RDS_LAYER_OVERRIDE_USER$),   "STR"):@RM
    MvFields := "OVERRIDE_DTM"   :@FM:SQL_Format(Rec(RDS_LAYER_OVERRIDE_DTM$),    "DATETIME"):@RM
    MvFields := "OVERRIDE_REASON":@FM:SQL_Format(Rec(RDS_LAYER_OVERRIDE_REASON$), "STR")
    
    // Write the data to the SQL database
    //Ans = SQL_Write_MV(Connection, "RDS_LAYER_OVERRIDE_USER", Keys, MvFields);
    
end

Return Ans
