Feature Request - URI access to MySQL - please support

I just added a feature request for URI access to MySQL databases.

https://tracker.xojo.com/xojoinc/xojo/-/issues/81226

Please consider supporting this request, as URI is common way to access MySQL databases.

Until this gets implemented, I have this method from an old(ish) project:

Public Function MySQLFromURI(uri as String) As MySQLCommunityServer
  var r As New RegEx
  r.SearchPattern = "^([^:]+)://([^:]+):([^@]+)@([^:/]+):(\d+)/(.+)$"
  
  var m As RegExMatch = r.Search(uri)
  
  if m <> Nil Then
    
    var protocol as String = m.SubExpressionString(1)
    if protocol <> "mysql" then
      raise new DatabaseException( "Invalid URI protocol supplied." )
      Return nil
    end if
    
    var username as String = m.SubExpressionString(2)
    var password as String = m.SubExpressionString(3)
    if username.IsEmpty or password.IsEmpty then
      raise new DatabaseException( "Invalid credentials supplied." )
      Return nil
    end if
    
    var hostname as String = m.SubExpressionString(4)
    var port as Integer = m.SubExpressionString(5).ToInteger
    if hostname.IsEmpty or port = 0 then
      raise new DatabaseException( "Invalid connection details supplied." )
      Return nil
    end if
    
    var database as String = m.SubExpressionString(6)
    if database.IsEmpty then
      raise new DatabaseException( "Invalid database name supplied." )
      Return nil
    end if
    
    var result as new MySQLCommunityServer
    result.UserName = m.SubExpressionString(2)
    result.Password = m.SubExpressionString(3)
    result.Host = m.SubExpressionString(4)
    result.Port = m.SubExpressionString(5).ToInteger
    result.DatabaseName = m.SubExpressionString(6)
    
    Return result
  Else
    raise new RuntimeException( "Invalid URI string supplied." )
  End If
  
  Return Nil
End Function

Used as:

var m as MySQLCommunityServer
try
  m = MySQLFromURI( uri )
catch de as DatabaseException
  MessageBox( de.Message )
end try

if m <> nil then
  m.Connect
  
  '// Do whatever else here...
end if
1 Like