Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
Mixed data typeing
I have a json that is being returned :
"item_code": [
254,
"1010-600",
300,
301,
302,
303,
1200,
304,
190,
193,
305,
218,
2155,
2054,
2057,
2499,
2196,
2999,
2998,
360,
2053,
2199,
3151
The problem is that:
1. the 3 digit numbers should have a leading 0 e.g. 300 s/b 0300 which is a key to the items file, which is in the item_code mv field being returned as 0300
2. The web programmer is also complaining that:
1. The types are different and it is a mix of string and numbers.
2. 190 is different from "0190" and it really gives me hard time to figure it out.
3. I can't use converting to number because "1063-600" is also is going to break.
The ITEM_CODE in the dct is varchar
The MAJOR problem is that the leading zero is being stripped (converting to numeric), which now worries me for other parts of the system
Whatneeds to be done to fix this, or am I missing something
"item_code": [
254,
"1010-600",
300,
301,
302,
303,
1200,
304,
190,
193,
305,
218,
2155,
2054,
2057,
2499,
2196,
2999,
2998,
360,
2053,
2199,
3151
The problem is that:
1. the 3 digit numbers should have a leading 0 e.g. 300 s/b 0300 which is a key to the items file, which is in the item_code mv field being returned as 0300
2. The web programmer is also complaining that:
1. The types are different and it is a mix of string and numbers.
2. 190 is different from "0190" and it really gives me hard time to figure it out.
3. I can't use converting to number because "1063-600" is also is going to break.
The ITEM_CODE in the dct is varchar
The MAJOR problem is that the leading zero is being stripped (converting to numeric), which now worries me for other parts of the system
Whatneeds to be done to fix this, or am I missing something
Comments
HTTP_JSON_Services
SetHALItem:
.
.
.
If SRP_JSON(hColumnArray, 'NEW', 'ARRAY') then
NumValues = Count(Value, @VM) + (Value NE '')
For ValueCnt = 1 to NumValues
SRP_JSON(hColumnArray, 'ADDVALUE', Value<0, ValueCnt>)
Next ValueCnt
If SRP_JSON(HALRootObj@, 'SET', Name, hColumnArray) else HTTP_Services('SetResponseStatus', 500, '')
SRP_JSON(hColumnArray, 'RELEASE')
end
I stumbled across the same issue.
The issue arises from calling srp_json passing "0190". It is srp_json that drops the leading zero because it interprets it as a number.
You can override this by adding the optional type of "STRING" to the srp_json SETVALUE or ADDVALUE call.
However there is no means of doing this in the generic http_framework. You will need to extend the framework to include a datatypes parameter. I think the idea was there already in that I think http_json_services had a datatypes parameter but I don't think it was being populated in the generic framework anywhere.
You will need to identify the best way to manage that within your code.
Whether you can do that generically and simply based on your dictionaries is a decision for you. If you can, then that will probably be easier to implement.
Wish me luck.
GetColumnDataTypes: TableName = Param1 ColumnNames = Param2 DataTypeSubsFrom = 'BOOL,CHAR,DATE,DECI,DOLL,FLOA,INTE,TEXT,TIME,VARB,VARC' DataTypeSubsTo = 'BOOLEAN,STRING,STRING,NUMBER,NUMBER,NUMBER,NUMBER,STRING,STRING,NUMBER,STRING' ColumnDataTypes='' If Len(ColumnNames) then DataTypes=xlate("DICT.":Tablename,ColumnNames,DICT_GENERIC_TYPE$,"X") loop while datatypes datatype=datatypes[1,@fm] datatypes[1,col2()]='' locate datatype[1,4] in DataTypeSubsFrom using ',' setting typePos then ColumnDataTypes:=field(DataTypeSubsTo,',',typePos):@fm end else ColumnDataTypes:='STRING':@fm end repeat ColumnDataTypes[-1,1]='' end Response = ColumnDataTypes return