Error 5126 (ERR_DATABASE_NO_MORE_DATA) when trying to read data from a table.

 

I have a table like this:

int Read_LastTrend(string UsedSymbol, string sCol)
{
   int Ret = 0;
   ResetLastError();
   
   //Create or open the database in the common terminal folder
   string filename = Filename(SCANNER_NAME, true);
   int db = DbOpen(filename, __FUNCTION__);
   if (db == INVALID_HANDLE)
   {
      Print("DB: ", filename, " open failed with code ", GetLastError());
      return 0;
   }
   
   //Create a query and get a handle for it
   string SQL = StringFormat("SELECT %s FROM LastTrend WHERE UsedSymbol='%s';", sCol, UsedSymbol);
   int request = DatabasePrepare(db, SQL);
   if (request == INVALID_HANDLE)
   {
      printf("%s request failed with code %d", filename, GetLastError());
      DatabaseClose(db);
      return 0;
   }
   else
   {
      if (DatabaseRead(request))
	  DatabaseColumnInteger(request, 0, Ret);
      else
	  printf("Lỗi DatabaseRead(request) " + GetLastError() + " | " + SQL);

      //Remove the query after use
      DatabaseFinalize(request);
   }
   
   //Close the database
   DatabaseClose(db);
   
   return Ret;
}

I used the above function to read information from the table. Occasionally, an error with error code 5126 (ERR_DATABASE_NO_MORE_DATA) occurs. Sometimes the data is retrieved, sometimes an error occurs. The table above shows 6 currency pairs, but the USDCAD pair is showing an error; the other 5 pairs are working normally.

I am using version 5.0 build 5660.

Could you please help me fix this problem? Thank you very much.

 
Nguyen Van Luong:

I have a table like this:

I used the above function to read information from the table. Occasionally, an error with error code 5126 (ERR_DATABASE_NO_MORE_DATA) occurs. Sometimes the data is retrieved, sometimes an error occurs. The table above shows 6 currency pairs, but the USDCAD pair is showing an error; the other 5 pairs are working normally.

I am using version 5.0 build 5660.

Could you please help me fix this problem? Thank you very much.


The error code is normal and not considered to be an error. It means your SELECT statement has not returned any data, or you have reached the end of your result iteration.
 
Dominik Egert #:
The error code is normal and not considered to be an error. It means your SELECT statement has not returned any data, or you have reached the end of your result iteration.
The SELECT statement has only one result. The data in the table remains unchanged. To retrieve data, use the function above. Clearly, DatabaseRead(request) is executed only once before executing DatabaseColumnInteger(request, 0, Ret);
 
Nguyen Van Luong #The SELECT statement has only one result. The data in the table remains unchanged. To retrieve data, use the function above. Clearly, DatabaseRead(request) is executed only once before executing DatabaseColumnInteger(request, 0, Ret);

As mentioned previously:

Executing prepared queries: DatabaseRead/Bind

The function returns true upon successful completion. The false value is used as an indicator of an error (for example, the database may be blocked or busy), as well as when the end of the results is normally reached, so you should analyze the code in _LastError. In particular, the value ERR_DATABASE_NO_MORE_DATA (5126) indicates that the results are finished.

So, from what I understand, after DatabaseRead(), check GetLastError(), if error = 5126, continue with your code normally.
 
Nguyen Van Luong:

I have a table like this:

I used the above function to read information from the table. Occasionally, an error with error code 5126 (ERR_DATABASE_NO_MORE_DATA) occurs. Sometimes the data is retrieved, sometimes an error occurs. The table above shows 6 currency pairs, but the USDCAD pair is showing an error; the other 5 pairs are working normally.

I am using version 5.0 build 5660.

Could you please help me fix this problem? Thank you very much.

Why are you using an old build ? 

Current release is 5833.

If you want to report a bug, you will need to provide the database and code that compiles to reproduce the issue.

 
Alain Verleyen #:

Why are you using an old build ? 

Current release is 5833.

If you want to report a bug, you will need to provide the database and code that compiles to reproduce the issue.

After updated 5800 I felt something was wrong, so I temporarily disabled the update. I will update to 5833.