_CP_writefields supports writing a set of named fields.
_CP_writefields(int type, SDATA ** returnset, SDATA ** statusset, int dictfd, int datafd, SDATA * itemidlist, SDATA * item, int * lockedresult, SDATA * fieldnames)
type | One of the values from the table in _CP_readfields(). It affects how the item is read while preparing to update the fields listed in fieldnames. See _CP_readfields for more information. |
returnset | A segment mark delimited list of return values corresponding to each item processed
and written from the itemidlist. It will contain a 0 for each item successfully processed and written. This call stops on error so there will be no other value besides 0 in the list. See itemidlist. |
statusset | A segment mark delimited list of status values corresponding to each item processed
and written from the itemidlist. It will contain a 0 for each item successfully processed and written. This call stops on error so there will be no other value besides 0 in the list. See itemidlist. |
dictfd | The handle, returned by _CP_open(), to the dictionary level of the file containing the ADIs. |
datafd | The handle, returned by _CP_open(), to the data level of the file containing the items referenced by itemidlist. |
itemidlist | An attribute mark delimited list of the item-ids used to write items to
datafd. If any item cannot be written (for example, it is locked) or any ADI cannot be read (for example, it does not exist), then the call stops processing the list and returns an error. No further items in the list will be processed or written. Items previously processed and written up to that point remain. |
item | A segment mark delimited list of items. There is one entry for each item to be processed. Each item has one attribute for each attribute listed in fieldnames. |
lockedresult | The lock status of the last item read. |
fieldnames | An attribute mark delimited list of the named fields (aka ADIs) to process and write
for each item in itemidlist. If any of the ADIs cannot be accessed, then the call fails. The conversion and correlative only support MD/MR/D codes. If they are not any of those, then that attribute is not written. |
This occurs if the output conversion or correlative is an MD, MR, or D code.
This function returns -1 if an error occurs and the error code is contained in _CP_errno.
Example 1
This example demonstrates the use of the _CP_writefields function with the D3 mvdemo,orders, file in Python.
Copyright (C) Rocket Software 1993-2020 import d3py def run(): d3py.logon('localhost', 'dm', '', 'mvdemo') f = d3py.File('mvdemo,orders,') fields = d3py.DynArray(['orderdate','shipdate','unitprice','saleprice']) f.writenamedfields('1001',fields,d3py.DynArray(['6/10/2020','6/9/2020','150','2500']))
Example 2
C Programming example:
/* Writes items "2001" and "2002" on "mvdemo,orders," and applies the output conversions from "orderdate", "shipdate", "unitprice", and "saleprice" to each. */ CPSTR * SM = _CP_mkstrl("\xff", 1); CPSTR * dict = _CP_mkstr("dict"); CPSTR * filename = _CP_mkstr("mvdemo,orders,"); CPSTR * returnset = _CP_str_null; CPSTR * statusset = _CP_str_null; int dictfd, datafd; CPSTR * itemidlist = _CP_mkstr("2001" "\xfe" "2002"); CPSTR * items = _CP_str_null; int lockedresult = 0; CPSTR * fieldnames = _CP_mkstr("orderdate" "\xfe" "shipdate" "\xfe" "unitprice" "\xfe" "saleprice"); CPSTR * item1 = _CP_mkstr("6/10/2020" "\xfe" "6/9/2020" "\xfe" "150" "\xfe" "2500"); CPSTR * item2 = _CP_mkstr("9/03/2021" "\xfe" "9/06/2021" "\xfe" "32000" "\xfe" "30000"); _CP_open(&datafd, _CP_str_null, filename); _CP_open(&dictfd, dict, filename); _CP_cat(&items, item1, SM); _CP_cat(&items, items, item2); _CP_writefields(_CP_READ, &returnset, &statusset, dictfd, datafd, itemidlist, items, &lockedresult, fieldnames); _CP_str_free(statusset); _CP_str_free(returnset); _CP_str_free(fieldnames); _CP_str_free(itemidlist); _CP_str_free(filename);