Compile function Copy_REACTOR_LOG_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given REACTOR_LOG record to the MSSQL database.
	
	History
	-------
	07/07/2010    KRF   Original Programmer
\*****************************************************************************/

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(75)
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  = "START_DATE"            :@VM:SQL_Format(Rec(1),  "DATE"):@FM
DataFields := "START_TIME"            :@VM:SQL_Format(Rec(2),  "TIME"):@FM
DataFields := "END_DATE"              :@VM:SQL_Format(Rec(3),  "DATE"):@FM
DataFields := "END_TIME"              :@VM:SQL_Format(Rec(4),  "TIME"):@FM
DataFields := "REACTOR"               :@VM:SQL_Format(Rec(5),  "INT"):@FM
DataFields := "CATEGORY"              :@VM:SQL_Format(Rec(6),  "STR"):@FM
DataFields := "REACT_HRS_START"       :@VM:SQL_Format(Rec(7),  "INT"):@FM
DataFields := "ENTRY_ID"              :@VM:SQL_Format(Rec(9),  "STR"):@FM
DataFields := "ENTRY_DATE"            :@VM:SQL_Format(Rec(10), "DATE"):@FM
DataFields := "CUST_NO"               :@VM:SQL_Format(Rec(11), "STR"):@FM
DataFields := "WO"                    :@VM:SQL_Format(Rec(12), "STR"):@FM
DataFields := "RDS_NO"                :@VM:SQL_Format(Rec(14), "STR"):@FM
DataFields := "TECH_SIG"              :@VM:SQL_Format(Rec(16), "STR"):@FM
DataFields := "REACT_PROB_ID"         :@VM:SQL_Format(Rec(17), "INT"):@FM
DataFields := "REACT_HRS_END"         :@VM:SQL_Format(Rec(20), "INT"):@FM
DataFields := "TOP_FLAT_IN"           :@VM:SQL_Format(Rec(21), "DEC", "3"):@FM
DataFields := "TOP_FLAT_OUT"          :@VM:SQL_Format(Rec(22), "DEC", "3"):@FM
DataFields := "LOW_BOTTOM_FLAT_IN"    :@VM:SQL_Format(Rec(23), "DEC", "3"):@FM
DataFields := "LOW_BOTTOM_FLAT_OUT"   :@VM:SQL_Format(Rec(24), "DEC", "3"):@FM
DataFields := "TUBE_GRADE"            :@VM:SQL_Format(Rec(25), "INT"):@FM
DataFields := "REACT_UTIL_ID"         :@VM:SQL_Format(Rec(29), "INT"):@FM
DataFields := "LL_TUBE_COND"          :@VM:SQL_Format(Rec(30), "INT"):@FM
DataFields := "LL_RECIRCULATION"      :@VM:SQL_Format(Rec(31), "BIT"):@FM
DataFields := "LL_TUBE_LEAK"          :@VM:SQL_Format(Rec(32), "BIT"):@FM
DataFields := "LL_GRAPHITE_PITS"      :@VM:SQL_Format(Rec(33), "INT"):@FM
DataFields := "LL_GOLD_COND"          :@VM:SQL_Format(Rec(34), "STR"):@FM
DataFields := "LL_ROTATION"           :@VM:SQL_Format(Rec(35), "STR"):@FM
DataFields := "LL_GRAPHITE_ADJ"       :@VM:SQL_Format(Rec(36), "BIT"):@FM
DataFields := "LL_SHADOW"             :@VM:SQL_Format(Rec(37), "BIT"):@FM
DataFields := "AW_EXTEND_HOME"        :@VM:SQL_Format(Rec(38), "DEC", "1"):@FM
DataFields := "AW_LEFT_EXTEND"        :@VM:SQL_Format(Rec(39), "DEC", "1"):@FM
DataFields := "AW_RIGHT_EXTEND"       :@VM:SQL_Format(Rec(40), "DEC", "1"):@FM
DataFields := "AW_LONG_EXTEND"        :@VM:SQL_Format(Rec(41), "DEC", "1"):@FM
DataFields := "AW_SHORT_EXTEND"       :@VM:SQL_Format(Rec(42), "DEC", "1"):@FM
DataFields := "AW_EDGE_EXTEND"        :@VM:SQL_Format(Rec(43), "DEC", "1"):@FM
DataFields := "AW_LSTEPS"             :@VM:SQL_Format(Rec(44), "DEC", "1"):@FM
DataFields := "AW_ROTATE_EDGE"        :@VM:SQL_Format(Rec(45), "DEC", "1"):@FM
DataFields := "AW_GSTEPS"             :@VM:SQL_Format(Rec(46), "DEC", "1"):@FM
DataFields := "AW_PICKUP_DELAY"       :@VM:SQL_Format(Rec(47), "DEC", "1"):@FM
DataFields := "AW_GAS_ON"             :@VM:SQL_Format(Rec(48), "DEC", "1"):@FM
DataFields := "AW_GAS_OFF"            :@VM:SQL_Format(Rec(49), "DEC", "1"):@FM
DataFields := "AW_DROPOFF_DELAY"      :@VM:SQL_Format(Rec(50), "DEC", "1"):@FM
DataFields := "AW_VELOCITY_EXTEND"    :@VM:SQL_Format(Rec(51), "DEC", "1"):@FM
DataFields := "AW_ACCELERATION_EXTEND":@VM:SQL_Format(Rec(52), "DEC", "1"):@FM
DataFields := "AW_VELOCITY_ROTATE"    :@VM:SQL_Format(Rec(53), "DEC", "1"):@FM
DataFields := "AW_ACCELERATION_ROTATE":@VM:SQL_Format(Rec(54), "DEC", "1"):@FM
DataFields := "REACTORHOURS"          :@VM:SQL_Format(Rec(55), "INT"):@FM
DataFields := "REACT_CYCLES_READ"     :@VM:SQL_Format(Rec(56), "INT"):@FM

