Modifying the SQL Statements

A place for users and developers of the Xataface to discuss and receive support.

Postby generatedname » Tue Sep 18, 2007 10:33 am

Hello,

I'm hoping you can help me.

There are some queries that are crashing my site because they are taking too long to process.

Basically any of the queries that have a select count(*), I need to change to select count(ID). But I cannot find any way to modify these queries, where are they used and how can I change them without breaking DF.

Thanks in advance!

-Kurtis
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Sep 18, 2007 11:26 am

In Dataface/QueryTool.php.

You can accomplish this by finding any line that says "select count(*) ...":
e.g.
$sql = "select count(*) from ".$this->_tablename;

And add a few lines before it:

$tableKeyNames = array_keys($this->_table->keys());
if ( count($tableKeyNames) <= 0 ) trigger_error("The table '$tablename' has no primary key. Please add one.", E_USER_ERROR);
$firstKeyName = $tableKeyNames[0];

And then change it to:
$sql = "select count(`$firstKeyName`) from ".$this->_tablename;

There are probably 3 places where this will need to be changed.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby generatedname » Tue Sep 18, 2007 12:10 pm

Thanks for the quick response Steve!

I'm going to give this a try.
generatedname
 
Posts: 53
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 25 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved