[Gambas-user] Two Databases at the same time...

T Lee Davidson t.lee.davidson at ...626...
Tue Dec 16 08:01:01 CET 2014


Hi Christian,

You really should have most of what you need to figure this out for yourself at:
http://gambaswiki.org/wiki/comp/gb.db/connection
http://gambaswiki.org/wiki/comp/gb.db/connection/open
http://gambaswiki.org/wiki/comp/gb.db/connection/exec
http://gambaswiki.org/wiki/comp/gb.db/connection/edit
http://gambaswiki.org/wiki/comp/gb.db/result


Though not SQL optimized nor transaction safe, maybe this example will help you get started:

Public Sub Main()

   Dim hConn1 As New Connection
   Dim hConn2 As New Connection
   Dim hResult1 As Result

   With hConn1
     .Type = "mysql"
     .Host = "localhost"
     .Login = "username"
     .Password = "passwd"
     .Name = "testdb1"
   End With

   Try hConn1.Open
   If Error Then Print "Cannot Open Database. Error = "; Error.Text

   With hConn2
     .Type = "mysql"
     .Host = "localhost"
     .Login = "username"
     .Password = "passwd"
     .Name = "testdb2"
   End With

   Try hConn2.Open
   If Error Then Print "Cannot Open Database. Error = "; Error.Text

   hResult1 = hConn1.Exec("select id, name from testdb1.those_records")
   For Each hResult1
     hConn2.Exec("update testdb2.these_records set this_name='" & hResult1!name & "' where this_id=" & hResult1!id)
   Next

End

You can also access the fields as a collection, ie. hResult1["id"], hResult1["name"]


Lee
__________

"Artificial Intelligence is no match for natural stupidity."


On 12/15/2014 01:10 PM, Christian e Ana Luiza Britto wrote:
> Hi,
> I need to work with 2 different databases at the same time, each one
> with his own tables. So, what I have to do to setup up the "Result"
> variables for each database? I wanna write a module that will read
> data from one database to update the another.
> Thanks,
> Christian
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>




More information about the User mailing list