<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Nette Framework forum : Using Nette Framework : Database &amp; ORM : How to get the generated sql query with Nette\Database\Explorer</title>
<link>https://forum.nette.org/en</link>
<description>Nette Framework forum</description>
<language>en</language>
<docs>http://backend.userland.com/rss</docs>
<item>
	<title>How to get the generated sql query with Nette\Database\Explorer (Database &amp; ORM)</title>
	<dc:creator>gregor_nette</dc:creator>
	<link>https://forum.nette.org/en/34914#p218265</link>
	<guid isPermaLink="false">218265@http://forum.nette.org/en</guid>
	<description>&lt;p&gt;Thanks, that helped.&lt;/p&gt;

&lt;p&gt;and to answer my own question how to get the generated query:&lt;/p&gt;

&lt;pre class=&quot;language-php&quot;&gt;&lt;code&gt;$selection-&amp;gt;getSql();&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;retrieves the query&lt;/p&gt;

&lt;p&gt;Thanks a lot&lt;/p&gt;

&lt;p&gt;s.th. like&lt;/p&gt;
</description>
	<pubDate>Mon, 13 Dec 2021 18:46:22 +0100</pubDate>
</item>
<item>
	<title>How to get the generated sql query with Nette\Database\Explorer (Database &amp; ORM)</title>
	<dc:creator>Kamil Valenta</dc:creator>
	<link>https://forum.nette.org/en/34914#p218264</link>
	<guid isPermaLink="false">218264@http://forum.nette.org/en</guid>
	<description>&lt;pre
class=&quot;language-php&quot;&gt;&lt;code&gt;$selection = $database-&amp;gt;table(&apos;artikel&apos;);

foreach ($search_arr as $search_str) {
    $selection-&amp;gt;where(&apos;artnr = ? OR benennung LIKE ? OR herstartnr LIKE ?&apos;, $search_str, $search_str, $search_str);
}&lt;/code&gt;&lt;/pre&gt;
</description>
	<pubDate>Mon, 13 Dec 2021 16:59:28 +0100</pubDate>
</item>
<item>
	<title>How to get the generated sql query with Nette\Database\Explorer (Database &amp; ORM)</title>
	<dc:creator>gregor_nette</dc:creator>
	<link>https://forum.nette.org/en/34914#p218263</link>
	<guid isPermaLink="false">218263@http://forum.nette.org/en</guid>
	<description>&lt;p&gt;Background: I know the domain logic of the application and therefore the raw
queries needed.&lt;br&gt;
&lt;code&gt;$search_arr = [&apos;nllee&apos;, &apos;sseia&apos;]&lt;/code&gt;&lt;br&gt;
and the result should look like this&lt;/p&gt;

&lt;pre
class=&quot;language-neon&quot;&gt;&lt;code&gt;SELECT *
FROM artikel
WHERE
(
    (`artnr` = &apos;nllee&apos;) OR
    (`benennung` LIKE &apos;%nllee%&apos;) OR
    (`herstartnr` LIKE &apos;%nllee%&apos;) OR
    (`longwg` LIKE &apos;%nllee%&apos;) OR
    (`longwg2` LIKE &apos;nllee%&apos;) OR
    (`ean` LIKE &apos;nllee%&apos;)
) AND (
    (`artnr` = &apos;sseia&apos;) OR
    (`benennung` LIKE &apos;%sseia%&apos;) OR
    (`herstartnr` LIKE &apos;%sseia%&apos;) OR
    (`longwg` LIKE &apos;%sseia%&apos;) OR
    (`longwg2` LIKE &apos;sseia%&apos;) OR
    (`ean` LIKE &apos;sseia%&apos;)
)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;How do I get this done with Nette\Database\Explorer ?&lt;br&gt;
Is there the possibility to get the generated queries????&lt;/p&gt;

&lt;p&gt;I do not want to use raw sql, because we might go from mysql to postgres in
the future and I would like to keep the queries hidden in the orm. The migration
is a endless threat by the management.&lt;/p&gt;

&lt;p&gt;I do already know, how to get there with dibi, but I would like to learn, how
to get there with Nette\Database\Explorer&lt;/p&gt;

&lt;p&gt;With dibi it is s.th. like this:&lt;/p&gt;

&lt;pre
class=&quot;language-php&quot;&gt;&lt;code&gt;        $qarr  = [];
        foreach ($search_arr as $search_str) {
            // $search_str = addslashes($search_str);
            $qarr[] = [
                &apos;%or&apos;, [
                    &apos;artnr&apos; =&amp;gt; $search_str,
                    &apos;benennung%~like~&apos; =&amp;gt; $search_str,
                    &apos;herstartnr%~like~&apos; =&amp;gt; $search_str,
                    &apos;longwg%~like~&apos; =&amp;gt; $search_str,
                    &apos;longwg2%like~&apos; =&amp;gt; $search_str,
                    &apos;ean%like~&apos; =&amp;gt; $search_str
                ],
            ];
        }
        $_artdaten = $this-&amp;gt;database-&amp;gt;query(&apos;SELECT artnr FROM artikel WHERE %and &apos;, $qarr)-&amp;gt;fetchAssoc(&apos;artnr&apos;);&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Thanks a lot&lt;/p&gt;
</description>
	<pubDate>Mon, 13 Dec 2021 15:26:33 +0100</pubDate>
</item>
</channel>
</rss>
