Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [mysql] nie moge stworzyc TEMPORARY TABLE
Forum PHP.pl > Forum > Przedszkole
pturkowski
Witam,
na pewno moge tworzyc tabele, bo zainstalowalem Drupala a potem dodatkowe moduly tworzyly dodatkowe tabele, jednak kiedy chcialbym szukac informacji dostaje taki komunikat:

Czy to sa ustawienie uzytkownika (brak "permissions"), czy moze cos innego? Pierwszy raz w zyciu widze taki komunikat.

Dziekuje i pozdrawiam.
toolmaniak
No generalnie jest to brak przywileju do tworzenia tabel tymaczasowych dla danego użytkownika w tej bazie. generalnie wystarczyło by byc może coś w stylu:

mysql>GRANT CREATE TEMPORARY TABLES ON *.* TO 'web75-sveadmin'@*;


Ale, jak nadmieniłeś że chodzi o Drupal, to problem leży też po stronie tegoż systemu a konkretnie dwóch modułów tj.: modules/search.module gdzie kod funkcji do_search trzeba zmienić mniej więcej tak:

  1. <?php
  2. function do_search($keywords, $type, $join1 = '', $where1 = '1', $arguments1 = array(), $select2 = 'i.relevance AS score', $join2 = '', $arguments2 = array(), $sort_parameters = 'ORDER BY score DESC') {
  3. $query = search_parse_query($keywords);
  4. global $user;
  5.  
  6. if ($query[2] == '') {
  7. form_set_error('keys', t('You must include at least one positive keyword with %count characters or more.', array('%count' => variable_get('minimum_word_size', 3))));
  8. }
  9. if ($query === NULL || $query[0] == '' || $query[2] == '') {
  10. return array();
  11. }
  12.  
  13. // First pass: select all possible matching sids, doing a simple index-based OR matching on the keywords.
  14. // 'matches' is used to reject those items that cannot possibly match the query.
  15. $conditions = $where1 .' AND ('. $query[2] .") AND i.type = '%s'";
  16. $arguments = array_merge($arguments1, $query[3], array($type, $query[4]));
  17. $result = db_query_temporary("SELECT i.type, i.sid, SUM(i.score * t.count) AS relevance, COUNT(*) AS matches FROM {search_index} i INNER JOIN {search_total} t ON i.word = t
    .word $join1 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d"
    , $arguments, 'temp_search_sids');
  18.  
  19. // Calculate maximum relevance, to normalize it
  20. $normalize = db_result(db_query('SELECT MAX(relevance) FROM temp_search_sids'.$user->sid));
  21. if (!$normalize) {
  22. return array();
  23. }
  24. $select2 = str_replace('i.relevance', '('. (1./ $normalize) .' * i.relevance)', $select2);
  25.  
  26. // Second pass: only keep items that match the complicated keywords conditions (phrase search, negative keywords, ...)
  27. $conditions = '('. $query[0] .')';
  28. $arguments = array_merge($arguments2, $query[1]);
  29. $result = db_query_temporary("SELECT i.type, i.sid, $select2 FROM temp_search_sids".$user->sid." i INNER JOIN {search_dataset} d ON i.sid = d.sid AND i.type = d.type $join
    2 WHERE $conditions $sort_parameters"
    , $arguments, 'temp_search_results');
  30. if (($count = db_result(db_query('SELECT COUNT(*) FROM temp_search_results'.$user->sid))) == 0) {
  31. db_query('DROP TABLE temp_search_results'.$user->sid);
  32. db_query('DROP TABLE temp_search_sids'.$user->sid);
  33. return array();
  34. }
  35. $count_query = "SELECT $count";
  36.  
  37. // Do actual search query
  38. $result = pager_query("SELECT * FROM temp_search_results".$user->sid, 10, 0, $count_query);
  39. $results = array();
  40. while ($item = db_fetch_object($result)) {
  41. $results[] = $item;
  42. }
  43.  
  44. db_query('DROP TABLE temp_search_results'.$user->sid);
  45. db_query('DROP TABLE temp_search_sids'.$user->sid);
  46.  
  47. return $results;
  48. }
  49. ?>


oraz includes/database.mysql.inc którego zresztą ścieżkę wypluwa przy Twoim zapytaniu. Tam trzeba z kolei zmienić wywołanie funkcji db_query_temporary na następujące:

  1. <?php
  2. function db_query_temporary($query) {
  3. $args = func_get_args();
  4. $tablename = array_pop($args);
  5. array_shift($args);
  6.  
  7. global $user;
  8.  
  9. db_query("DROP TABLE IF EXISTS ".$tablename.$user->sid);
  10. $query = preg_replace('/^SELECT/i', 'CREATE TABLE '.$tablename . $user->sid.' SELECT', db_prefix_tables($query));
  11. if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
  12. $args = $args[0];
  13. }
  14. _db_query_callback($args, TRUE);
  15. $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
  16. return _db_query($query);
  17. }
  18. ?>


Spróbuj, może to coś da. Pozdrówka
pturkowski
A jesli uda mi sie uzyskac ten przywilej to czy nadal powinienem poprawiac te dwa pliki ?
toolmaniak
Cytat(pturkowski @ 12.08.2007, 00:14:28 ) *
A jesli uda mi sie uzyskac ten przywilej to czy nadal powinienem poprawiac te dwa pliki ?



Trudno mi jednoznacznie na to odpowiedzieć. Dałem prawdopodobne (bo trudno cokolwiek rokować na 100%) rozwiązanie tego problemu, ale możesz wcześniej oczywiście spróbować grant-em jak masz dostęp do konsoli mysql lub po prostu w skrypcie.

GRANT CREATE TEMPORARY TABLES ON web75-sveadmin.* TO 'web75-sveadmin'@*;
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.