Code Monkey home page Code Monkey logo

Comments (4)

kafoso avatar kafoso commented on August 15, 2024

You will probably need to do a native query for that to work out, and not parameterizing that specific value. Just make absolutely sure that the string is on the correct format to avoid SQL vulnerabilities. E.g. through a regular expression such as:

/^x'[0-9a-f]{32}'$/

from doctrine-firebird-driver.

e-belair avatar e-belair commented on August 15, 2024

Finally, I found another way to use it by sending binary as parameter
I'm using https://github.com/ramsey/uuid-doctrine

from doctrine-firebird-driver.

e-belair avatar e-belair commented on August 15, 2024

I created a user defined function to use the x'' syntax. I don't use it anymore but maybe it could be usefull:

namespace Application\Doctrine;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\InputParameter;
use Doctrine\ORM\Query\Lexer;

/**
 * Class XExtension
 * Usage in query: $qb->where('e.id = X(:id)')->setParameter('id', $value)
 * @package Application\Doctrine
 */
class XExtension extends FunctionNode
{
    /** @var InputParameter */
    private $stringPrimary = null;

    /**
     * @param \Doctrine\ORM\Query\SqlWalker $sqlWalker
     *
     * @return string
     * @throws \Doctrine\ORM\Query\AST\ASTException
     */
    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
    {
        $this->stringPrimary->dispatch($sqlWalker);
        return "x'".$sqlWalker->getQuery()->getParameter($this->stringPrimary->name)->getValue()."'";
    }

    /**
     * @param \Doctrine\ORM\Query\Parser $parser
     *
     * @return void
     * @throws \Doctrine\ORM\Query\QueryException
     */
    public function parse(\Doctrine\ORM\Query\Parser $parser)
    {
        $lexer = $parser->getLexer();
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->stringPrimary = $parser->InputParameter();

        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }
}

If you think it's a good idea, let me know and I'll make a PR. If not, close the ticket.

from doctrine-firebird-driver.

kafoso avatar kafoso commented on August 15, 2024

It seems to me that ramsey/uuid and ramsey/uuid-doctrine provide much of the answer and solution to your inquiry. You can convert the string to and from binary using hex2bin and unpack. For cohesion, you may even use \Ramsey\Uuid\Codec\StringCodec-> encodeBinary (...) and \Ramsey\Uuid\Codec\StringCodec->decodeBytes(...).

Your second reply with the code snippet is nice, but it does not belong in this library. The goal with this library is to tackle only the absolute fundamentals of the DBAL.

from doctrine-firebird-driver.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.