Skip to main content

The specified line does not exist

When using a primary key or unique key to operate a specified piece of data, if the corresponding data does not exist, an error code will be automatically returned.

Including usage scenarios:

  • Check orders
  • Modify single item
  • Delete a single item

Not applicable scenarios

In the following scenarios, failure to find data is normal business logic. Luwak will not consider it an error and will not return an error code:

  • Check the result set (in this case, if no result set is found, an empty result set will be returned)

Compatibility history

When querying a single piece of data using the primary key and unique key, if the result is empty, will an error code be returned?

Luwak system configuration file has a global switch:

throw_error_when_row_not_found = true

  • If this switch is enabled, an error code (ITEM_NOT_FOUND) will be returned when the specified row cannot be found.
  • If this option is disabled, when the specified row cannot be found, success will be returned, but the result will be empty (this is to be compatible with the historical habits of some customers)
  • Enabled by default

Example

Taking the employees table as an example, in order to ensure that subsequent examples operate on records that do not exist, a statement to clear employee data of emp_no=20001 is added after the data table structure.

--Employee table
CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` enum('M','F') NOT NULL,
`hire_date` date NOT NULL,
`salary` int(11) DEFAULT NULL,
PRIMARY KEY (`emp_no`)
);

--Clear data that interferes with testing
delete from employees where emp_no = '20001';

Example 1 Query non-existing records

During data preparation, we have deleted the data with job number 20001. Let’s query and verify it through SQL first.

mysql> select * from employees where emp_no=20001;
Empty set (0.00 sec)

It can be seen that the data does not exist in the data table.

Next, we query the employee's information through luwak and see what the results will return.

Request message

The JSON-RPC request message is as follows

{
"jsonrpc": "2.0",
"method": "hrm.employees.detail",
"params": 20001,
"id": "client-unique-request-id"
}

Response message

The system prompts that the specified data does not exist and gives an error message.

{
"jsonrpc": "2.0",
"error": {
"code": -32600,
"message": "checking if the primary key exists: hrm.employees 20001 does not exist",
"data": {
"errorCode": "EU.Constraint.PK.NotFound",
"errorDetails": [
{
"field": "empNo",
"fieldValue": "20001",
"location": "hrm.employees",
"message": "hrm.employees.emp_no 20001 does not exist"
}
],
"errorMessage": "hrm.employees 20001 does not exist"
}
},
"id": "client-unique-request-id"
}

Example 2 Modify non-existent records

Let’s take the data that we just verified does not exist as an example. Now try to modify the data and see what the execution results will be.

Request message

The JSON-RPC request message is as follows

{
"jsonrpc": "2.0",
"method": "hrm.employees.update",
"params": {
"empNo": 20001,
"firstName": "Thomas"
},
"id": "client-unique-request-id"
}

Response message

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32600,
"message": "checking if the primary key exists: hrm.employees map[empNo:20001] does not exist",
"data": {
"errorCode": "EU.Constraint.PK.NotFound",
"errorDetails": [
{
"constraint": "PrimaryKeyNotFound",
"field": "empNo",
"fieldValue": 20001,
"location": "hrm.employees",
"message": "primary key not found in hrm.employees.emp_no 20001"
}
],
"errorMessage": "hrm.employees map[empNo:20001] does not exist"
}
},
"id": "client-unique-request-id"
}

It can be seen that when modifying a record that does not exist, the system prompts that the corresponding record is not found and refuses the operation.

Example 3 Delete non-existent records

Still taking the above non-existent data as an example, let's try to delete it.

Request message

The JSON-RPC request message is as follows

{
"jsonrpc": "2.0",
"method": "hrm.employees.delete",
"params": 20001,
"id": "client-unique-request-id"
}

Response message

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32600,
"message": "checking if the primary key exists: hrm.employees map[empNo:20001] does not exist",
"data": {
"errorCode": "EU.Constraint.PK.NotFound",
"errorDetails": [
{
"constraint": "PrimaryKeyNotFound",
"field": "empNo",
"fieldValue": "20001",
"location": "hrm.employees",
"message": "primary key not found in hrm.employees.emp_no 20001"
}
],
"errorMessage": "hrm.employees map[empNo:20001] does not exist"
}
},
"id": "client-unique-request-id"
}

It can be seen that when operating on a record that does not exist, the system will prompt that the corresponding record is not found and refuse the operation.

Tested on Luwak 1.12.9