-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"SQLSTATE[HY093]: Invalid parameter number" with Laravel 10 #6852
Comments
Thanks. This seems at first glance to be an issue with Dolt handling that CTE. @max-hoffman is the expert in these. |
Nevermind, you said it returned in Dolt but the value on the wire is messing up Laravel. Not @max-hoffman :-) |
We may be able to do this faster if you pop over to our Discord. Could you run Dolt in Also, we have had problems with |
Also, if you give me a step-by-step guide to reproduce the error on my Mac, I'm happy to do it and start to debug on my side. I have Laravel installed already from supporting another customer :-) |
Query with original setup and traceSo it looks like the query doesn't even hit dolt(?), running with trace and executing the page yields:
so there is no trace of the query even being sent over to Dolt, which is weird. Query when ATTR_EMULATE_PREPARES is trueInterestingly enough by setting PDO::ATTR_EMULATE_PREPARES => true it does work and Dolt generates this log for the query:
Test case creationTo create a test case: composer create-project laravel/laravel dolt-testcase
cd dolt-testcase
composer require staudenmeir/laravel-adjacency-list Edit the .env file and change the DB_ connection parameters. CREATE TABLE `ticket_esemenyek` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`ticket_id` BIGINT(20) UNSIGNED NOT NULL,
`parent_id` BIGINT(20) UNSIGNED NULL DEFAULT NULL,
`creator_id` BIGINT(20) UNSIGNED NOT NULL,
`esemeny_neve` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`created_at` TIMESTAMP NULL DEFAULT NULL,
`updated_at` TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `ticket_id` (`ticket_id`)
) ENGINE=InnoDB;
INSERT INTO `ticket_esemenyek` (`id`, `ticket_id`, `parent_id`, `creator_id`, `esemeny_neve`, `created_at`, `updated_at`) VALUES (1, 1, NULL, 1, 'Item 1', NULL, NULL);
INSERT INTO `ticket_esemenyek` (`id`, `ticket_id`, `parent_id`, `creator_id`, `esemeny_neve`, `created_at`, `updated_at`) VALUES (2, 1, 1, 1, 'Item 1.1', NULL, NULL);
INSERT INTO `ticket_esemenyek` (`id`, `ticket_id`, `parent_id`, `creator_id`, `esemeny_neve`, `created_at`, `updated_at`) VALUES (3, 1, 2, 1, 'Item 1.1.1', NULL, NULL);
INSERT INTO `ticket_esemenyek` (`id`, `ticket_id`, `parent_id`, `creator_id`, `esemeny_neve`, `created_at`, `updated_at`) VALUES (4, 1, 2, 1, 'Item 1.2.1', NULL, NULL);
INSERT INTO `ticket_esemenyek` (`id`, `ticket_id`, `parent_id`, `creator_id`, `esemeny_neve`, `created_at`, `updated_at`) VALUES (5, 1, NULL, 1, 'Item 2', NULL, NULL); Create a TicketEsemenyek.php in app\Models with: <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;
class TicketEsemenyek extends Model
{
use HasRecursiveRelationships;
protected $table = "ticket_esemenyek";
protected function getPathSeparator(): string
{
return "'/'";
}
} in routes\web.php change the original route for "/" to: Route::get('/', function () {
dd(\App\Models\TicketEsemenyek::tree()->get());
}); Now in your terminal run: php artisan serve and you can access the local server at http://127.0.0.1:8000/ showing you this exact error message of "SQLSTATE[HY093]: Invalid parameter number". If you now copy the generated query (that long thing in the top box) and run it in Dolt it will work and give the correct result. If you want to set ATTR_EMULATE_PREPARES then you can in config\database.php in the big array under mysql add this to the options array: PDO::ATTR_EMULATE_PREPARES => true, and now the query runs normally. |
Thanks for the repro! I'm glad we found a workaround for you with setting I'll test this today and see if we can figure out how to fix root cause. |
@kde99, thank you for the awesome repro instructions! I've got your repro running in the debugger now, and I see where the Vitess library we use isn't finding the bind variable in the statement that's being prepared. I'm stepping through that code now to see what's going on and will update again soon. This is likely some small bug where a node in the parsed tree isn't properly dispatching to its children, but we should know more soon. |
Update... as we were suspecting, part of the statement wasn't getting properly traversed when the Vitess layer was searching for bind variables in the statement being prepared, so it missed the bind var and then complained about the execute statement sending the wrong number of bind vars. PR dolthub/vitess#284 fixes that issue and I verified that with that change, your repro now loads a page successfully. I'll work on getting this bug fix released for you today, and I'm also going to spend some time looking at why we didn't have any clues in the logs about what was going on. Seems like there may be a gap there we need to fill, too. We also have a new test harness we're working on that should be able to help proactively identify issues like this before customers hit them. I'll sync up with that developer and we'll brainstorm about how we can use that new harness to get more coverage over our prepared tests. The way we currently test prepared statements doesn't go over a sql-server connection, so the code in the Vitess layer doesn't get executed and that's why our tests missed this case. Thank you again for taking the time to report this issue and provide such an easy to use repro! We'll keep you updated as we get the fixed released. |
@kde99 – We just released Dolt version 1.21.1 with the fix for this issue. Thanks for letting us know about this problem so we could fix it! 🙏 Let us know if you hit any other issues and we'll be happy to help. |
Hello everyone!
I am using Laravel 10.28 for my project and added the laravel-adjacency-list package to my project and tried to use it, but was greeted by this error message. (You can find the issue I submitted there at staudenmeir/laravel-adjacency-list#204 )
I tried migrating my DB back to MySQL 8 and test there (same code, just different DB), and it runs there so I assume the issue is with something related to Dolt. I have just installed the latest Dolt (1.21.0) and the issue is still present. I have shared the error screen on Flare (see https://flareapp.io/share/Lm89AYMP#context-request-headers ). The query in question is (that should be running, i.e. already parameters bound):
The query is correct and gives correct results in both Dolt and MySQL when ran from the console directly.
I have logged out the query and the binding Laravel is trying to execute (dd at runQueryCallback) :
I am a bit at loss here since there is only one parameter and only one binding so should work, but for some reason (not sure if PHP, PDO, Laravel, or something else related) it doesn't work under Dolt, but does under MySQL with only the DB server being different.
I am hoping somebody with a bit more knowledge can look into this issue, and have it resolved.
Thanks for your help.
The text was updated successfully, but these errors were encountered: