Add DatabaseErrorCode

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
feirio
New User
New User
Posts: 1
Joined: Wed May 13, 2020 10:26 am

Add DatabaseErrorCode

Post 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().
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Add DatabaseErrorCode

Post by Fred »

Or may be a flag to DatabaseError() would be enough ? Something like DatabaseError(0, #PB_Database_ErrorCode)
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Add DatabaseErrorCode

Post 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.
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Add DatabaseErrorCode

Post 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
User avatar
HeX0R
Addict
Addict
Posts: 992
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Add DatabaseErrorCode

Post 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.
Post Reply