CHAR
Introduction
Verify string length.
Example
Data Dictionary
hrm.departments Human Resources System-Department Table
| Column name | Data type | Not empty | Increment | Key | Description | |-----------|-------------|----|----|-----|------- -| | dept_no | char(4) | yes | - | primary key | department unique number | | dept_name | varchar(40) | yes | - | unique key | department name |
As shown in the above table, the department number field dept_no is of char type and the length does not exceed 4 characters.
Example
The value of the dept_no field is a string exceeding the maximum length of 4
luwak request
POST http://127.0.0.1:21000
Content-Type: application/json;charset=utf-8
{
"jsonrpc": "2.0",
"method": "hrm.departments.add",
"params": {
"deptNo": "d12345",
"deptName": "Human Resources"
},
"id": "client-unique-request-id"
}
Response results
The request is intercepted and an error is reported, indicating that the inserted data exceeds the maximum length of the field type.
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "validating data type: deptNo: d1235 does not validate as maxstringlength(4)",
"data": {
"errorCode": "EU.Validator.DataTypeError",
"errorDetails": [
{
"field": "deptNo",
"fieldValue": "d1235",
"location": "hrm.departments",
"message": "deptNo: d1235 does not validate as maxstringlength(4)",
"validator": "maxstringlength"
}
],
"errorMessage": "deptNo: d1235 does not validate as maxstringlength(4)"
}
},
"id": "client-unique-request-id"
}
Remarks: The above example was tested in Luwak 1.12.9.