Compile function Copy_GAS_SRC_Record_To_SQL(Connection, Key, Record)

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

$insert REACTOR_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "CURR_GAS"          :@VM:SQL_Format(Rec(1),           "STR"):@FM
DataFields := "CURR_SERIAL"       :@VM:SQL_Format(Rec(2),        "BIT"):@FM
DataFields := "CURR_INSTALL_DTM"    :@VM:SQL_Format(Rec(3),     "DATE"):@FM
DataFields := "ALARM_NO"           :@VM:SQL_Format(Rec(5),            "STR")

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

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

// REACTOR_GAS_SRC

If Ans EQ "" AND Rec(6) NE "" then
    ReactIDs = Rec(6)
    NumVals = Count(ReactIDs, @VM) + (ReactIDs NE "")
    For ValLoop = 1 to NumVals
        mvKey  = "REACT_NO":@VM:SQL_Format(ReactIDs<0, ValLoop>, "INT"):@FM
        mvKey := "AREA":@VM:SQL_Format(Field(Key, "*", 1, 1), "STR"):@FM
        mvKey := "CAB":@VM:SQL_Format(Field(Key, "*", 2, 1), "STR"):@FM
        mvKey := "POS":@VM:SQL_Format(Field(Key, "*", 3, 1), "STR")
        mvDataFields = ""
        Ans = SQL_Write(Connection, "REACTOR_GAS_SRC", mvKey, mvDataFields);
    Next Vals
end


Return Ans
