Modifying the SQL Statements

Archived from the Xataface Users forum.

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


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


generatedname — Tue Sep 18, 2007 12:10 pm

Thanks for the quick response Steve!

I’m going to give this a try.