TableResult SetTable(OdId tOb, SetTableArg tArg)
tOb. Moniker of repository object that is table, external table or view.
tArg. Operation execution parameters.
The SetTable operation changes table/external table/view.
The operation changes structure of table/external table/view. Table/external table/view should be opened for edit. To execute the operation, in the tOb field specify moniker of opened object instance, and in the tArg.meta field specify updated metadata to be applied. The moniker can be obtained on executing the OpenTable operation. In the tArg.pattern field specify the pattern that will be used to change metadata. If the tArg.metaGet field is defined, the operation results in the updated metadata that will be again obtained after its changing in the object. The changes are saved automatically on executing the operation.
The example of adding a new index to table structure. The request contains moniker of opened table instance and updated metadata with added index parameters. The response contains the list of table fields and indexes.
{
"SetTable" :
{
"tOb" :
{
"id" : "S1!M!S!TABLE5"
},
"tArg" :
{
"pattern" :
{
"obInst" : "true",
"indexes" :
{
"indexes" : "Add",
"indexesFields" : "Add"
}
},
"meta" :
{
"indexes" :
{
"its" :
{
"it" :
[
{
"k" : "0",
"id" : "NEW_INDEX",
"n" : "New index",
"unique" : "true",
"indexFields" :
{
"its" :
{
"it" :
[
{
"k" : "1",
"id" : "ISO_CODE",
"n" : "ISO country code",
"vis" : "true",
"dt" : "1",
"mandatory" : "true",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "false"
}
]
}
}
}
]
}
}
},
"metaGet" :
{
"obInst" : "true",
"fields" : "Get",
"indexes" :
{
"indexes" : "Get"
}
}
}
}
}
{
"SetTableResult" :
{
"id" :
{
"id" : "S1!M!S!TABLE5"
},
"meta" :
{
"obInst" :
{
"obDesc" :
{
"@ds" : "",
"@isShortcut" : "0",
"@isLink" : "0",
"@ver" : "21",
"@hf" : "0",
"i" : "T_COUNTRY_INFO",
"n" : "Data by countries",
"k" : "9053",
"c" : "769",
"p" : "9050",
"h" : "0",
"hasPrv" : "0",
"ic" : "0",
"isPermanent" : "1",
"isTemp" : "0"
},
"openArgs" : ""
},
"fields" :
{
"its" :
{
"it" :
[
{
"k" : "1",
"id" : "ISO_CODE",
"n" : "ISO country code",
"vis" : "1",
"dt" : "1",
"mandatory" : "1",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "0"
},
{
"k" : "2",
"id" : "NAME",
"n" : "Name",
"vis" : "1",
"dt" : "1",
"mandatory" : "1",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "0"
},
{
"k" : "3",
"id" : "POPULATION",
"n" : "Population",
"vis" : "1",
"dt" : "3",
"mandatory" : "0",
"defaultValue" : "",
"size" : "20",
"precision" : "2",
"isCalculated" : "0"
},
{
"k" : "4",
"id" : "AREA",
"n" : "Area",
"vis" : "1",
"dt" : "3",
"mandatory" : "0",
"defaultValue" : "",
"size" : "20",
"precision" : "2",
"isCalculated" : "0"
},
{
"k" : "5",
"id" : "CURRENCY",
"n" : "Currency",
"vis" : "1",
"dt" : "1",
"mandatory" : "0",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "0"
}
]
}
},
"indexes" :
{
"its" :
{
"it" :
[
{
"k" : "1",
"id" : "T_COUNTRY_INDEX",
"n" : "Index",
"vis" : "1",
"primary" : "1",
"unique" : "1",
"allowNulls" : "0",
"clustered" : "2",
"indexFields" :
{
"its" :
{
"it" :
[
{
"k" : "1",
"id" : "ISO_CODE",
"n" : "ISO country code",
"vis" : "1",
"dt" : "1",
"mandatory" : "1",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "0"
},
{
"k" : "2",
"id" : "NAME",
"n" : "Name",
"vis" : "1",
"dt" : "1",
"mandatory" : "1",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "0"
}
]
}
},
"expression" : ""
},
{
"k" : "2",
"id" : "NEW_INDEX",
"n" : "New index",
"vis" : "1",
"primary" : "0",
"unique" : "1",
"allowNulls" : "0",
"clustered" : "2",
"indexFields" :
{
"its" :
{
"it" :
[
{
"k" : "1",
"id" : "ISO_CODE",
"n" : "ISO country code",
"vis" : "1",
"dt" : "1",
"mandatory" : "1",
"defaultValue" : "",
"size" : "255",
"precision" : "0",
"isCalculated" : "0"
}
]
}
},
"expression" : ""
}
]
}
}
}
}
}
public static TableResult ChangeTable(string moniker, TableField field, ListOperation operation)
{
var somClient = new SomPortTypeClient(); //Proxy object for operation execution
//Operation execution parameters
var tSet = new SetTable()
{
tArg = new SetTableArg()
{
meta = new TableMd()
{
indexes = new TableIndexes()
{
its = new TableIndex[]
{
new TableIndex()
{
id = "NEW_INDEX",
n = "New index",
indexFields = new TableFields()
{
its = new TableField[]
{
field
}
},
unique = true
}
}
}
},
pattern = new TableMdPattern()
{
indexes = new TableIndexesPattern()
{
indexes = operation,
indexesFields = operation
}
},
metaGet = new TableMdPattern()
{
indexes = new TableIndexesPattern()
{
indexes = ListOperation.Get
},
fields = ListOperation.Get
}
},
tOb = new OdId() { id = moniker }
};
//Change metadata
var tResult = somClient.SetTable(tSet);
return tResult;
}
See also: