Author: way0utwest

  • Trying GO with SQL Server

    Not the batch separator, but the GO language.

    I’m always interested in learning new things, and GO has been one of those items that I’ve wanted to look at and see how it works. This is a big language at Google and

    I saw a new blog from Mat Hayward-Hill on Golang (Go) and decided to make a quick test. After all, he had the code. I first installed the Go language, which was simple. I then added a variable according to the blog and the extension to VSCode.

    From there, I copied his code and tried it. Hello World worked fine, but I had a couple issues with the SQL connection.

    First, I don’t have default instances, just named ones. The connection string was:

    condb, errdb := sql.Open("mssql", "server=localhost\SQL2016;user id=sa;password=SA_PASSWORD=yourStrong(!)Password;")

    However, I had to escape the backslash. VSCode showed this to be an issue, so I tried a second one to clean things up. This worked fine.

    condb, errdb := sql.Open("mssql", "server=localhost\\SQL2016;user id=sa;password=SA_PASSWORD=yourStrong(!)Password;")

    The next thing was the entire password string, including the second equals sign, needs to be your pwd. I connected to SQL 2016 on Win, and once I removed the stuff after the second =, I connected and got the version back.

    The Go Language

    Go was created by Google and is something of an evolution of C, but with some of the ease of Python. It’s apparently good for things like network and web servers where concurrency matters. More of a systems programming language, not one for GUI or desktop apps.

    Who uses it? Quite a few well known sites. Google does, Kubernetes (the container company), YouTube (technically Google as well), 99Designs, Adobe, Bitbucket, Pinterest, and more. It seems to have more popularity than I’d expect, but I don’t examine the language breakdowns often and I’m sure it’s just one of many languages used at these companies.

    Still, it was neat to try a new language. Now to try a few tutorials over at golang.org.

  • Quick Graph Database

    There’s a sample to work through here: https://docs.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-sample

    I decided to try this in CTP2 and just see how it works. I didn’t do much, but I added a node and an edge with this code:

    CREATE TABLE Person (ID INTEGER PRIMARY KEY, name VARCHAR(100)) AS NODE;
    CREATE TABLE friends (StartDate date) AS EDGE;

    Next I added a few values, based on the samples.

    INSERT Person
     VALUES (1, 'Steve')
          , (2, 'Andy')
          , (3, 'Brian')
          , (4, 'Leon')
          , (5, 'Jon')
    GO
    INSERT Friends VALUES ((SELECT $node_id FROM Person WHERE id = 1), (SELECT $node_id FROM Person WHERE id = 2),'3/10/2001')
    INSERT Friends VALUES ((SELECT $node_id FROM Person WHERE id = 3), (SELECT $node_id FROM Person WHERE id = 4),'5/1/2000')
    INSERT Friends VALUES ((SELECT $node_id FROM Person WHERE id = 1), (SELECT $node_id FROM Person WHERE id = 3), '3/1/2001')

    Then I ran query.

    SELECT *
    FROM Person p1, Friends, Person p2
    WHERE MATCH (p1-(friends)->p2)
    AND p1.name = 'Brian';

    What does this give me? First, these columns with this data. It’s a wide result set, so I have the column and data listed after it, even though this is really a 1 row table.

    $edge_id_5F276FF32E2B492A96858AC68B530F09                                               
    
    {"type":"edge","schema":"dbo","table":"friends","id":1}
    
    $from_id_DE63E53A3F4749C2980FC989BC2E5405                                            
    
    {"type":"node","schema":"dbo","table":"Person","id":2}                                              
    
    $to_id_19F4532DDEC74B22876DCCFBB24797BE                                                 
    
    {"type":"node","schema":"dbo","table":"Person","id":3}                                              
    
    StartDate  
    
    2000-05-01
    
    $node_id_D004B78ADB644588BE4B9E337823356A                                            
    
    {"type":"node","schema":"dbo","table":"Person","id":2}
    
    ID
    
    3
    
    name                                                                                                 
    
    Brian
    
    $node_id_D004B78ADB644588BE4B9E337823356A                                        
    
    {"type":"node","schema":"dbo","table":"Person","id":3}   
    
    ID
    
    4
    
    name
    Leon

    What does all that mean? No idea. Clearly there is JSON that’s returned here and can be deserialized to gather meanings. Is this useful? I think graphs solve a certain set of problems very well, and more efficiently than relational systems. Certainly I could implement a graph structure relationally, but at scale I’m not sure the queries would be as easy to write or run as quickly.

    I don’t know if I’d use a graph structure in any of the problems we try to solve in the SQLServerCentral app, but who knows. Maybe we would if we could.

    This is just another option for SQL Server, another tool in your toolbelt. Should you use it? I don’t know, but I’d recommend that if you think you have a complex relationship structure, maybe lots of FKs internal to a table or you are modeling relationships, learn more about GraphSQL and how graph databases work and build a POC. I’m not sure when the SQL Server implementation will be production ready, but it doesn’t hurt to test and learn a bit if you have the chance.

  • Less QA?

    This editorial was originally published on Jul 31, 2013. It is being re-run as Steve is out of the office.

    Throughout most of my career, people have complained that software is never tested enough, not tested well, and certainly not enough time is allocated in project plans. I’d also argue that all too often we don’t have people building software with experience in how to perform extensive testing. Most developers only have a rudimentary knowledge of software testing and that part of their skill set doesn’t receive constant training. However I’ve found plenty of QA people that were in the same situation. Some educate themselves and learn how to test better, but many go through the motions. They don’t take pride in their role as a software tester.

    There have been lots of advances in automated testing and TDD methodologies over the years, which means that developers have been taking more of the responsibility, and effort, for testing code. It’s hard to know if this has resulted in higher quality code, lower quality, or a mix. Overall I think that the latter is likely. Code quality is all over the board, probably based more on the skill and talent of the individual developer than on any process.

    That’s good for the companies that have hired strong developers, but not so great for our industry as a whole. We still produce lots of software that takes too long to develope, costs too much, and often has too many bugs. Overall we are sloppy and inconsistent in how we build software. Some of that is the nature of our business, one with such a low bar of entry that anyone can give software development a try.

    I don’t know how we improve the quality of software, though I do think continuing to educate and train people on what works well is a good start. However I also think that we still need QA groups. We need people that will use software in ways that automated tests won’t. People that will press buttons, enter values, and push software in ways that developers would never consider using it. Most of all, we need QA and testing to be treated as a valuable part of our industry. We need QA people that view testing as a valid career path, not a stepping stone for junior developers that look to move on as soon as possible.

    Steve Jones

  • DevOps Basics–Creating a local repo and committing files

    Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers. This is also a part of a basic series on git and how to use it.

    A local repo is a repository, and is the version control system you will use locally. In a previous post I looked at cloning a repo. That’s a way to get code from others, but what if I want to start a new project?

    That’s easy. This post will start a new project, save a few files, and show how to commit these to my git VCS.

    Create a Repo

    If you use tooling, there is usually a CREATE function somewhere, but at the command line, you can just do this:

    git init

    Assuming you’ve installed git, this will create a repo in your folder, and let you know it exists.

    2017-04-26 14_16_13-cmd

    At this point I have an empty repo, and if I look in my folder, there’s a .git folder.

    2017-04-26 14_16_20-GitTests

    This folder will essentially control how this repo works on my system. Let me start by adding a couple text files. I’ll use a markdown file as a Readme, since I’ll eventually push this to Github and I like to have something there that makes sense. I’ve also got the contents of the text file here, which makes it easy to track what changes are being made and versioned.

    2017-04-26 14_17_30-SomeTestFile.txt - Notepad

    Let’s now check my status:

    2017-04-26 14_18_01-cmd

    I’ve saved files here, but they aren’t being versioned. There’s not automatic tracking here just because I’ve saved files. This is something I need to do. Some tooling will do this for you, but it’s good to understand how this actually works. I need to tell git to track these files, so let’s do that.

    First, I’ll add the files. I could specify specific files, but for now, I’m adding them all (both of them). Then I’ll check my status.

    2017-04-26 14_19_14-cmd

    Notice the files are in green now. These are being tracked, and they’re “staged” for commit, but they’re not committed. Git sees these are new files, but the changes haven’t been saved.

    I’ll now save the files with a git commit. I use the –m option to specify a comment on the command line. In another post I’ll show you what happens when you don’t do this.

    2017-04-26 14_20_41-cmd

    If I now look at status, I see nothing.

    2017-04-26 14_21_32-cmd

    Why?

    Git is concerned with changes and versioning. If everything is tracked, then git sees a clean directory and no files to commit. The files exist, but the version is not tracked in git.

    Changes

    I’ll make a change to a file and then we can see the effect. Here I’ll add text and save the file.

    2017-04-26 14_23_39-GitTests

    Now let’s check status. Below you’ll see I have a “modified” file, which I’ll then “stage” and add as something I want to commit.

    2017-04-26 14_24_05-cmd

    Let’s now commit this.

    2017-04-26 14_25_21-cmd

    I can see that things are clean again, and my folder looks like I’d expect. The two files, one of which has two lines in it.

    That’s really it for now. If you want to play along, download git, create a repo, and make some changes and commits. In another post, I’ll look at how I see the changes and get back to a previous version.

    SQLNewBlogger

    This was a quick post, about 10 minutes, as I practiced and experimented with things I know about git, trying to ensure I get them straight in my mind. That’s a good way to learn or improve skills in an area.

    The hardest part in this post is trying to focus and stop writing.