OpenDatabase problem with space characters in database names

Just starting out? Need help? Post your questions and find answers here.
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

OpenDatabase problem with space characters in database names

Post 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?
Last edited by DK5UR on Wed Sep 28, 2022 2:03 pm, edited 2 times in total.
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: OpenDatabase problem with space characters in database names

Post by Kiffi »

perhaps this one?

Code: Select all

host.s = "host=127.0.0.1 port=3306 dbname=" + Chr(34) + "mysql test" + Chr(34)
Hygge
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

Re: OpenDatabase problem with space characters in database names

Post by DK5UR »

Nope...
Result is

Code: Select all

Unknown database '"mysql'
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenDatabase problem with space characters in database names

Post by infratec »

Try this:

Code: Select all

host.s ="host=127.0.0.1 port=3306 dbname=`mysql test`"
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

Re: OpenDatabase problem with space characters in database names

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: OpenDatabase problem with space characters in database names

Post 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)
Egypt my love
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: OpenDatabase problem with space characters in database names

Post 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.
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

Re: OpenDatabase problem with space characters in database names

Post 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"
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

Re: OpenDatabase problem with space characters in database names

Post 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?
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: OpenDatabase problem with space characters in database names

Post by Little John »

Maybe replace the space character with %20 (like in URLs)? Just another guess.
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

Re: OpenDatabase problem with space characters in database names

Post 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.
Last edited by DK5UR on Wed Sep 28, 2022 4:13 pm, edited 1 time in total.
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: OpenDatabase problem with space characters in database names

Post by Kiffi »

square brackets?

Code: Select all

host.s = "host=127.0.0.1 port=3306 dbname=[mysql test]"
Hygge
DK5UR
User
User
Posts: 23
Joined: Mon Jun 23, 2008 9:44 pm
Location: Laubach

Re: OpenDatabase problem with space characters in database names

Post by DK5UR »

I have tried everything ", ', `, and [ - nothing helps
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: OpenDatabase problem with space characters in database names

Post 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.
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: OpenDatabase problem with space characters in database names

Post 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.
Last edited by Olli on Wed Sep 28, 2022 5:14 pm, edited 1 time in total.
Post Reply