<?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>SQL</title>
	<atom:link href="https://www.project34.net/category/software/sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.project34.net</link>
	<description></description>
	<lastBuildDate>Thu, 26 Oct 2023 20:35:48 +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>Storing face_encodings in a database</title>
		<link>https://www.project34.net/2022/01/06/storing-face_encodings-in-a-database/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Thu, 06 Jan 2022 21:59:31 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">http://www.project34.net/?p=252</guid>

					<description><![CDATA[I&#8217;ve been interested in Python for a while now. One thing i like is the possibility to do face recognition. Made a python script based upon a youtube clip from sentdex. The script worked fine and after some tests i was confident that i could extend the original script to what i want it to&#8230;]]></description>
										<content:encoded><![CDATA[
<p>I&#8217;ve been interested in Python for a while now. One thing i like is the possibility to do face recognition. Made a python script based upon a <a href="https://www.youtube.com/watch?v=535acCxjHCI">youtube clip from sentdex</a>. The script worked fine and after some tests i was confident that i could extend the original script to what i want it to do.</p>



<p>The main thing that annoyed me was that every time you run the script, the scripts went through the same intensive process of checking if there is a face, encoding this face to a 128 value variable type that make up this face. The 128 value variable (&#8220;encoded face&#8221;) didn&#8217;t change between run 1, run 2 and run 100. Only if you would change something to the image, maybe the library (for better processing), that could be a reason to recheck the image.</p>



<p>One other thing that annoyed me was the size of the files. When the files have been processed and you have the &#8220;face variable&#8221;, there is no need to store those files anymore. because the information that we need (and have), is much smaller then the file.</p>



<p>A couple of hours later i just couldn&#8217;t find any reliable and usable info about how that data is represented. There is a lot of information what the data means, but (at least) i couldn&#8217;t find the correct way to store the data in a MariaDB database. Well, then start from the beginning: What is the data type that comes out of <em>face_recognition.face_encodings</em>?</p>



<p>First start at the beginning:<br>Let&#8217;s find what the type is:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
encoding = face_recognition.face_encodings(image)&#x5B;0]
print(type(encoding))
</pre></div>


<p>This results in the output:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
&amp;lt;class &#039;numpy.ndarray&#039;&gt;
</pre></div>


<p>After a lot of searching (again), there was not an easy solution:</p>



<ul class="wp-block-list">
<li>sqlite3 has an array data type, which MariaDB doesn&#8217;t have.</li>



<li>You can use pickle to convert the data something to store in the database, but i just couldn&#8217;t get it working with a normal insert command</li>



<li>Converting it to base64 gave me the same issue as pickle.</li>
</ul>



<p>Eventually i found the solution to my misery: it was as, but it took me a while: <em>str(encoding.tolist())</em></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
encoding = face_recognition.face_encodings(image)&#x5B;0]
encodinglist = str(encoding.tolist())
print(type(encodinglist))
</pre></div>


<p>This gave me the following output: <em>&lt;class &#8216;str&#8217;></em></p>



<p>Well, strings is something MariaDB can work with. Created a column as varchar(4096) and voila the data can be stored. <br>Well, the 3 part process is now for 2/3 done (getting info and storing info) now we need to get the data back. The retrieval is very straight forward, select the correct columns from the table and storing it into a array again.</p>



<p>Because the data is now stored as a string and not an array, the face_recognition.compare_faces process can&#8217;t do anything with it. To convert the string back to an array is very easy:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: python; title: ; notranslate">
KNOWN_FACES.append(eval(row&#x5B;1]))
</pre></div>


<p>The eval part converts the string back to an array and puts that array in the KNOWN_FACES array.</p>



<p>So now after processing the images the main info is stored in the database and you can throw away the images if you want, or not, do what you like.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Creating Database Diagrams in SQL Server Management Studio can make the application lock up</title>
		<link>https://www.project34.net/2020/11/26/creating-database-diagrams-in-sql-server-management-studio-can-make-the-application-lock-up/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Thu, 26 Nov 2020 16:55:48 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSMS]]></category>
		<guid isPermaLink="false">http://www.project34.net/?p=212</guid>

					<description><![CDATA[Got a question today from a colleague. He had an application that could create a diagram for a database. This was an old program (last release in 2009) and it worked with Java. If i was able to install the application for an audit. My first thought was: &#8220;Why? SSMS is able to do this!&#8221;.&#8230;]]></description>
										<content:encoded><![CDATA[<p>Got a question today from a colleague. He had an application that could create a diagram for a database. This was an old program (last release in 2009) and it worked with Java. If i was able to install the application for an audit. My first thought was: &#8220;Why? SSMS is able to do this!&#8221;. So started SSMS and logged in to the SQL Instance, opened the database diagrams section and dumped all the tables in the canvas&#8230;&#8230;&#8230;</p>
<p>And SSMS stopped responding. 15 minutes later everything went down the drain. The application didn&#8217;t respond at all. Had to restart the application. Went for a retry and just added 25 tables at a time and again same issue when i added the last set: SSMS stopped responding, after 15 minutes i had to kill the app&#8230;. <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f641.png" alt="🙁" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Tried a smaller set of 10 at a time, but it all seemed to lock up.</p>
<p>The problem seemed to happen when a lot of tables were added and the app had to create the relationships between the new tables and then create the relationship between the nw tables and the old ones.</p>
<p>Eventually found a solution: When in the screen where you can add the tables, select the first one and press add. That table is added and removed from the screen and the next new top one is selected , press add. Now SSMS only has to create the relations between the newly added table and the ones already on the canvas, so it&#8217;s less intensive. When you add al the tables like this and the screen is empty, you can close it and start working imediatly without lag or something.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Print MSSQL TSQL output immediately</title>
		<link>https://www.project34.net/2018/05/02/print-mssql-tsql-output-immediately/</link>
		
		<dc:creator><![CDATA[Maikel]]></dc:creator>
		<pubDate>Wed, 02 May 2018 10:28:50 +0000</pubDate>
				<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">http://www.project34.net/?p=170</guid>

					<description><![CDATA[Sometimes when you make a SQL script, that loops through a lot of records, you want to print a status. When you do this using print (or select), this will only display the content when the buffer is full. To immidiatly print everything to the screen use: This will flush the buffers to screen and&#8230;]]></description>
										<content:encoded><![CDATA[
<p></p>



<p>Sometimes when you make a SQL script, that loops through a lot of records, you want to print a status. When you do this using print (or select), this will only display the content when the buffer is full. To immidiatly print everything to the screen use:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
RAISERROR (&#039;here&#039;, 0, 1) WITH NOWAIT
</pre></div>


<p>This will flush the buffers to screen and so you will see the output immediately.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
