# Rohes SQL im Plugin / Controller

**URL:** <https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337>\
**Category:** Shopware 6 (German)\
**Created:** [23. Januar 2025 um 14:51 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337 "2025-01-23T14:51:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [23. Januar 2025 um 14:51 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/1 "2025-01-23T14:51:07Z")

</div>

Hi,  
ich habe hier folgendes Beispiel, leider gibt es kein Ergebnis zurück, wahrscheinlich weil DBAL nicht reines SQL zulässt?

```auto
use Doctrine\DBAL\Connection;  
...
class XXXController extends StorefrontController
   {
      private Connection $connection;
      …
      public function __construct(Connection $connection) { 
          $this->connection = $connection;
      }
      ...
      public function (...) {
      $sql = "SELECT * FROM example AS pes WHERE pes.order_id IN ($placeholders)";

      $pickwareStock = $this->connection->fetchAllAssociative($sql, $orderIds);
     }
   }

```

Für ein Beispiel mit rohem SQL wäre ich sehr dankbar.

Danke und Gruss

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [23. Januar 2025 um 15:00 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/2 "2025-01-23T15:00:44Z")

</div>

Ich glaube dieses Beispiel könnte dir helfen: [shopware/src/Core/Content/Product/Stock/StockStorage.php at trunk · shopware/shopware · GitHub](https://github.com/shopware/shopware/blob/trunk/src/Core/Content/Product/Stock/StockStorage.php#L117)

Viele Grüße

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [25. Januar 2025 um 13:22 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/3 "2025-01-25T13:22:23Z")

</div>

Vielen Dank für das Beispiel, jedoch funktioniert das nicht.  
Irgendwie werden die Hex Werte beim umwandeln in Uuid nicht korrekt ausgeführt.  
Gibt es da eine möglichkeit echtes rohes SQL zu machen anstatt dieses Verkrüppelung?

Danke und Gruss.

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [25. Januar 2025 um 14:21 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/4 "2025-01-25T14:21:47Z")

</div>

Hm?! Wieso Verkrüppelung? Shopware arbeitet mit UUIDs und für direkte SQL Abfragen müssen diese in die entsprechenden binaries übersetzt werden. Das IST „rohes“ SQL.

Viele Grüße

---

<div class="post-metadata">

**Author:** ![Max\_Shop](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Max\_Shop](https://forum.shopware.com/u/Max_Shop)\
**Post date:** [26. Januar 2025 um 10:58 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/5 "2025-01-26T10:58:18Z")

</div>

> [@EikeBrandtWarneke](#):
>
> Wieso Verkrüppelung?

Ich glaube, sein Punkt bezieht sich auf Uuid::fromHexToBytes($context-\>getVersionId())

hex2bin($uuid) steckt hinter der Methode. Alternativ in SQL direkt per use HEX() „to input and UNHEX() to output“.

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [26. Januar 2025 um 16:27 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/6 "2025-01-26T16:27:03Z")

</div>

```auto
$orderIdsBin = Uuid::fromHexToBytesList($orderIds); // $orderIds ist ["019...","019...",...]

 $pickwareStock = $this->connection->fetchAllAssociative(
    "SELECT * FROM pickware_erp_stock AS pes WHERE pes.order_id IN (:orderIdsBin)",
    ['orderIdsBin' => $orderIdsBin],
    ['orderIdsBin' => ArrayParameterType::BINARY]
 );

```

Mit Verkrüppelung meine ich, dass es viele Hinweise Im Netz gibt wie es gehen müsste. mit/ohne prepare(), mit/ohne SQL,SQL als variable, mit/ohne executeQuery() Jetzt habe ich alles ausprobiert und nur executeStatement() gibt mir eine 1…

Danke und Gruss.

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [26. Januar 2025 um 16:43 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/7 "2025-01-26T16:43:52Z")

</div>

Das sieht mir doch soweit richtig aus? Gibts irgendwelche Fehlermeldungen - oder wo ist nun konkret das Problem?

Viele Grüße

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [26. Januar 2025 um 18:59 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/8 "2025-01-26T18:59:41Z")

</div>

Hi,  
leider gibt es keinen Fehler.  
Rückgabewert bei gettype() ist Array. count(Array) = 1, aber es ist „nichts“.  
Direkt in phpmyadmin die SQL und ich erhalte ein Ergebnis.  
Direkt die komplette fertige SQL reingemacht und ich bekomme nichts. \>` $sql = "SELECT * FROM pickware_erp_stock AS pes WHERE pes.order_id IN (UNHEX('0192d8e1941f737eb99bc43c1564870e'),UNHEX('0192d....` usw

- executeQuery()
- fetchAssociative()
- fetchAllKeyValue()
- fetchAllAssociativeIndexed()

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [26. Januar 2025 um 20:38 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/9 "2025-01-26T20:38:01Z")

</div>

Die Syntax ist korrekt, sonst würde MySQL einen Fehler werfen. Die Parameter sind korrekt, sonst würde doctrine einen Fehler werfen. Es werden also schlichtweg keine Datensätze gefunden.

Was ergibt ein dd($pickwareStock)? Was ergibt ein dd($pickwareStock) wenn du den WHERE Teil weglässt.

Viele Grüße

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [26. Januar 2025 um 21:23 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/10 "2025-01-26T21:23:46Z")

</div>

dd($pickwareStock) bekomme ich folgendes ergebnis. das ist ja schonmal was, danke für die info.

```auto
 array:1 [▼
  b"<Aâ‗Ì¸L´øøV6ü¦å▒" => array:15 [▼
    "quantity" => "1"
    "product_id" => b"
\x01
’|';épß¦ÊtßS cf"
    "product_version_id" => b"
\x0F
©
\x1C
ãéjKÂ¾KÙÎu,4%"
    "location_type_technical_name" => "order"
    "warehouse_id" => null
    "bin_location_id" => null
    "order_id" => b"
\x01
’Øá”
\x1F
s~¹›Ä<
\x15
d‡
\x0E
"
    "order_version_id" => b"
\x0F
©
\x1C
ãéjKÂ¾KÙÎu,4%"
    "stock_container_id" => null
    "goods_receipt_id" => null
    "return_order_id" => null
    "return_order_version_id" => b"
\x0F
©
\x1C
ãéjKÂ¾KÙÎu,4%"
    "special_stock_location_technical_name" => null
    "created_at" => "2025-01-23 12:26:54.753"
    "updated_at" => null
  ]
]

```

ist denn dann an meiner ausgabe im trig was falsch?

```auto
return $this->renderStorefront('@MyTheme/storefront/page/account/backlog.html.twig', [
            "pickwareStock" => $pickwareStock
        ]);

```

wo das hier steht:

```auto
let pickwareStock = {{ pickwareStock | json_encode | raw }};

```

Danke und Gruss

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [27. Januar 2025 um 06:13 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/11 "2025-01-27T06:13:15Z")

</div>

Mensch @brettvormkopp, du bist doch nun lange genug dabei. Hör doch bitte auf uns immer wieder nur stückchenweise anzufüttern und uns immer die Hälfe zu verschweigen ☹

Welche twig Ausgabe meinst du? Was genau „ist falsch“? Wo und in welchem Zusammenhang steht dein „let pickwareStock…“?

Was du aber auf jeden Fall tun solltest, wenn du mit den Daten weiterarbeiten möchtest: am besten die binarys values direkt in der SQL Abfrage in hex zu rechnen:

SELECT LOWER(HEX(id)) AS id, location\_type\_technical\_name, LOWER(HEX(order\_id)) AS order\_id …

Viele Grüße

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [27. Januar 2025 um 07:01 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/12 "2025-01-27T07:01:44Z")

</div>

Hi, ja du hast recht. Sorry.

Danke für die Lösung.

Wie schafft es den phpmyadmin mit einer custom Query die binary in hex zu wandeln als ergebnis, wenn ich dort die gleiche Query eingebe? Wie wandeln die das um zu einem lesbaren ergebnis?

Danke und Gruss.

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [27. Januar 2025 um 07:27 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/13 "2025-01-27T07:27:48Z")

</div>

Wie oben bereits geschrieben kannst du LOWER(HEX(id)) nutzen, um die binary in einen (lesbaren) hex umzuwandeln.

Viele Grüße

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/2/9/29c7587ba660f00e4995d1743162782e5d6d8653.svg) [@system](https://forum.shopware.com/u/system)\
**Post date:** [26. Februar 2025 um 07:28 UTC](https://forum.shopware.com/t/rohes-sql-im-plugin-controller/106337/14 "2025-02-26T07:28:09Z")

</div>

Dieses Thema wurde automatisch 30 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.
