<?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>MS SQL Server &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/ms-sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Mon, 15 Apr 2024 15:19:41 +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>SQL 50th Anniversary</title>
		<link>https://blog.xojo.com/2024/04/15/sql-50th-anniversary/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Mon, 15 Apr 2024 15:19:40 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[IBM]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQLite]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=12874</guid>

					<description><![CDATA[SQL is 50 years old! It was first introduced in a 1974 paper titled “SEQUEL: A STRUCTURED ENGLISH QUERY LANGUAGE” by Donald Chamberlin and Raymond&#8230;]]></description>
										<content:encoded><![CDATA[
<p><a href="https://en.wikipedia.org/wiki/SQL">SQL</a> is 50 years old! It was first introduced in a 1974 paper titled “<a href="https://s3.us.cloud-object-storage.appdomain.cloud/res-files/2705-sequel-1974.pdf">SEQUEL: A STRUCTURED ENGLISH QUERY LANGUAGE</a>” by Donald Chamberlin and Raymond Boyce who were part of the IBM Research Laboratory in San Jose California.</p>



<p>This paper probably explains the biggest issue regarding SQL that persists to this day: its pronunciation.</p>



<p>I always flip between saying “sequel” and “ess cue ell” depending on context. The authors used SEQUEL as an <a href="https://www.merriam-webster.com/dictionary/acronym">acronym</a> of <strong>S</strong>tructured <strong>E</strong>nglish <strong>QUE</strong>ry <strong>L</strong>anguage. Over time this was referred to as Structured Query Language and the <a href="https://www.merriam-webster.com/dictionary/initialism">initialism</a> of SQL took hold. Still, the pronunciation of sequel seems to have also stuck. Anyway, pronounce it how you want — I won’t judge.</p>



<p>I&#8217;ve sometimes seen people claim that SQL stands for Standard Query Language. As the above clearly shows, that is not true. And if you&#8217;ve used SQL at all with more than one database, you also have empirical evidence that there is not much standard about it beyond the main keywords.</p>



<p>The <a href="https://s3.us.cloud-object-storage.appdomain.cloud/res-files/2705-sequel-1974.pdf">paper itself</a> is only about 15 pages, so not long at all. I found this surprising as I expected it to be some lengthy and detailed specification written for academics.</p>



<p>But it’s not.</p>



<p>It starts by talking about the relational model of data, a somewhat new concept at the time (first <a href="https://en.wikipedia.org/wiki/Relational_model">described in 1969</a>), and the predicate calculus, introducing a sublanguage called SQUARE, which strikes me a somewhat functional way of querying relational data. Math nerds do love their functional languages.</p>



<p>The authors then go on to introduce SEQUEL as a substitute for SQUARE and it’s here where we see the first syntax that you might recognize:</p>



<pre class="wp-block-code"><code>SELECT NAME
FROM   EMP
WHERE  DEPT = ’TOY’</code></pre>



<p>Boolean expressions in the WHERE clause are also covered along with functions in the SELECT clause. These are all things still being used to this day.</p>



<p>The main justification the authors use for SEQUEL is that the concepts of predicate calculus and SQUARE require &#8220;too much sophistication for the ordinary user&#8221;. I won’t argue with that!</p>



<p>They drive that point home by showing how to get data results using some example queries, first by using SQUARE and then comparing to the SEQUEL equivalents. Their first query is this:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>Find the names of managers who manage more than ten employees.</p>
</blockquote>



<p>Note that for this example, there is a previously defined database with one of the tables as follows:</p>



<p>EMP (NAME, DEPT, MGR, SAL, COMM)</p>



<p>The SQUARE example looks like this:</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="122" src="https://blog.xojo.com/wp-content/uploads/2024/04/Pasted-Graphic-1024x122.png" alt="" class="wp-image-12878" srcset="https://blog.xojo.com/wp-content/uploads/2024/04/Pasted-Graphic-1024x122.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/04/Pasted-Graphic-300x36.png 300w, https://blog.xojo.com/wp-content/uploads/2024/04/Pasted-Graphic-768x92.png 768w, https://blog.xojo.com/wp-content/uploads/2024/04/Pasted-Graphic-1536x184.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/04/Pasted-Graphic.png 1672w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>I’m not going to even try to explain this. Read the paper if you’re curious.</p>



<p>Here&#8217;s the SEQUEL version:</p>



<pre class="wp-block-code"><code>SELECT   MGR
FROM     EMP
GROUP BY MGR
WHERE    COUNT (NAME) &gt; 10</code></pre>



<p>Well, now. That certainly makes more sense to me. I&#8217;ll bet that everyone reading this knows exactly how to parse out the SEQUEL command. It would actually work as-is in a database such as SQLite today!</p>



<p>There are other examples in the paper as well. Like I said, it’s somewhat short so you might find it to be an interesting read.</p>



<p>Happy 50th Birthday, SEQUEL (SQL)!!</p>



<p><em>Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at <a href="https://goto10.substack.com" target="_blank" rel="noreferrer noopener">Goto 10</a> and </em>on Mastodon @lefebvre@hachyderm.io.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Good Change, API 2.0 Database Benefits</title>
		<link>https://blog.xojo.com/2020/09/17/good-change-api-2-0-database-benefits/</link>
		
		<dc:creator><![CDATA[Wayne Golding ]]></dc:creator>
		<pubDate>Thu, 17 Sep 2020 10:00:20 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Guest Post]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Xojo API 2.0]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=7292</guid>

					<description><![CDATA[I decided when updating the project, I would also update to API 2.0 database commands using Xojo 2019 R3.2 and I would like to share some of those code changes with you.]]></description>
										<content:encoded><![CDATA[
<p>Recently I needed to update an old Web project that used a Microsoft SQL Server Database as its data source. This application is running as a service on a Windows machine and is for internal use only. I decided when updating the project, I would also update to API 2.0 database commands using Xojo 2019 R3.2 and I would like to share some of those code changes with you.</p>



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



<p>In API 2.0, SQLSelect became <a href="http://documentation.xojo.com/api/databases/database.html#database-selectsql">SelectSQL</a> and SQLExecute became <a href="http://documentation.xojo.com/api/databases/database.html#database-executesql">ExecuteSQL</a>. Additionally API 2.0 automatically uses prepared statements. Now, while they perform much the same actions, there are enhancements which make code much simpler to create and read. This is because they implement Prepared Statements under the hood.</p>



<p>For Example, this API 1.0 code:</p>



<pre class="wp-block-preformatted">Dim ps As PreparedSQLStatement<br>Dim rs As RecordSet<br><br>ps = Session.db.Prepare("SELECT * FROM users WHERE emailaddress = ?;")<br>ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)<br>ps.Bind(0, "wayne@axisdirect.co.nz")<br><br>rs = ps.SQLSelect()<br><br>Session.UserID = rs.Field("id").IntegerValue</pre>



<p>Becomes:</p>



<pre class="wp-block-preformatted">Var rs As RowSet

rs = Session.db.SelectSQL("SELECT * FROM users WHERE emailaddress = ?;" _
 ,"wayne@axisdirect.co.nz")

Session.UserID = rs.Column("id").IntegerValue</pre>



<p>Seven lines of code become just four and in my opinion the second is much easier to follow.&nbsp;A prepared statement is not required (as it is implemented under the hood), and the bind type is automatic.</p>



<p>That SELECT statement does not have many bindings, but here is an INSERT statement that does – API 1.0 code</p>



<pre class="wp-block-preformatted">Dim ps As PreparedSQLStatement
ps = Session.db.Prepare("INSERT INTO reports (title, scheduletype, dayofmonth, dayofweek, sunday, monday, tuesday, wednesday, thursday, friday, saturday, nextrun, reportfile, deliverymethod, suspended) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")<br><br>ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)<br>ps.BindType(1, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_INT)<br>ps.BindType(2, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_INT)<br>ps.BindType(3, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_INT)<br>ps.BindType(4, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(5, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(6, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(7, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(8, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(9, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(10, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br>ps.BindType(11, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING) ' This is a datetime value, but we're going to bind a SQLDateTime String<br>ps.BindType(12, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)<br>ps.BindType(13, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_INT)<br>ps.BindType(14, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_TINYINT)<br><br>ps.Bind(0, TitleField.Text)
ps.Bind(1, ScheduleTypeMenu. ListIndex)
ps.Bind(2, If(ScheduleTypeMenu. ListIndex = 2, Val(DayOfMonthField.Text), 0)
ps.Bind(3, If(ScheduleTypeMenu. ListIndex = 1, Val(DayOfWeekField.Text), 0)
ps.Bind(4, If(WeekDay(0).Value, 1, 0)
ps.Bind(5, If(WeekDay(1).Value, 1, 0)<br><br>ps.Bind(6, If(WeekDay(2).Value, 1, 0)
ps.Bind(7, If(WeekDay(3).Value, 1, 0)
ps.Bind(8, If(WeekDay(4).Value, 1, 0)
ps.Bind(9, If(WeekDay(5).Value, 1, 0)
ps.Bind(10, If(WeekDay(6).Value, 1, 0)
ps.Bind(11, NextRunField.DateValue.SQLDateTime)
ps.Bind(12, ReportFileField.Text)
ps.Bind(13, DeliveryMethodMenu.SelectedIndex)
ps.Bind(14, 1)

ps.SQLExecute()

If Session.db.Error Then
  Break ' The insert statement failed for some reason - this should only happen during debugging.
End If</pre>



<p>Becomes:</p>



<pre class="wp-block-preformatted">Var sql As String

sql = "INSERT INTO reports (title, scheduletype, dayofmonth, dayofweek, sunday, monday, tuesday, wednesday, thursday, friday, saturday, nextrun, reportfile, deliverymethod, suspended) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

Try
&nbsp; Session.db.ExecuteSQL(sql, _
&nbsp;  TitleField.Value, _
&nbsp;  ScheduleTypeMenu.ListIndex, _
&nbsp;  If(ScheduleTypeMenu.ListIndex = 2, Val(DayOfMonthField.Text), 0), _
&nbsp;  If(ScheduleTypeMenu.ListIndex = 1, Val(DayOfWeekField.Text), 0), _
&nbsp;  If(WeekDay(0).Value, 1, 0), _
&nbsp;  If(WeekDay(1).Value, 1, 0), _
&nbsp;  If(WeekDay(2).Value, 1, 0), _
&nbsp;  If(WeekDay(3).Value, 1, 0), _
&nbsp;  If(WeekDay(4).Value, 1, 0), _
&nbsp;  If(WeekDay(5).Value, 1, 0), _
&nbsp;  If(WeekDay(6).Value, 1, 0), _
&nbsp;  NextRunField.DateValue.SQLDateTime, _
&nbsp;  ReportFileField.Value, _
&nbsp;  DeliveryMethodMenu.ListIndex, _
&nbsp;  1)

Catch Err As DatabaseException
  Break ' The insert statement failed for some reason - this should only happen during debugging.
End Try</pre>



<p>Again, a huge reduction in coding and a more readable result.&nbsp;You will also notice the use of a try/catch block. API 2.0 methods raise exceptions and during debugging these are invaluable as they break on the exception rather than later when your logic bug bites <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f60a.png" alt="😊" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>The API 2.0 SelectSQL method also returns a <a href="https://documentation.xojo.com/api/databases/rowset.html">RowSet</a> rather than a RecordSet.&nbsp;The RowSet is iterable unlike the RecordSet and that makes it much more user friendly. I can’t tell you how many times I’ve run a project only to find it just sits there using all the CPU cycles it can because I forgot to call the MoveNext method.</p>



<p>I understand that many people using Xojo on Windows probably aren&#8217;t targeting MS SQL Server, but I believe this is changing. And as more developers target Windows and MS SQL Server, the fixes and improvements that come with API 2.0 will make this easier for them. I know they are making my life a lot easier.</p>



<p>Oh, and by the way, before this update this application would start with a memory usage of about 100MB and grow to &gt;500MB over the week and then I would restart the service.&nbsp;Updating this project to API 2.0 resulted in ongoing memory usage of between 7.5 and 8.5MB for the running application.&nbsp;I suspect this is a combination of my improved coding and improvements under the hood by Xojo.</p>



<p><em>Wayne Golding has been a Xojo developer since 2005 and is a Xojo MVP. He operates the IT Company <a href="http://www.axisdirect.nz">Axis Direct Ltd </a>which primarily develops applications using Xojo that integrate with Xero www.xero.com. Wayne’s hobby is robotics where he uses Xojo to build applications for his Raspberry Pi, often implementing IoT for remote control.</em></p>



<p></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
