Page 1 of 1

Add DatabaseErrorCode

Posted: Wed May 13, 2020 10:46 am
by feirio
I have the problem that the MySQL connection gets lost after about 10 minutes due to the MySQL server setup. It would be quite easy to reconnect having the error code. The currently only build in way is parsing the error string that is returned by DatabaseError().

My workaround is importing the mysql_errno function from the library. So I think it is quite easy to add this as a native Purebasic function.

Code: Select all

  ImportC "-lmariadb"
     mysql_errno.l(id.i)
  EndImport

  Define db.i = DatabaseID(#Database)
  Define errorCode.l = mysql_errno(db)

  If errorCode = 2006 Or errorCode = 2013
    Debug "Do the reconnect"
  EndIf
List of error codes: https://dev.mysql.com/doc/refman/8.0/en ... rence.html

TL;DR: It would be great to have a function DatabaseErrorCode() additionally to DatabaseError().

Re: Add DatabaseErrorCode

Posted: Thu May 14, 2020 9:19 am
by Fred
Or may be a flag to DatabaseError() would be enough ? Something like DatabaseError(0, #PB_Database_ErrorCode)

Re: Add DatabaseErrorCode

Posted: Thu May 14, 2020 11:52 am
by User_Russian
Fred, DatabaseError returns a string. Can she get the number back? There is no functions in PB that depending on the flag returns a number or a string. This is forbidden at the compiler level.

Re: Add DatabaseErrorCode

Posted: Thu May 14, 2020 2:17 pm
by Fred
It could be the errorcode as a string, it's not an issue. You will use it for comparison, not doing math with it

Re: Add DatabaseErrorCode

Posted: Sun May 24, 2020 11:17 pm
by HeX0R
What about adding a new command "GetLastError()", which is independant of any library?
You could get rid of DatabaseError(), DialogError(), SerialPortError(), XMLError(), ... and there would be only one command to retrieve the last errors.

That would be the first step for a PB, full of usable error messages (think about the network library as one example, almost unusable without using API to retrieve error messages).

Maybe add another command like "GetLastErrorText()", for those, who never do any multi-language apps.