{"id":14,"date":"2008-01-15T11:40:29","date_gmt":"2008-01-15T19:40:29","guid":{"rendered":"http:\/\/www.installaware.com\/blog\/?p=14"},"modified":"2008-01-15T12:12:33","modified_gmt":"2008-01-15T20:12:33","slug":"online-serial-key-validation-with-installaware-the-database-part-final","status":"publish","type":"post","link":"https:\/\/www.installaware.com\/blog\/?p=14","title":{"rendered":"Online Serial Key Validation with InstallAware, the Database Part (final)"},"content":{"rendered":"<p>In this last installment of the serial validation series, we&#8217;re taking a look at the database structures used by the web side scripts. You&#8217;ll need to know some SQL-92 or T-SQL basics, if you don&#8217;t already please visit <a href=\"http:\/\/www.mysql.com\/\">http:\/\/www.mysql.com\/<\/a> and <a href=\"http:\/\/www.microsoft.com\/sql\/\">www.microsoft.com\/sql\/<\/a> to get acquainted.<\/p>\n<p>First, some database design. We&#8217;ll keep serial data on one table and user data on another table.<\/p>\n<p>The <strong>serials table<\/strong> columns:<br \/>\n<strong>id (bigint) , productname (nvarchar), serial (nvarchar), activated (tinyint)<\/strong><\/p>\n<p>The <strong>users table <\/strong>columns:<br \/>\n<strong>id (bigint), firstname (nvarchar), lastname (nvarchar), username (nvarchar), password (nvarchar)<\/strong><\/p>\n<p>During validation we can use the <span style=\"font-weight: bold\">SQL SELECT statement <\/span>to make sure the serial number has not been used before and has not been activated yet:<br \/>\n<span style=\"font-weight: bold\">SELECT id FROM serials WHERE <\/span><a style=\"font-weight: bold\" href=\"mailto:serial=@serial\">serial=@serial<\/a><span style=\"font-weight: bold\"> AND activated != 1<\/span><\/p>\n<p>This is a T-SQL compliant query, where <span style=\"font-weight: bold\">@serial <\/span>is the parameter containing the serial number being queried. If this query doesn&#8217;t return a value, that&#8217;ll mean that the serial number specified is either invalid or has already been activated.<\/p>\n<p>Otherwise, we can go ahead and activate this serial number. The T-SQL statement for this activation is:<br \/>\n<span style=\"font-weight: bold\">UPDATE serials SET activated=1 WHERE <\/span><a style=\"font-weight: bold\" href=\"mailto:serial=@serial\">serial=@serial<\/a><\/p>\n<p>Now, all that remains to do is to add an entry in the users table:<br \/>\n<strong>INSERT INTO users(firstname,lastname,username,password) VALUES(@firstname,@lastname,@username,@password);<\/strong><\/p>\n<p>My suggestion for you is to implement all of the above statements as separate <strong>stored procedures <\/strong>and not stand-alone &#8220;injected&#8221; queries lying around inside multiple web script files. It&#8217;s better that way since code maintenance overhead is reduced &#8211; just like replacing all separate <strong>Run Program <\/strong>statements with a common <strong>Label <\/strong>statement like we did earlier for the MSIcode update script.<\/p>\n<p>So as you can see, in a few simple lines, we&#8217;ve implemented the business logic\/workflow of our application, in an integrated fashion with Install<strong>Aware<\/strong>. You&#8217;ve probably noticed that there isn&#8217;t any directly Install<strong>Aware<\/strong> related content in this post, but we&#8217;ve had a lot of requests for samples of web server back-end behavior for things like serial activation, so we hope this helps!<\/p>\n<p>Thank you and we&#8217;ll be back soon,<\/p>\n<p>Panagiotis Kefalidis<br \/>\nSoftware Design Team Lead<br \/>\nInstall<span style=\"font-weight: bold\">Aware<\/span> Software Corporation<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this last installment of the serial validation series, we&#8217;re taking a look at the database structures used by the web side scripts. You&#8217;ll need to know some SQL-92 or T-SQL basics, if you don&#8217;t already please visit http:\/\/www.mysql.com\/ and www.microsoft.com\/sql\/ to get acquainted. First, some database design. We&#8217;ll keep serial data on one table &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.installaware.com\/blog\/?p=14\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Online Serial Key Validation with InstallAware, the Database Part (final)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":0,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.installaware.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}