<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Fetching and writing source code from and to DB records]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have some questions concerning a special plugin.<br />
Maybe someone else has already developed a plugin similar to my project.</p>
<p dir="auto">My source code is stored within a DB and NOT in a simple file. I want to read and<br />
write source code directly from to the DB.</p>
<p dir="auto">DB-querying is not a problem.</p>
<p dir="auto">But, how to insert query results into the editor (e.g. from the clipboard).<br />
Where to find an … how to get started.</p>
<p dir="auto">Has anyone got an idea.</p>
<p dir="auto">Thanks a lot, beginner.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/10854/fetching-and-writing-source-code-from-and-to-db-records</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 18:01:43 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/10854.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 22 Nov 2015 19:37:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fetching and writing source code from and to DB records on Thu, 26 Nov 2015 00:38:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/michael-gollnick" aria-label="Profile: Michael-Gollnick">@<bdi>Michael-Gollnick</bdi></a></p>
<p dir="auto">2nd try - both example scripts</p>
<blockquote>
<p dir="auto">I have some questions concerning a special plugin.<br />
Maybe someone else has already developed a plugin similar to my project.</p>
<p dir="auto">My source code is stored within a DB and NOT in a simple file. I want to read and<br />
write source code directly from to the DB.</p>
<p dir="auto">DB-querying is not a problem.</p>
<p dir="auto">But, how to insert query results into the editor (e.g. from the clipboard).<br />
Where to find an … how to get started.</p>
<p dir="auto">Has anyone got an idea.</p>
<p dir="auto">Thanks a lot, beginner.</p>
</blockquote>
<p dir="auto">Hello Michael-Gollnick,</p>
<p dir="auto">well I don’t have a specialized plugin for this but maybe<br />
you can use the python script plugin to achieve this.<br />
Which database do you use?<br />
If it is SQLite than it is easy because it is already<br />
part of python 2.7, if it isn’t than maybe someone<br />
has already written a py module to access it.</p>
<p dir="auto">So two scripts like the followings could maybe solve your problem</p>
<p dir="auto">[code]<br />
import sqlite3</p>
<p dir="auto">conn = sqlite3.connect(r’D:\my_database.sqlite’)<br />
c = conn.cursor()<br />
c.execute(‘SELECT Code_ID, Code FROM Code’)<br />
records = c.fetchall()<br />
dict_record = dict(records)<br />
msg = “”<br />
for record in records:<br />
id, code = record<br />
msg += “{0} {1}\n”.format(id, code)</p>
<p dir="auto">console.write(’ Codes \n’ + msg)</p>
<p dir="auto">id = notepad.prompt(“Select the ID from the console output window”, ‘SELECT Code_ID, Code FROM Code’, ‘nothing chosen’)</p>
<p dir="auto">if id != ‘nothing chosen’:<br />
notepad.new(id)<br />
editor.addText(dict_record[int(id)])</p>
<p dir="auto">c.close()<br />
[/code]</p>
<p dir="auto">and second script to save the changes</p>
<p dir="auto">[code]<br />
import sqlite3, os</p>
<p dir="auto">conn = sqlite3.connect(r’D:\my_database.sqlite’)<br />
c = conn.cursor()<br />
c.execute(r’UPDATE Code SET Code = ? WHERE Code_ID = ? ',(editor.getText(),os.path.basename(notepad.getCurrentFilename())))<br />
if c.rowcount &gt; 0:<br />
conn.commit()<br />
os.remove(notepad.getCurrentFilename())<br />
console.write(“CODE UPDATED”)<br />
else:<br />
console.writeError(“UPDATE failed”)<br />
c.close()<br />
[/code]</p>
<p dir="auto">For easy access you can assign icons (16x16 bmp) to the scripts and add it to the notepad toolbar.</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/12251</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/12251</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 26 Nov 2015 00:38:50 GMT</pubDate></item><item><title><![CDATA[Reply to Fetching and writing source code from and to DB records on Thu, 26 Nov 2015 00:11:05 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">I have some questions concerning a special plugin.<br />
Maybe someone else has already developed a plugin similar to my project.</p>
<p dir="auto">My source code is stored within a DB and NOT in a simple file. I want to read and<br />
write source code directly from to the DB.</p>
<p dir="auto">DB-querying is not a problem.</p>
<p dir="auto">But, how to insert query results into the editor (e.g. from the clipboard).<br />
Where to find an … how to get started.</p>
<p dir="auto">Has anyone got an idea.</p>
<p dir="auto">Thanks a lot, beginner.</p>
</blockquote>
<p dir="auto">Hello Michael-Gollnick,</p>
<p dir="auto">well I don’t have a specialized plugin for this but maybe<br />
you can use the python script plugin to achieve this.<br />
Which database do you use?<br />
If it is SQLite than it is easy because it is already<br />
part of python 2.7, if it isn’t than maybe someone<br />
has already written a py module to access it.</p>
<p dir="auto">So two scripts like those could myabe solve your problem</p>
<p dir="auto">&lt;code&gt;<br />
import sqlite3</p>
<p dir="auto">conn = sqlite3.connect(r’D:\my_database.sqlite’)<br />
c = conn.cursor()<br />
c.execute(‘SELECT Code_ID, Code FROM Code’)<br />
records = c.fetchall()<br />
dict_record = dict(records)<br />
msg = “”<br />
for record in records:<br />
id, code = record<br />
msg += “{0} {1}\n”.format(id, code)</p>
<p dir="auto">console.write(’ Codes \n’ + msg)</p>
<p dir="auto">id = notepad.prompt(“Select the ID from the console output window”, ‘SELECT Code_ID, Code FROM Code’, ‘nothing chosen’)</p>
<p dir="auto">if id != ‘nothing chosen’:<br />
notepad.new(id)<br />
editor.addText(dict_record[int(id)])</p>
<p dir="auto">c.close()<br />
&lt;code&gt;</p>
<p dir="auto">Cheers<br />
Claudia</p>
]]></description><link>https://community.notepad-plus-plus.org/post/12250</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/12250</guid><dc:creator><![CDATA[Claudia Frank]]></dc:creator><pubDate>Thu, 26 Nov 2015 00:11:05 GMT</pubDate></item></channel></rss>