User login

Biblioreference module keyword fetching SQL wrong turns

re[] = "n.type = 'biblio'";
$count = count($words);
for ($i = 0; $i < $count; $i++) {
$where[] = 'bk.word ' . $match_operators[$match];
// for multiple words we're going to have to string a bunch of these together with "or"
// first we took only the first word as a proof of concept
// now we're sticking with and, not or, so multiple words act as filtering
}
$args = $words;
$where_clause = $where ? 'where '. implode(' and ', $where) : '';

// right way -- actually, no need for db_rewrite_sql 'cause we aren't honoring node access-- or are we? i guess we have n.nid in there and that can be acted on
// $sql = db_rewrite_sql("select n.nid, n.title as node_title, n.type as node_type from {node} n $where_clause order by n.title, n.type");
// $result = db_query( limit %d", $limit);

// wrong in so many ways-- especially the where clause, must be or if we search
// for multiple words, but why does this work at all? in any case it does not work as intended.
// $sql = db_rewrite_sql("select count(bk.nid) as nidcount, bk.nid as nid, n.title as node_title from {biblioreference_keyword} bk left join {node} n on n.nid=bk.nid $where_clause group by bk.nid order by nidcount desc");
// this also doesn't work
// $sql = "select bk.nid as nid, n.title as node_title from biblioreference_keyword bk left join node n on n.nid=bk.nid where n.type = 'biblio' and bk.word like '%s%%'";
$sql = "select bk.nid as nid, n.title as node_title from {biblioreference_keyword} bk left join {node} n on n.nid=bk.nid " . $where_clause;
$limit = null;
$result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args);

(Special thanks to how to get a c with cedilla on Ubuntu for making it possible for me to log in to Agaric from .)

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.