[Gambas-user] hConnection = New Connection ( [ DatabaseURL As String ] ) Clarification

Tobias Boege taboege at ...626...
Wed Aug 28 13:47:21 CEST 2013


On Wed, 28 Aug 2013, Bruce wrote:
> First off, thanks everyone for your answers - all are correct.
> 
> My original question was purely about the syntax of the Connection
> constructor, specifically about the optional DatabaseURL parameter.
> 
> Clarification 1: According to the help there are three ways to
> initialise a connection:
> a) by directly setting the connection properties, (as Paul describes)
> b) by using a predefined connection, (as Fabian describes)
> c) by using the constructor DatabasURL parameter (as Tobi describes).
> 
> Regarding the latter, the help is somewhat silent as to the syntax of
> that parameter.  Thanks to Tobi, I now see it to be:
> 
>         $TYPE://$USER@$HOST:$PORT/$DB
> 
> Clarification 2: This syntax also provides a clue that this method can
> only work where the underlying database is a server process e.g. mysql
> or postgresql and I don't think it can work for sqlite. 
> 

It does work like $TYPE://$PATH because for sqlite, the Host part is a
directory and the DB is a file relative to the directory. The parser takes
the last part of the string (after the last /) as the DB name, the stuff
before as Host. It seems like the $USER path is also optional... I just
tested it:

$hConn = New Connection("sqlite3:///home/tab/Kontakte.sqlite")

> In fact, contrary to Tobi's experience, I still cannot get this to work
> (for a postgresql database).  Here I have a server machine "bluecow"
> that has three postgresql server processes running on it (called say
> "prod", "dev" and "test" each using a separate port). So, if I
> understand Tobi's answer:
> 
>         $conn = New Connection("postgresql://bb@...2711...:5432/horse")
> 
> where the database name is "horse" and the dev server is using port
> 5432, should create a valid connection, but I still get this "Malformed
> URL" error??? 

I just installed postgresql and the following works. I followed the Arch
Linux wiki article for setting it up (created the DB user 'root') and the
following does indeed work (with the 'test' database created via Database
example of Gambas):

$hConn = New Connection("postgresql://root@...40...:5432/test")

I don't know what's wrong on your side, sorry...

Regards,
Tobi




More information about the User mailing list