uuid
uuid copied to clipboard
How to search a partial uuid?
My transactions table uses a uuid which is stored as bytes in the database.
I would like to know how to search for a partial uuid? Obviously, since we are using bytes, the data is stored as a binary in the table so in theory I need to convert the partial uuid string to a binary and then to search on that.
Is there anyway to do this natively with UUID?
If I had a full UUID, I am simply going to use something like so:
$qb->andWhere('transactions.uuid = :uuid')->setParameter('uuid', Uuid::fromString($options['transactionUuid'])->getBytes());
But to search a partial uuid, I am looking to do something as follows:
$qb->expr()->like('transaction.uuid', Uuid:fromString(':search')->getBytes()),
But obviously the fromString requires a correctly formed uuid string as apposed to a partial.
I am not sure this is possible and perhaps is one of the downfalls of using bytes in the table as apposed to string.
Hi @chateaux ,
you could use lower()
and hex()
to convert the transaction.uuid into something searchable.
$qb->andWhere('LOWER(HEX(transactions.uuid)) LIKE :uuid')->setParameter('uuid', '%f68f66cd%');
It is not a solution withing this library but it should work. Although I have not tested the above line.
Best Sebastian