Speeding Up ODBC Query

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

Speeding Up ODBC Query

Post by johnmiller1950 » Fri Feb 03, 2012 7:51 pm

Greetings All,

I use a program I wrote to access a company database on a server using OBDC. My program creates special reports from the database. If I run my program on the server, it performs the queries very rapidly. However, when we use the program on a desktop connected to the server, the whole process takes anywhere from 10 to 20 times as long. I have been doing some reading about this kind of thing, and it has been suggested that when you do a query, make sure that the query is being handled by the server with only the results being sent to the desktop. Is sounds like the solution I'm looking for, but I'm not sure how to do this. Can this be done from within LiveCode?

You help is greatly appreciated.

John Miller

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Speeding Up ODBC Query

Post by Mark » Sat Feb 04, 2012 1:22 pm

Hi John,

Just try it and let us know the results. If it doesn't work, maybe we can help.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

Re: Speeding Up ODBC Query

Post by johnmiller1950 » Sat Feb 04, 2012 5:47 pm

Mark,

Try what???


John

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Speeding Up ODBC Query

Post by Mark » Sat Feb 04, 2012 6:44 pm

Hi John,

Try making one long query that does all the sorting, filtering etc. on the server instead of a number of small queries that are processed by LiveCode.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

Re: Speeding Up ODBC Query

Post by johnmiller1950 » Mon Feb 06, 2012 3:20 pm

Mark,

I am completely confused. Is this a function of the ODBC Query, or is it a LiveCode scripting issue? What LiveCode command/function would I use to pass such a query? I'm not sure how to proceed.

Thanks,
John

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Speeding Up ODBC Query

Post by Mark » Mon Feb 06, 2012 3:37 pm

Hi John,

How do you currently retrieve data from the database? Can you post a sample of your code?

Usually, you use the revExecuteSQL command or the revQueryDatabase command. The trick is to write one very long query that does as much as possible instead of writing many short queries and using LiveCode scripts to process the data from the queries.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

johnmiller1950
Posts: 116
Joined: Mon Apr 30, 2007 3:33 pm

Re: Speeding Up ODBC Query

Post by johnmiller1950 » Mon Feb 06, 2012 4:09 pm

Mark,

Here is my main query code. How would I compact this into one long query?

Thanks,
John

put "SELECT itemNum,name1,class,cost,name2 FROM icitem" into dbCommand
put revOpenDatabase("ODBC","Company 0",,"UserName","Password") into dbID -- databaseID
put revQueryDatabase(dbID,dbCommand) into rsID
put revDataFromQuery (tab,return,dbID,dbCommand) into XX
revCloseCursor rsID
revCloseDatabase dbID

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Speeding Up ODBC Query

Post by Mark » Mon Feb 06, 2012 4:24 pm

Hi John,

You're running your query twice. Just remove

Code: Select all

put revQueryDatabase(dbID,dbCommand) into rsID 
and all should be fine.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply