Compile function Copy_RECIPE_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given RECIPE record to the MSSQL database.
	
	History
	-------
	06/25/2010    KRF   Original Programmer
\*****************************************************************************/

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(56)
MatParse Record into Rec
					    
// List of key names and their values
Keys = "SEQ":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = "EPI_DOPANT"     :@VM:SQL_Format(Rec(1),  "STR"):@FM
DataFields := "EPI_TEMP"       :@VM:SQL_Format(Rec(2),  "INT"):@FM
DataFields := "EPI_DILUENT"    :@VM:SQL_Format(Rec(4),  "DEC", "2"):@FM
DataFields := "EPI_GASES"      :@VM:SQL_Format(Rec(5),  "STR"):@FM
DataFields := "EPI_GASES_UNIT" :@VM:SQL_Format(Rec(6),  "STR"):@FM
DataFields := "ETCH_TIME"      :@VM:SQL_Format(Rec(11), "INT"):@FM
DataFields := "NOTES"          :@VM:SQL_Format(Rec(16), "STR", 1):@FM
DataFields := "RECIPE_NAME"    :@VM:SQL_Format(Rec(17), "STR"):@FM
DataFields := "ENTRY_ID"       :@VM:SQL_Format(Rec(18), "STR"):@FM
DataFields := "ENTRY_DATE"     :@VM:SQL_Format(Rec(19), "DATE"):@FM
DataFields := "EPI_GAS_RATE"   :@VM:SQL_Format(Rec(20), "DEC", "2"):@FM
DataFields := "CAP_BURST"      :@VM:SQL_Format(Rec(43), "BIT"):@FM
DataFields := "CAP_BURST_GASES":@VM:SQL_Format(Rec(44), "STR"):@FM
DataFields := "STATUS"         :@VM:SQL_Format(Rec(48), "STR"):@FM
DataFields := "ENG_SIG"        :@VM:SQL_Format(Rec(49), "STR")
* DataFields := "ETCH1_MIN"      :@VM:SQL_Format(Rec(50), "INT"):@FM
* DataFields := "ETCH1_MAX"      :@VM:SQL_Format(Rec(51), "INT"):@FM
* DataFields := "ETCH2_MIN"      :@VM:SQL_Format(Rec(52), "INT"):@FM
* DataFields := "ETCH2_MAX"      :@VM:SQL_Format(Rec(53), "INT"):@FM
* DataFields := "ETCH3_MIN"      :@VM:SQL_Format(Rec(54), "INT"):@FM
* DataFields := "ETCH3_MAX"      :@VM:SQL_Format(Rec(55), "INT")

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

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

