<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sqlite | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/sqlite/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Wed, 09 Aug 2023 09:51:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Sqlite Administration in IntelliJ IDE</title>
		<link>https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 17 May 2021 05:51:21 +0000</pubDate>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[Sqlite]]></category>
		<category><![CDATA[IntelliJ Ultimate]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3050</guid>

					<description><![CDATA[<p>Sometime ago I tried to use Adminer in Docker to administrate a sqlite database, which was not as easy as expected.If you are a happy user of IntelliJ IDE like PHPStorm or IntelliJ Ultimate like me :) then i would nowadays recommend to use the built-in database tool of your IntelliJ IDE for Sqlite administration &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/" class="more-link">Continue reading<span class="screen-reader-text"> "Sqlite Administration in IntelliJ IDE"</span></a></p>
The post <a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/">Sqlite Administration in IntelliJ IDE</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Sometime ago I tried to use <a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/" target="_blank" rel="noreferrer noopener">Adminer in Docker</a> to administrate a sqlite database, which was not as easy as expected.<br />If you are a happy user of IntelliJ IDE like PHPStorm or IntelliJ Ultimate like me :) then i would nowadays recommend to use the built-in database tool of your IntelliJ IDE for Sqlite administration instead.<br />Even in dockerized context.</p>



<span id="more-3050"></span>



<p>A Sqlite database is only one file, which you surely have access to.<br />So just add a Database configuration to your IDE and point it to the Sqlite file.<br />Click on the Database flyout on the left side then on the + (Plus) and add a Sqlite configuration.<br />(IntelliJ has good documentation on <a href="https://www.jetbrains.com/help/idea/connecting-to-a-database.html#connect-to-sqlite-database" target="_blank" rel="noreferrer noopener">Sqlite Database connection</a> as well of course)</p>



<figure class="wp-block-image size-large"><a href="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database.png"><img fetchpriority="high" decoding="async" width="1024" height="563" src="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-1024x563.png" alt="" class="wp-image-3051" srcset="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-1024x563.png 1024w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-300x165.png 300w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database-768x422.png 768w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Sqlite_Database.png 1257w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></a></figure>



<p>Then you are ready to go.<br />The UI of the database structure is quite good.<br />You can browse the tables by doublelick on the table in the database structure view.<br />Also you can edit values in the table view.<br />Note: <em>When the DB was created inside the Docker container you probably dont own the DB from the host and you wont be able write to it.<br />While developing just change permissions on the host, if necessary.</em></p>



<p>You can also open a <strong>Database Console</strong> window where you can test queries.<br />This is particular better than using Adminer because these test queries are persisted and will still be there the next day.<br />You can add multiple database consoles and reopen them from &#8220;Scratches and Consoles&#8221; in your Project menu.</p>



<figure class="wp-block-image size-large"><a href="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console.png"><img decoding="async" width="1024" height="447" src="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-1024x447.png" alt="" class="wp-image-3052" srcset="https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-1024x447.png 1024w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-300x131.png 300w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console-768x335.png 768w, https://nerdpress.org/wp-content/uploads/2021/05/IntelliJ_Database_Console.png 1434w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></a></figure>



<p>So no Adminer needed. Sqlite is just a file, dude.<br />No hassles with docker-compose anymore for DB administration and still using Docker for the app. :)</p>



<p><strong>Update 09.08.2023:</strong><br />JetBrains has now also uploaded a nice Youtube Video Tutorial on how to deal with Sqlite databases in IntelliJ IDEs like f.e. PHPStorm:<br /><a href="https://www.youtube.com/watch?v=Qw_JniULJBI" target="_blank" rel="noopener" title="">Working with SQLite Databases in any JetBrains IDE</a></p>



<p>I learned that you can now Drag and Drop Sqlite database files into the DataBase Pane and the IDE connects it directly, nice!</p>