// Symbolics
DataFields := "ELAPSED_HOURS"         :@VM:SQL_Format({ELAPSED_HOURS}, "DEC", 2)

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

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

// REACTOR_LOG_ITEMS
If Ans EQ "" AND Rec(15) NE "" then
        
    // List of data fields and their values
    MvFields  = "REACT_ITEM_IDS":@FM:SQL_Format(Rec(15), "STR"):@RM
    MvFields := "REACT_SERV_ID":@FM:SQL_Format(Rec(18), "INT"):@RM
    MvFields := "REACT_ITEM_QTY":@FM:SQL_Format(Rec(19), "INT"):@RM
    MvFields := "SCHEDULED":@FM:SQL_Format(Rec(26), "BIT"):@RM
    MvFields := "REACT_SERV_CAT_ID":@FM:SQL_Format(Rec(27), "INT"):@RM
    MvFields := "REACT_PROB_CAT_ID":@FM:SQL_Format(Rec(28), "INT"):@RM
    MvFields := "REACT_PROB_CAT_DESC":@FM:SQL_Format({REACT_PROB_CAT_DESC}, "STR"):@RM
    MvFields := "REACT_SERV_DESC":@FM:SQL_Format({REACT_SERV_DESC}, "STR")
    
    RepeatFields  = "REACTOR":@VM:SQL_Format(Rec(5), "STR"):@FM
	RepeatFields := "ENTRY_DATE":@VM:SQL_Format(Rec(10), "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "REACTOR_LOG_ITEMS", Keys, MvFields, RepeatFields);
    
end

// REACTOR_LOG_NOTES
If Ans EQ "" AND Rec(8) NE "" then
        
    // List of data fields and their values
    MvFields  = "NOTES":@FM:SQL_Format(Rec(8), "STR"):@RM
    MvFields := "NOTE_DTMS":@FM:SQL_Format(Rec(72), "DATETIME"):@RM
    MvFields := "NOTE_USERS":@FM:SQL_Format(Rec(73), "STR"):@RM

    RepeatFields = ''
    // Write the data to the SQL database
    Ans          = SQL_Write_MV(Connection, "REACTOR_LOG_NOTES", Keys, MvFields, RepeatFields);
    
end

Return Ans