// RECIPE_LIMIT
If Ans EQ "" AND Rec(45) NE "" then
    
    // List of data fields and their values
    MvFields  = "PROD_SPEC_IDS":@FM:SQL_Format(Rec(45), "INT"):@RM
    MvFields := "DEP_TIME_MIN":@FM:SQL_Format(Rec(7), "DEC", 1):@RM
    MvFields := "DEP_TIME_MAX":@FM:SQL_Format(Rec(8), "DEC", 1):@RM
    MvFields := "DOPANT_FLOW_MIN":@FM:SQL_Format(Rec(9), "DEC", 2):@RM
    MvFields := "DOPANT_FLOW_MAX":@FM:SQL_Format(Rec(10), "DEC", 2):@RM
    MvFields := "BAKE_TIME_MAX":@FM:SQL_Format(Rec(12), "INT"):@RM
    MvFields := "H2_FLOW_MIN":@FM:SQL_Format(Rec(13), "INT"):@RM
    MvFields := "H2_FLOW_MAX":@FM:SQL_Format(Rec(14), "INT"):@RM
    MvFields := "DCS_FLOW_MIN":@FM:SQL_Format(Rec(15), "INT"):@RM
    MvFields := "DCS_FLOW_MAX":@FM:SQL_Format(Rec(24), "INT"):@RM
    MvFields := "AUX1_MIN":@FM:SQL_Format(Rec(25), "DEC", 2):@RM
    MvFields := "AUX1_MAX":@FM:SQL_Format(Rec(26), "DEC", 2):@RM
    MvFields := "AUX2_MIN":@FM:SQL_Format(Rec(27), "DEC", 2):@RM
    MvFields := "AUX2_MAX":@FM:SQL_Format(Rec(28), "DEC", 2):@RM
    MvFields := "F_OFFSET_MIN":@FM:SQL_Format(Rec(29), "INT"):@RM
    MvFields := "F_OFFSET_MAX":@FM:SQL_Format(Rec(30), "INT"):@RM
    MvFields := "S_OFFSET_MIN":@FM:SQL_Format(Rec(31), "INT"):@RM
    MvFields := "S_OFFSET_MAX":@FM:SQL_Format(Rec(32), "INT"):@RM
    MvFields := "R_OFFSET_MIN":@FM:SQL_Format(Rec(33), "INT"):@RM
    MvFields := "R_OFFSET_MAX":@FM:SQL_Format(Rec(34), "INT"):@RM
    MvFields := "BAKE_TIME_MIN":@FM:SQL_Format(Rec(35), "INT"):@RM
    MvFields := "DILUENT_MIN":@FM:SQL_Format(Rec(37), "DEC", 2):@RM
    MvFields := "DILUENT_MAX":@FM:SQL_Format(Rec(38), "DEC", 2):@RM
    MvFields := "HCL_FLOW_MIN":@FM:SQL_Format(Rec(39), "DEC", 2):@RM
    MvFields := "HCL_FLOW_MAX":@FM:SQL_Format(Rec(40), "DEC", 2):@RM
    MvFields := "TCS_FLOW_MIN":@FM:SQL_Format(Rec(41), "DEC", 1):@RM
    MvFields := "TCS_FLOW_MAX":@FM:SQL_Format(Rec(42), "DEC", 1):@RM
    MvFields := "ETCH1_MIN":@FM:SQL_Format(Rec(50), "INT"):@RM
    MvFields := "ETCH1_MAX":@FM:SQL_Format(Rec(51), "INT"):@RM
    MvFields := "ETCH2_MIN":@FM:SQL_Format(Rec(52), "INT"):@RM
    MvFields := "ETCH2_MAX":@FM:SQL_Format(Rec(53), "INT"):@RM
    MvFields := "ETCH3_MIN":@FM:SQL_Format(Rec(54), "INT"):@RM
    MvFields := "ETCH3_MAX":@FM:SQL_Format(Rec(55), "INT")
    
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RECIPE_LIMIT", Keys, MvFields);
    
end

// RECIPE_LAYER
If Ans EQ "" AND Rec(21) NE "" then
    
    // List of data fields and their values
    MvFields  = "LAYER_INFO":@FM:SQL_Format(Rec(21), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RECIPE_LAYER", Keys, MvFields);
    
end

// RECIPE_MODIFY
If Ans EQ "" AND Rec(22) NE "" then
    
    // List of data fields and their values
    MvFields  = "MOD_ID":@FM:SQL_Format(Rec(22), "STR"):@RM
    MvFields := "MOD_DATE":@FM:SQL_Format(Rec(23), "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RECIPE_MODIFY", Keys, MvFields);
    
end

// RECIPE_REACTOR
If Ans EQ "" AND Rec(3) NE "" then
    
    // List of data fields and their values
    MvFields  = "REACTOR_TYPE":@FM:SQL_Format(Rec(3), "STR"):@RM
    MvFields := "[DISK]":@FM:SQL_Format(Rec(36), "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RECIPE_REACTOR", Keys, MvFields);
    
end

// RECIPE_RMOD
If Ans EQ "" AND (Rec(46) NE "" OR Rec(47) NE "") then
    
    // List of data fields and their values
    MvFields  = "RMOD_FIELD":@FM:SQL_Format(Rec(46), "STR"):@RM
    MvFields := "RMOD_ID":@FM:SQL_Format(Rec(47), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RECIPE_RMOD", Keys, MvFields);
    
end

Return Ans
