NCC
Posts: 6
|
| Posted: 12/18/2008, 6:48 PM |
|
When hiding Grids I would also like to not run the component's SQL query for server performance reasons.
What's the best way to achieve this?
|
 |
 |
TonyReid
Posts: 159
|
| Posted: 12/19/2008, 2:21 AM |
|
You could use the before build select event and modify the sql dynamically based on what grids you are showing.
As an example - search the help topics for "Dynamically Modify the WHERE Clause"
_________________
-----------
PHP/indy Game Developer - http://www.AbsoluteBreeze.co.uk |
 |
 |
mentecky
Posts: 321
|
| Posted: 12/19/2008, 12:42 PM |
|
NCC,
I do this a lot... for example I don't want the SQL to run unless a date range is entered. Select your grid and in Before Build Select add code to test if you want the SQL to run or not... then just set the ds->SQL to "". That will prevent it from running.
For example:
if (CCGetParam("StartDate", "") == "")
{
$grid->ds->SQL = "";
}
I did that from memory so I hope it's right. It's at least pretty close.
Rick
_________________
http://www.ccselite.com |
 |
 |
NCC
Posts: 6
|
| Posted: 12/19/2008, 4:45 PM |
|
mentecky,
Your approach is exactly what I'm looking for but unfortunately setting SQL to "" doesn't stop the query from running.
I tried both of the following but the SELECT still runs and returns the results. Any idea why??
$recipe_article2->DataSource->SQL = "";
$recipe_article2->ds->SQL = "";
|
 |
 |
mentecky
Posts: 321
|
| Posted: 12/19/2008, 6:33 PM |
|
NCC,
Try moving it to Before Execute Select. I may have inadvertently lied to you with the other event.
(Not on my CCS computer right now so I can't look at code)
Rick
_________________
http://www.ccselite.com |
 |
 |
NCC
Posts: 6
|
| Posted: 12/19/2008, 6:37 PM |
|
Moving the statement to the Before Execute Select server event worked nearly.
Everything but the LIMIT get's cleared so the following error gets thrown 
Database Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0,25' at line 1
|
 |
 |
mentecky
Posts: 321
|
| Posted: 12/19/2008, 8:18 PM |
|
This is not my most elegant fix but... Change the code to:
$grid->ds->SQL = "SELECT 1";
It'll make a valid SQL statement but has next to no execution time.
Rick
_________________
http://www.ccselite.com |
 |
 |
NCC
Posts: 6
|
| Posted: 12/20/2008, 6:41 AM |
|
Thanks, Richard. This workaround is viable. I appreciate the help!
Wish list: Yes Software update the CCS API to NOT run SQL queries for hidden components.
|
 |
 |
Gena
Posts: 591
|
| Posted: 12/20/2008, 7:55 AM |
|
NCC, could you clarify please, what is "hidden components" ?
_________________
Gena |
 |
 |
NCC
Posts: 6
|
| Posted: 12/20/2008, 8:50 AM |
|
Gena,
By "hidden components" I mean components with their Visible property set to No.
It doesn't seem logical to hide an item from display and continue to process the components SQL query.
|
 |
 |
datadoit
|
| Posted: 12/20/2008, 12:55 PM |
|
If you hide your grid in the Page or Grid's BeforeShow event, then that
grid's datasource will not be run at all.
Page BeforeShow()
$Container->YourGrid->Visible = false;
This is verified in our v3.2.
|
|
|
 |
NCC
Posts: 6
|
| Posted: 12/20/2008, 7:00 PM |
|
datadoit,
Maybe I need to run an older version of CCS :). I'm running 4.1 and printing the query string from the query function verifies my situation with queries running for hidden components.
function query($Query_String) {
echo $Query_String . "<br><br>\n";
|
 |
 |
datadoit
|
| Posted: 12/21/2008, 5:46 AM |
|
For a test, create a grid that is enormously complex and something that
you know will take a while to run and load on a page. If you show it,
then the page will load slowly as the query is run. If you hide it,
then the page will load instantly. That will tell you that CCS is
indeed skipping the query (or grid) as it should if it's set to hidden
in the Page's BeforeShow event.
Another test could be to set a record form's datasource to something
like 'INSERT INTO YourTable SET YourField=Whatever'. Show the record
form and the insert is done. Hide the record form and the insert is not
done.
|
|
|
 |
dunechi1d
Posts: 23
|
| Posted: 01/26/2009, 1:05 PM |
|
The best way to make CCS not perform the SQL of a hidden grid is to make sure the grid is hidden in the page "After Initialize" event.
In the "After Initialize" event turn off all the grids on the page and then turn on only those needed for the current execution.
Danny
|
 |
 |