Page 1 of 2

OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 11:33 am
by DK5UR
I have a database on the client side named "mysql test". I know this is not a smart way to name the database, but I can't change it.
I use this code snippet to retrieve the table names from the database:

Code: Select all

UseMySQLDatabase()
host.s = "host=127.0.0.1 port=3306 dbname=mysql test" -> results in table name list for database mysql
;host.s = Chr(34)+"host=127.0.0.1 port=3306 dbname=mysql test"+Chr(34) -> results in table name list for database mysql
;host.s = "host=127.0.0.1 port=3306 dbname=`mysql test`" ->  results in error message: Unknown database '`mysql'
;host.s = "host=127.0.0.1 port=3306 dbname='mysql test'" -> results in error message: Unknown database ''mysql'
;host.s = "host=127.0.0.1 port=3306 dbname=" + Chr(34) + "mysql test" + Chr(34) -> results in error message: Unknown database '"mysql'
If OpenDatabase(0, host, "user", "password")
  If Not DatabaseQuery(0,"SHOW TABLES")
    Debug "DatabaseQuery: "+DatabaseError()
  Else
    While NextDatabaseRow(0)
      Debug GetDatabaseString(0,0)
    Wend
    FinishDatabaseQuery(0)
    CloseDatabase(0)
  EndIf
Else
  Debug "OpenDatabase:"+DatabaseError()
EndIf
As I see it, the "dbname" is probably passed internally only from the equal sign to the first space. Bug or feature?
Is there a way to mask the space?

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 12:03 pm
by Kiffi
perhaps this one?

Code: Select all

host.s = "host=127.0.0.1 port=3306 dbname=" + Chr(34) + "mysql test" + Chr(34)

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 12:07 pm
by DK5UR
Nope...
Result is

Code: Select all

Unknown database '"mysql'

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 12:45 pm
by infratec
Try this:

Code: Select all

host.s ="host=127.0.0.1 port=3306 dbname=`mysql test`"

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 12:50 pm
by DK5UR
infratec wrote: Wed Sep 28, 2022 12:45 pm Try this:

Code: Select all

host.s ="host=127.0.0.1 port=3306 dbname=`mysql test`"
Already tested... Unfortunately no success

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 1:50 pm
by RASHAD
Shoot in the dark
Try

Code: Select all

host.s = Chr(34)+"host=127.0.0.1 port=3306 dbname=mysql test"+Chr(34)

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 1:57 pm
by infratec
No, this does also not work.
It is a problem of the PB OpenDatabase() procedure.

At the moment I check the packets with WireShark and always the dbname is truncated at the space character.

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 1:59 pm
by DK5UR
RASHAD wrote: Wed Sep 28, 2022 1:50 pm Shoot in the dark
...
Sorry RASHAD, also not the result i needed... Only the table list of the databse "mysql"

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 2:01 pm
by DK5UR
infratec wrote: Wed Sep 28, 2022 1:57 pm At the moment I check the packets with WireShark and always the dbname is truncated at the space character.
That's exactly what i mentioned... So it seems to be a bug, of the OpenDatabase function, doesn't it?

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 3:58 pm
by Little John
Maybe replace the space character with %20 (like in URLs)? Just another guess.

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 4:06 pm
by DK5UR
Little John wrote: Wed Sep 28, 2022 3:58 pm Maybe replace the space character with %20 (like in URLs)? Just another guess.
Doesn't helps leads to "Unknown database 'mysql%20test'".
Also any try with escape sequences ends in no result.

Problem is that the dbname is truncated at the first space character.

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 4:07 pm
by Kiffi
square brackets?

Code: Select all

host.s = "host=127.0.0.1 port=3306 dbname=[mysql test]"

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 4:09 pm
by DK5UR
I have tried everything ", ', `, and [ - nothing helps

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 4:41 pm
by Olli
Replace the space with a escaped character :

%20 is one of their types

test again :

%32 (decimal)

/space

/space;

&20;



&32;

etc... Test everything, while it's been created, it can be managed.

And don't nest your expression between anything.

Re: OpenDatabase problem with space characters in database names

Posted: Wed Sep 28, 2022 4:48 pm
by Olli
don't touch anything !

https://stackoverflow.com/questions/506 ... n-its-name

dbname=`your_data_base`

replace with underscore, and... nest your expression (i was wrong) between your special quote characters :`

edit: no good again, it was an advice only...

Could we reproduce your bug ?
Could we create a symbolic database with space in the name ? (I do know anything in mySql, too slow)

It seems that if backticks are not okay, it's a bug.