id_spreadsheet = par_id;
cou_logError( cnx, CO_LOG_DEBUG, "setReferencedCell called");

snprintf(SQLString, SQLBUFSIZE, "
UPDATE co_sys_expression_cell
SET
id_ref_spreadsheet = %d ,
id_ref_column = %d ,
id_ref_row = %d ,
is_ref_column_hard = (%d<>0) ,
is_ref_row_hard = (%d<>0) ,
is_ref_column_named = (%d<>0) ,
is_ref_row_named = (%d<>0) ,
deleted = 0
WHERE id_spreadsheet=%d AND id_column=%d AND id_row=%d AND index_ref = %d ;
", id_ref_spreadsheet, id_ref_column, id_ref_row, ref_column_hard, ref_row_hard,
ref_column_named, ref_row_named,
id_spreadsheet, id_column, id_row,index);

__SQL_EXEC

cou_logError( cnx, CO_LOG_DEBUG, "setReferencedCell 1st done");

if (ok==0) { /* new reference */
snprintf(SQLString, SQLBUFSIZE, "
INSERT INTO co_sys_expression_cell
(id_spreadsheet,id_column,id_row, index_ref, id_ref_spreadsheet, id_ref_column, id_ref_row, is_ref_column_hard, is_ref_row_hard, is_ref_column_named, is_ref_row_named)
VALUES(%d,%d,%d,%d,%d,%d,%d,(%d<>0),(%d<>0),(%d<>0),(%d<>0)) ;
", id_spreadsheet,id_column,id_row,index,id_ref_spreadsheet,id_ref_column, id_ref_row, ref_column_hard, ref_row_hard,ref_column_named, ref_row_named);

cou_logError( cnx, CO_LOG_DEBUG, "setReferencedCell(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
id_spreadsheet,id_column,id_row,index,id_ref_spreadsheet,id_ref_column, id_ref_row, ref_column_hard, ref_row_hard,ref_column_named, ref_row_named
);
__SQL_EXEC

cou_logError( cnx, CO_LOG_DEBUG, "setReferencedCell 2nd done");

}

{
const char* class_names[] = {"spreadsheet","spreadsheet_column","spreadsheet_row",NULL};
int object_ids[] = {id_spreadsheet,id_column,id_row};
char prop_name[32]; /* 2*id(10dig) + 1*index+2*'_' */
char prop_value[32]; /* 2*id + 2*bool+3*',' */
snprintf(prop_name, 32, "p%d_%d_%d", id_column, id_row,index);
snprintf(prop_value, 32, "%d,%d,%d,%d,%d,%d", id_ref_column, id_ref_row, ref_column_hard, ref_row_hard, ref_column_named, ref_row_named);

cou_queueActionX( cnx, "expression_cell", class_names, object_ids,CO_OP_UPDATE, prop_name, prop_value, NULL );
}