Can SQL Yoga keep two database connections?

This is the place to post technical queries about SQL Yoga

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller, trevordevore

Post Reply
trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Can SQL Yoga keep two database connections?

Post by trevordevore » Fri Oct 11, 2013 2:47 pm

[This post is an archive from the old SQL Yoga forums]

Hi Trevor and others,

I have a working application with SQL Yoga here. I want to sync my local SQLite database with a remote PostgreSQL database, can I create a new dbobject? If I create a new one, and set it as default, will I loose the one as default now (sqlite)?

Do you have a screen steps goodie showing us how do it?

Thanks in advance
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Can SQL Yoga keep two database connections?

Post by trevordevore » Fri Oct 11, 2013 2:48 pm

Here is a brief lesson that discusses how to work with multiple Connection objects.

How To Work With Multiple Connection Objects

I also added a lesson that discusses how to work with multiple Database objects:

How To Work With Multiple Database Objects
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Can SQL Yoga keep two database connections?

Post by trevordevore » Fri Oct 11, 2013 2:48 pm

Trevor,

Again thanks for the wonderful tutorials. Screensteps makes everything easy.

Even though I followed them, I could not get it to work. I worked by building my application normally using GLX APP with a local sqlite connection that was the default connection. I never set its name, it is the default database and the default connection. Then later in development, I tried creating another database object, pointing to a different database using a postgresql connection. I could not get it to work and in the process, I messed my default connection and in the end, lost the whole stuff. I use mercurial so it was just the case of reverting to the commit before me wrecking everything but still, it would be a nice addition to have a how to for users that already have a default database and connection set, like hey, need one more database, here how you do it!
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Can SQL Yoga keep two database connections?

Post by trevordevore » Fri Oct 11, 2013 2:48 pm

I worked by building my application normally using GLX APP with a local sqlite connection that was the default connection. I never set its name, it is the default database and the default connection."
At this point you have a Database object named "default".
Then later in development, I tried creating another database object, pointing to a different database using a postgresql connection. I could not get it to work and in the process, I messed my default connection and in the end, lost the whole stuff."
Can you add the code you are using to do this? Seeing what you are doing so I can spot the mistakes makes it easier to see how the lessons need to be changed.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Can SQL Yoga keep two database connections?

Post by trevordevore » Fri Oct 11, 2013 2:48 pm

Trevor,

again thanks for the always quick replies. I ended up writting the remote database code using plain RevDB and of course I am not happy with it so I am going to give another try to my skills at multiple connections with SQL Yoga. Can you please tell me if the outline below would work?

I already have a default database and connection serialized to a rev button object.

Code: Select all

dbobject_createObject "remote"

dbobject_set "storage object", the long id of button "Remote Database Object Storage", "remote"

dbconn_createObject "default connection", "postgresql", empty, "remote"

dbobject_save

use on open card:

dbobject_createFromObject the long id of button "Remote Database Object Storage", "remote"

dbconn_set <set all postgress params>, "default connection", "remote"

dbconn_connect "default connection", "remote"
Will this work?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Can SQL Yoga keep two database connections?

Post by trevordevore » Fri Oct 11, 2013 2:49 pm

Yes, that code should work. The thing to keep in mind with multiple database objects is that you HAVE to tell SQL Yoga which database object you are targeting if you are not targeting the default target (sqlyoga_getDefaultDatabase()).

This would be much easier if we had objects in Rev that we could call methods from rather than just having libraries.

I've started working on a plugin that will help you manage Database and Connection objects. It allows you to create them and quickly see properties and perform some other operations. Not ready for general use yet but if you want a copy email me.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply

Return to “SQL Yoga”