<p></p>The post <a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/">Sqlite Administration in IntelliJ IDE</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Adminer for Sqlite in Docker</title>
		<link>https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 23 Oct 2019 08:02:47 +0000</pubDate>
				<category><![CDATA[docker]]></category>
		<category><![CDATA[Sqlite]]></category>
		<category><![CDATA[adminer]]></category>
		<category><![CDATA[docker-compose]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2889</guid>

					<description><![CDATA[<p>Recently i wanted to use Sqlite with Adminer in Docker and it turned out to be not so easy. I actually thought i could just declare Adminer in a docker-compose.yml file with a volume mounted, similar as i would do for adminer with mysql. Update: Today i would rather use the IntelliJ Database Tool for &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/" class="more-link">Continue reading<span class="screen-reader-text"> "Adminer for Sqlite in Docker"</span></a></p>
The post <a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/">Adminer for Sqlite in Docker</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Recently i wanted to use Sqlite with <a aria-label="Adminer (opens in a new tab)" href="https://www.adminer.org/" target="_blank" rel="noreferrer noopener">Adminer</a> in Docker and it turned out to be not so easy.<br /> I actually thought i could just declare Adminer in a docker-compose.yml file with a volume mounted, similar as i would do for adminer with mysql.</p>



<p><strong>Update</strong>: Today i would rather use the <a href="https://nerdpress.org/2021/05/17/sqlite-administration-in-intellij-ide/">IntelliJ Database Tool for Sqlite administration</a>.</p>



<p>But since Adminer is a popular hacking target they introduced a <a href="https://www.adminer.org/en/password/" target="_blank" rel="noreferrer noopener" aria-label="feature (opens in a new tab)">feature</a> that does not allow to run adminer without a password, out of the box.<br /> Sqlite database usually runs without password and dang, workaround needed!</p>



<span id="more-2889"></span>



<p>So we need to add a plugin to adminer that allows password-less login and extend the official Adminer Docker image to include the plugin.</p>



<p>We add a script that loads the official password-less-login plugin and copy it to the plugins-enabled folder of the Adminer image</p>



<p>login-password-less.php:</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:100%"><div class="wp-block-syntaxhighlighter-code "><pre class="brush: php; title: ; notranslate">
&lt;?php
require_once(&#039;plugins/login-password-less.php&#039;);

/** Set allowed password
 * @param string result of password_hash
 */
return new AdminerLoginPasswordLess(
    $password_hash = password_hash(&quot;admin&quot;, PASSWORD_DEFAULT)
);
</pre></div></div>
</div>



<p>Dockerfile:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
FROM adminer
USER root
COPY login-password-less.php /var/www/html/plugins-enabled/login-password-less.php
#USER adminer # we run as root because of permissions problems on db file with the volume
</pre></div>


<p>In docker-compose.yml:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
version: &quot;3&quot;
services:
  app:
    build: ./php
      - mailcatcher
    volumes:
      - &quot;../:/app:rw&quot;
      - &quot;./php/cli/php.ini:/etc/php/7.3/cli/php.ini:ro&quot;
      - &quot;./php/fpm/php.ini:/etc/php/7.3/fpm/php.ini:ro&quot;

  nginx:
    build: ./nginx
    depends_on:
      - app
    command: /bin/sh -c &quot;nginx -g &#039;daemon off;&#039;&quot;
    volumes:
      - &quot;..:/app:rw&quot;
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    ports:
      - &#039;8088:80&#039;

  adminer:
    build: ./adminer
    restart: unless-stopped
    volumes:
      - &quot;..:/app:rw&quot;
    ports:
      - 8080:8080
</pre></div>


<p>File tree:</p>



<ul class="wp-block-list"><li>adminer<br />&#8211; Dockerfile<br />&#8211; login-password-less.php</li><li>nginx<br />&#8230;</li><li>php<br />&#8230;</li><li>docker-compose.yml</li></ul>



<p><em>Note that since docker-compose.yml version 3 the volumes_from directive was removed in favor of top level volumes to share volumes across images. However this implementation is imho rather weird, so i jut duplicated the volumes declaration in the App container and Adminer container.<br /> Feels rather wrong but thats all i could come up with. Any advice here is welcome.</em></p>



<p>Now that this is done we can open the Sqlite3 database with the pseudo-password &#8220;admin&#8221; and manage the database.</p>



<p>After all you could also just copy the one-file Adminer with plugin to the php container and run it from within the php container. Just adjust your Nginx config to allow calling the file directly and take care to not deploy Adminer to live.<br /> There is also a project that bundles the plugin with Adminer to one file: <a href="https://github.com/FrancoisCapon/LoginToASqlite3DatabaseWithoutCredentialsWithAdminer" target="_blank" rel="noreferrer noopener">https://github.com/FrancoisCapon/LoginToASqlite3DatabaseWithoutCredentialsWithAdminer/blob/master/build-adminer-4-sqlite3-into-one-file.sh</a></p>The post <a href="https://nerdpress.org/2019/10/23/adminer-for-sqlite-in-docker/">Adminer for Sqlite in Docker</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>sqlite VACUUM</title>
		<link>https://nerdpress.org/2010/06/23/sqlite-vacuum/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 23 Jun 2010 11:20:14 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Sqlite]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1070</guid>

					<description><![CDATA[<p>Mal ein kleines Zauberwort für Zwischendurch: VACUUM; Dieses Kommando räumt eine Sqlite Datenbank auf, killt unnötige Leerzeichen und defragmentiert den Datenbank File. In meinem Fall war die DB nach dem löschen einer relativ großen Table immer noch auf ca 20MB, das hat mich doch stutzig gemacht und zu diesem Kommando geführt. Nachdem ich es ausgeführt &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2010/06/23/sqlite-vacuum/" class="more-link">Continue reading<span class="screen-reader-text"> "sqlite VACUUM"</span></a></p>
The post <a href="https://nerdpress.org/2010/06/23/sqlite-vacuum/">sqlite VACUUM</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Mal ein kleines Zauberwort für Zwischendurch:<br />
<strong><a href="http://www.sqlite.org/lang_vacuum.html">VACUUM</a>;</strong></p>
<p>Dieses Kommando räumt eine Sqlite Datenbank auf, killt unnötige Leerzeichen und defragmentiert den Datenbank File.</p>
<p>In meinem Fall war die DB nach dem löschen einer relativ großen Table immer noch auf ca 20MB, das hat mich doch stutzig gemacht und zu diesem Kommando geführt.<br />
Nachdem ich es ausgeführt hatte, war der File dann tatsächlich auf 2MB geschrumpft!</p>
<p>Sollte man vielleicht nicht im laufendem Betrieb machen und als nächstes schau ich mir dann <a href="http://www.sqlite.org/pragma.html#pragma_auto_vacuum">AUTO_VACUUM</a> an.</p>The post <a href="https://nerdpress.org/2010/06/23/sqlite-vacuum/">sqlite VACUUM</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PHP und Sqlite Transaktionen</title>
		<link>https://nerdpress.org/2010/03/09/php-und-sqlite-transaktionen/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Tue, 09 Mar 2010 10:30:11 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sqlite]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=827</guid>

					<description><![CDATA[<p>Ich bin ja Fan von sqlite, besonders für kleinere Projekte, wo kein hohes paralelles Schreiben zu erwarten ist, also für fast alle kleineren Seiten. Keine Datenbank Administration, einfach loslegen und schnell ist es auch noch. Ein paar Krücken gibts aber schon, zB bei Transaktionen (die MySql im Regelfall gar nicht kann ;)). Ich benutze die &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2010/03/09/php-und-sqlite-transaktionen/" class="more-link">Continue reading<span class="screen-reader-text"> "PHP und Sqlite Transaktionen"</span></a></p>
The post <a href="https://nerdpress.org/2010/03/09/php-und-sqlite-transaktionen/">PHP und Sqlite Transaktionen</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Ich bin ja Fan von sqlite, besonders für kleinere Projekte, wo kein hohes paralelles Schreiben zu erwarten ist, also für fast alle kleineren Seiten.<br />
Keine Datenbank Administration, einfach loslegen und schnell ist es auch noch.</p>
<p>Ein paar Krücken gibts aber schon, zB bei Transaktionen (die MySql im Regelfall gar nicht kann ;)).<br />
Ich benutze die in diesem Fall für multiple Inserts, um da Performance rauszuschlagen.</p>
<p>Über diese bin ich letztens noch gestolpert:</p>
<p>1. Es ist keine gute Idee Transaktionen zu stückeln und sequentiell abzuarbeiten.(warum auch immer man auf diese Idee kommt ;))<br />
besser ist: alle Queries zu buffern und dann in einer Transaktion auszuführen.<br />
Denn Transaktionen locken die DB und nach meiner Erfahrung kann das PHP SQLiteDatabase Object den Datenbank Cursor nicht richtig schließen.<br />
Das führt dann zu sowas: <em>&#8220;cannot start a transaction within a transaction&#8221;</em><br />
<span id="more-827"></span><br />
Folgender Code:</p>
<pre class="brush: php; title: ; notranslate">
for ($i = 0 ; $i &lt; count($data) ; $i++) {
	$q=&#039;BEGIN;&#039;;
	$q.=&quot;INSERT INTO &quot;.$this-&gt;table.&quot; (bla) VALUES (&#039;blub&#039;);&quot;;
	$q.=&#039;COMMIT;&#039;;	
	$this-&gt;_db-&gt;query($q);
}
</pre>
<p>wird also nicht klappen.</p>
<p>Bei PDO gibt es da wohl bessere Unterstützung für Transaktionen.<br />
Das PHP SQLiteDatabase Object ist da etwas kryptisch.</p>
<p>2. ->query() mag keine Transaktionen, ->queryExec() jedoch schon.<br />
Wahrscheinlich deswegen : </p>
<blockquote><p>SQLite führt Mehrfach-Anfragen, die durch Semikolon getrennt wurden, aus, so dass Sie Anfragen ausführen können, die aus einer Datei oder über ein Skript geladen wurden. Wie auch immer, das funktioniert nur, wenn das Ergebins der Anfrage nicht benutzt wird. Sollte es doch genutzt werden, wird nur die erste SQL-Anfrage der Liste ausgeführt. Die Funktion sqlite_exec() wird immer Mehrfach-Anfragen ausführen.</p>
<p>Wenn Mehrfach-Anfrage ausgeführt werden, wird die Funktion im Fehlerfall FALSE zurückgeben, anderenfalls jedoch ein undefiniertes Ergebnis (das kann, sollte die Anfrage gelingen, TRUE oder ein Ergebnis-Handle sein).
</p></blockquote>
<p>Also ->queryExec() kanns und ->query kanns irgendwie nicht.<br />
Dort würde nur der erste query ausgeführt und der Rest stillschweigend ignoriert, d.h. die Anweisung gibt true zurück.<br />
Es würde also viele Tupel -unbemerkt- verlorengehen.</p>
<p>Folgender Code hingegen klappt dann:</p>
<pre class="brush: php; title: ; notranslate">
$q=&#039;&#039;;
$this-&gt;_db-&gt;queryExec(&#039;BEGIN;&#039;);
for ($i = 0 ; $i &lt; count($data) ; $i++) {
	$q.=&quot;INSERT INTO &quot;.$this-&gt;table.&quot; (bla) VALUES (&#039;blub&#039;);&quot;;
}
$this-&gt;_db-&gt;queryExec($q);
$this-&gt;_db-&gt;queryExec(&#039;COMMIT;&#039;);
</pre>
<p>Diese Seite war dabei übrigens recht hilfreich:<br />
<a href="http://www.ordix.de/ORDIXNews/1_2004/unix_linux_2.html">http://www.ordix.de/ORDIXNews/1_2004/unix_linux_2.html</a></p>
<p>Ja krass, gar kein Framework benutzt hier! ;)</p>The post <a href="https://nerdpress.org/2010/03/09/php-und-sqlite-transaktionen/">PHP und Sqlite Transaktionen</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>symfony und multiple inserts</title>
		<link>https://nerdpress.org/2009/11/11/symfony-und-multiple-inserts/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Wed, 11 Nov 2009 17:24:46 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[propel]]></category>
		<category><![CDATA[Sqlite]]></category>
		<category><![CDATA[Symfony]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=559</guid>

					<description><![CDATA[<p>Manchmal sollte man multiple Inserts machen, ist doch performanter als in jedem Schleifendurchlauf die Database Engine zu bemühen. Falls man sich mal fragt wie man multiple Inserts mit symfony hinkriegt, fängt man an zu googlen und stößt schnell auf dieses Snippet. Und bevor man da rumeiert und das auf zB Sqlite umschreibt, einfach mal Propel &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2009/11/11/symfony-und-multiple-inserts/" class="more-link">Continue reading<span class="screen-reader-text"> "symfony und multiple inserts"</span></a></p>
The post <a href="https://nerdpress.org/2009/11/11/symfony-und-multiple-inserts/">symfony und multiple inserts</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Manchmal sollte man multiple Inserts machen, ist doch performanter als in jedem Schleifendurchlauf die Database Engine zu bemühen.</p>
<p>Falls man sich mal fragt wie man multiple Inserts mit symfony hinkriegt, fängt man an zu googlen und stößt schnell auf dieses <a href="http://snippets.symfony-project.org/snippet/307" target="_blank">Snippet</a>.</p>
<p>Und bevor man da rumeiert und das auf zB Sqlite umschreibt, einfach mal<a href="http://propel.phpdb.org/trac/wiki/Users/Documentation/1.3/HowTos/Transactions" target="_blank"> Propel Transaktionen</a> anschauen:</p>
<p><span id="more-559"></span></p>
<pre class="brush: php; title: ; notranslate">

$con = Propel::getConnection();
$con-&gt;beginTransaction();

foreach ($temp as $item) {

$blog = new Blogs();
$blog-&gt;setTitle($title);

$blog-&gt;save($con);

}

$con-&gt;commit();

</pre>
<p>Klappt super, zumindest mit Sqlite bei mir hier.</p>The post <a href="https://nerdpress.org/2009/11/11/symfony-und-multiple-inserts/">symfony und multiple inserts</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
