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

paulwheeler paulwheeler at ...546...
Wed Aug 28 00:54:23 CEST 2013


   Bruce and Fabien,
   My  email a few days back gave the code that I am using to open sqlite
   databases. That code opens a db in any directory you have access to. Is
   there something I am not understanding about Bruce's question?
   The code is attached.
   paul

   On 08/27/2013 12:42 AM, Fabien Bodard wrote:

And then if you configure the connection ide you can use :


Connections["Connection1"].Open()


2013/8/26 Tobias Boege [1]<taboege at ...626...>

On Mon, 26 Aug 2013, Bruce wrote:

What syntax for "DatabaseURL As String"?

I'm trying to create a connection to an SQLite db in a different gambas
project source directory:

        $conn = New

Connection("/share/projects/gambas3_proj/horse/horseBO/.connection/bometa.conne
ction")

(and various other path strings to the connection definition).

All I get is "Malformed URL" error.

>From the sources, I deduce the following format (and it works here):

$TYPE://$USER@$HOST:$PORT/$DB

where the :$PORT part is optional.

So to connect to something like

hConn = New Connection
With hConn
  .Type = "mysql"
  .Login = "root"
  .Password = "toor"
  .Host = "localhost"
  .Port = 3306
  .Name = "test"
  .Open()
End With

you could write

hConn = New Connection("mysql://root@...40...:3306/test")
hConn.Passwort = "toor"
hConn.Open()

Regards,
Tobi


------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
[2]http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
[3]Gambas-user at lists.sourceforge.net
[4]https://lists.sourceforge.net/lists/listinfo/gambas-user

References

   1. mailto:taboege at ...626...
   2. http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
   3. mailto:Gambas-user at lists.sourceforge.net
   4. https://lists.sourceforge.net/lists/listinfo/gambas-user
-------------- next part --------------
This will allow you to open a connection anywhere. All you have to change is
   the "sName" and the .Host entry
   
   Enjoy!
   
   paul
   
   
   '' Put these at the  beginning of your program on your form named fMain:
   Public $hConn As New Connection
   Public sMyPath As String
   Public sAppPath As String
   
   
   '' Your routine to open the connection:
   Public Sub Open_DB()
       ' If you want to see the commands sent to the database then uncomment this line:
       ' DB.Debug = True
       ' For debug purposes only:
         Print "$hConn.Opened from fMain Form (s/b F) = " & Str($hConn.Opened)    

        sName = "MyDatabaseName.sqlite"
        ' For debug purposes only:
        Print "sName = " & sName             

        With $hConn
            .Type = "sqlite3"      ' DB type for your database
            .Host = "/share/projects/gambas3_proj/horse/
            .Name = sName          'Example: "MyDatabaseName.sqlite"
        End With

     ' I had multiple kinds of catch statements. This is for debugging the opening of a connection
        sTryMessage = "OpenConn"       
        Print "Try to open connection for use"
        
        Try $hConn.Open
        ' For debug purposes only:
        Print "$hConn.Opened from fMain Form (s/b T) = " & Str($hConn.Opened) 
        Print "Connection Host = " & $hConn.Host  
        
        Catch
        If sTryMessage = "OpenConn" Then
            If errorMessageHeader = "" Then
                errorMessageHeader = "Could not open DB connection in fMain Form Open on " & sName & " On " & sMyPath
                Print "Connection Open Error in fMain Form Open " & Error.Text
                Error.Raise(Error.Text & " in  fMain Form Open")
            End If
        Endif
   End


More information about the User mailing list