2015-11-18 8 views
5

मौजूद नहीं है, मैं सिम्फनी 2 में LEVENSHTEIN फ़ंक्शन को शामिल करने की कोशिश कर रहा हूं, हालांकि, मुझे अभी भी त्रुटियां मिलती हैं। चश्मा + मैं अब तक क्या किया है:सिम्फनी 2 - कस्टम डीक्यूएल फ़ंक्शन पंजीकृत है लेकिन

  • PostgreSQL 9.3
  • Levenshtein fuzzystrmatch विस्तार
  • खोल निष्पादन के माध्यम से समारोह परीक्षण में शामिल थे। बिल्कुल ठीक काम करता है:

    postgres=# SELECT levenshtein('test', 'text'); 
    levenshtein 
    ------------- 
          1 
    (1 row) 
    
  • जोड़ा गया DQL में समारोह:

    <?php 
    
    namespace AppBundle\DQL; 
    
    use Doctrine\ORM\Query\AST\Functions\FunctionNode; 
    use Doctrine\ORM\Query\Lexer; 
    use Doctrine\ORM\Query\Parser; 
    use Doctrine\ORM\Query\SqlWalker; 
    
    class LevenshteinFunction extends FunctionNode { 
    
        public $firstStringExpression = null; 
    
        public $secondStringExpression = null; 
    
        public function getSql(SqlWalker $sqlWalker) { 
         return 'LEVENSHTEIN(' . $this->firstStringExpression->dispatch($sqlWalker) . ', ' . $this->secondStringExpression->dispatch($sqlWalker) . ')'; 
        } 
    
        public function parse(Parser $parser) { 
         // levenshtein(str1, str2) 
         $parser->match(Lexer::T_IDENTIFIER); 
         $parser->match(Lexer::T_OPEN_PARENTHESIS); 
         $this->firstStringExpression = $parser->StringPrimary(); 
         $parser->match(Lexer::T_COMMA); 
         $this->secondStringExpression = $parser->StringPrimary(); 
         $parser->match(Lexer::T_CLOSE_PARENTHESIS); 
        } 
    } 
    

    Config.yml

    orm: 
        auto_generate_proxy_classes: "%kernel.debug%" 
        auto_mapping: true 
        dql: 
         numeric_functions: 
          LEVENSHTEIN: AppBundle\DQL\LevenshteinFunction 
    
  • समस्या: जब मेरे भंडार में निम्नलिखित codeblock क्रियान्वित , निम्न त्रुटियां होती हैं:

    $this->getEntityManager()->createQuery("SELECT LEVENSHTEIN('test', 'text') FROM AppBundle:User"); 
    return $query->getResult(); 
    

    SQLSTATE[42883]: Undefined function: 7 ERROR: function levenshtein(unknown, unknown) does not exist

मैं क्या याद आ रही है? डीक्यूएल/सिम्फनी/पीडीओ/... फ़ंक्शन को पहचानने क्यों नहीं है? किसी भी सहायताको बहुत सराहा जाएगा!

उत्तर

1

त्रुटि पोस्टग्रेस से आता है, दृश्यता के साथ एक समस्या की तरह लगता है।

अतिरिक्त मॉड्यूल fuzzystrmatch को निश्चित रूप से स्थापित किया जाना है। आपने स्पष्ट रूप से ऐसा किया है, या आपका फ़ंक्शन कॉल psql में भी काम नहीं करेगा।

यह psql में काम करता है, लेकिन अपने अनुप्रयोग में नहीं हैं, तो केवल कुछ ही संभव स्पष्टीकरण रहते हैं। स्पष्ट पहले:

  • आप एक ही डाटाबेस से जुड़े हैं? (उसी सर्वर, एक ही बंदरगाह, एक ही डीबी?)

  • आप एक ही उपयोगकर्ता से जुड़ रहे हैं? शायद ...

  • यदि किसी भिन्न उपयोगकर्ता से कनेक्ट हो रहा है (लेकिन किसी भी मामले में), तो जांचें कि आप एक ही खोज पथ पर काम कर रहे हैं या नहीं। या तो संबंध में चलाने के लिए और तुलना करें:

    SHOW search_path; 
    

    विवरण - और कैसे स्थापित करने के लिए search_path:

ध्यान रखें कि किसी भी एक्सटेंशन स्कीमा करने के लिए स्थापित किया जा सकता है आपकी पसंद। डिफ़ॉल्ट स्थापित करने के समय, जो आम तौर public है पर search_path ("वर्तमान स्कीमा" में पहली स्कीमा है, लेकिन मैं नहीं जानता कि अपनी स्थापना के बारे में दस्तावेज़:।

If not specified, and the extension's control file does not specify a schema either, the current default object creation schema is used.

को यह भागो

extension | schema | schema_owner |    schema_acl 

---------------+------------+--------------+------------------------------------- 
adminpack  | pg_catalog | postgres  | {postgres=UC/postgres,=U/postgres} 
plpgsql  | pg_catalog | postgres  | {postgres=UC/postgres,=U/postgres} 
fuzzystrmatch | public  | postgres  | {postgres=UC/postgres,=UC/postgres} 
tablefunc  | public  | postgres  | {postgres=UC/postgres,=UC/postgres} 
... 

तो schema_aclमें शामिल हैं:

SELECT e.extname AS extension, nsp.nspname AS schema 
    , r.rolname AS schema_owner, nsp.nspacl AS schema_acl 
FROM pg_extension e 
JOIN pg_namespace nsp ON nsp.oid = e.extnamespace 
JOIN pg_roles  r ON r.oid = nsp.nspowner 

आप की तरह कुछ मिलता है: चीजों की एक जोड़ी का निदान(U for USAGE), तो public भूमिका में पहुंच है, यानी सभी लोग।

तदनुसार अपने कनेक्शन के लिए search_path सेट करें या (पुनः-) एक दृश्यमान स्कीमा पर स्थापित करें और इसे काम करना चाहिए।

सैद्धांतिक रूप से, मालिक भूमिका या एक सुपर उपयोगकर्ता समारोह से ही EXECUTE अनुमति निरस्त कर दिया है हो सकता है ...

1

आपकी फ़ंक्शन क्लास मेरे लिए ठीक प्रतीत होती है, लेकिन आपकी कॉन्फ़िगरेशन गलत हो सकती है। यह वही है मैं अपने CAST समारोह के लिए है:

doctrine: 
    orm: 
     dql: 
      string_functions: 
       CAST: App\MyBundle\Doctrine\DBAL\Functions\Porgres\Cast 

आप ध्यान रखें कि आप कार्यों अर्थात string_functions, numeric_functions, datetime_functions के विभिन्न प्रकार के विभिन्न संग्रह है। उनमें से सभी आधिकारिक documentation में सूचीबद्ध हैं।

इसके अलावा, आपका कोड आपके कैश को साफ करने के ठीक बाद ठीक काम करना चाहिए।

संबंधित मुद्दे