Indiana native. Purdue grad. Programmer / Dev Ops in trade. Dog owner. Husband and father. Have questions? Ask!
407 stories
·
0 followers

TRY/CATCH Doesn’t Always Work.

2 Shares

If you’re using TRY/CATCH to do exception handling in T-SQL, you need to be aware that there are a lot of things it doesn’t catch. Here’s a quick example.

Let’s set up two tables – bookmarks, and a process log to track whether our stored proc is working or not:

DROP TABLE IF EXISTS dbo.Bookmarks;
DROP TABLE IF EXISTS dbo.ProcessLog;

CREATE TABLE dbo.Bookmarks(
    URL VARCHAR(50));
GO

CREATE TABLE dbo.ProcessLog(
    ProcessDate DATETIME,
    StatusMessage VARCHAR(50));
GO

And create a simple stored procedure that adds a bookmark, and tracks whether it was successful:

CREATE OR ALTER PROC dbo.AddBookmark @URL VARCHAR(50) AS
BEGIN
    BEGIN TRY
        INSERT INTO dbo.Bookmarks
            VALUES (@URL);

        INSERT INTO dbo.ProcessLog
            VALUES (GETDATE(), 'It Worked');
    END TRY

    BEGIN CATCH
        INSERT INTO dbo.ProcessLog
            VALUES (GETDATE(), 'It Failed');
    END CATCH

END
GO

When you execute the proc, it succeeds, and a row is written to ProcessLog:

But if someone adds a new column to our Bookmarks table:

ALTER TABLE dbo.Bookmarks ADD BookmarkedOn DATETIME;

And we try to run our stored proc again, it fails:

Because the stored proc’s insert statement didn’t explicitly list the columns in the Bookmark table:

INSERT INTO dbo.Bookmarks
            VALUES (@URL);

Okay, that’s bad code – but did the CATCH come into play? Check the table contents:

There’s no row in ProcessLog saying that the process failed! What happened? Wasn’t our CATCH supposed to insert a row there?

Catch only catches SOME errors.

Early errors aren’t caught, like errors when the query is being compiled. In this case, when SQL Server was building an execution plan for the stored procedure, SQL Server couldn’t build a valid execution plan because there’s no way for it to execute the insert. The compilation failed, which technically means the query wasn’t executed – even though to you and me and our app users, it was executed.

Low-priority errors aren’t caught, like under severity 10. Those are just considered informational messages.

High-priority errors aren’t caught, like severity 20 or higher. Those terminate the connection altogether.

Right about here is where you’re expecting me to give you a magic bullet that fixes these problems, but instead, I have to give you a monster amount of documentation. Check out the epic posts Error and Transaction Handling in SQL Server Part 1, Part 2, and Part 3 by Erland Sommarskog. They’re monster posts, and I have to be honest with you, dear reader, I haven’t ever read them cover to cover. This is one of those times where I’m glad I have a fake job, aka consultant, where I can just say, “If our stored procedure’s business logic is really that critical and complex, it’s time we move that processing over into an application language like C# that has better error handling and testability.”

Read the whole story
RyanAdams
41 days ago
reply
Central Indiana
Share this story
Delete

Nancy by Olivia Jaimes for Sun, 01 Sep 2024

1 Share

Nancy by Olivia Jaimes on Sun, 01 Sep 2024

Source - Patreon

Read the whole story
RyanAdams
66 days ago
reply
Central Indiana
Share this story
Delete

Please Don’t Idolize Me (or Anyone, Really)

1 Share

In the wake of the various recent allegations involving Neil Gaiman, people have been both very sad that someone who they looked up to as an inspiration has, allegedly, turned out to be something less than entirely admirable, and are now looking to see who is now left that they can rotate into the spot of “the good dude,” i.e., that one successful creative guy who they think or at least hope isn’t hiding a cellar full of awful actions. One name I see brought up is mine, in ways ranging from “Well, at least we still have Scalzi,” to “Oh, God, please don’t let Scalzi be a fucking creep too.” Which, uhhhh, yeah? Thanks?

I have many thoughts about this and I’m going to try to make sense of them here, as much for myself as anyone else, so this may be messy and discursive and long (seriously, 3600 words, y’all), but, well, welcome to me. So, ordered by how these things come out of my head:

1. Stop Idolizing Creative People. Creative people are easy to idolize because they create the art you love, and that gives you permission to feel things, and to see yourself and your desires reflected in that art. That is a powerful thing, and from the outside, it can feel like magic, and that the people who do it are tapped into something otherworldly and admirable. Plus, they often get to have cool lives and get to know other cool creative people. They do things that are removed from the day-to-day aspect of a “normal” life, and they’ll even post about them on social media where you can see them. Sometimes, independent of their art directly, they’ll speak about their life, or life in general, and they’ll seem wise and considered and kind. I mean, what’s not to like?

But please consider that this is all an extremely mediated experience of this person. The art is the edited and massaged result of hours and days and weeks and months of work, into which the work of many others is also added. My novels originate from me, but it’s not just me in there, nor is the final form of the novel an accurate statement of who I am as a person, not least of all for the simple reason that I am not trying to tell my story in my novels. I’m creating fictional characters, and the world in which they make sense, for the purpose of the story.

Despite how it might look from the outside, this is not sorcery. It’s years of experience at a craft. It’s not magic, just work. A completed novel (or any other piece of art) won’t tell you much about the specific, day-to-day life and inclinations of the individual who made it, other than a general nod toward their competence, and the competence of their collaborators. Likewise what you see of their lives, even from the illusorily close vantage of social media, is deeply mediated. Lives always look admirable at a distance, when you can only see the lofty peaks and not the rubble at the base — especially when your attention by design is pointed at those lofty peaks. There’s much you don’t see and that you’re not meant to see. The vast majority of what you’re not meant to see isn’t nefarious. It’s just not your business.

Now, before I was a professional creative person, I was an entertainment journalist who spent years interviewing writers, directors, movie stars, musicians, authors and other creative folks. Since I’ve been on the other side of the rope, I’ve likewise met a huge range of creative people from all walks of life. Please believe me when I assure you that creative people are just people. Richer and/or more famous? Sometimes (less often than you might think, though). Prettier and/or more charismatic? Especially if they’re actors or pop stars, often yes! But at the end of the day they are just folks, and they run the whole range of how people are. By and large, the day-to-day experience of getting through their life is the same as yours. Outside of their own specific field of work, they don’t know any more about life, have no more facility for dealing with the world, and have just as few clues about what’s going on in their own head, as anyone else.

They’re just people. Whose work is making the stuff you like! And that’s great, but that’s not a substantive basis for idolizing them. It makes no more sense to idolize them than to idolize a baker who makes cookies you like, or the guy who comes and trims your hedges the way you want them to be trimmed, or the plumber who fixes your clogged drain. You can appreciate what they do, and even admire they skill they have. But holding them up as a life model might be a bit much. Which is the point! If you’re not willing to idolize a plumber, then you shouldn’t idolize a creative person.

(“But a plumber doesn’t make me feel like a creative person does,” you say, to which I say, are you sure about that? Because I will tell you what, when my sump pump stopped working and the plumber got in there, replaced the pump and started draining out my basement which had an inch of standing water in it, that man was the focus of all my emotions and was my goddamned hero that day. My plumber that day did more for me than easily 90% of the great art I’ve ever experienced.)

Enjoy the art creative people do. Enjoy the experience of them in the mediated version of them you get online and elsewhere, if such is your joy. But remember that the art is from the artist, not the artist themselves, and the version of their life you see is usually just the version they choose to show. There is so much you don’t see, and so much you’re not meant to see. At the end of the day, you don’t have all the information about who they are that you would need to make them your idol, or someone you might choose to, in some significant way, pattern some fraction of your life on. And anyway creative people aren’t any better at life than anyone else.

Which brings up the next point:

2. Fuck idols anyway! People are complicated and contradictory and you don’t know everything about them! You don’t know everything even about your parents or siblings or best friends or your partner! People are hypocrites and liars and fail to live up to their own standards for themselves, much less yours! Your version of them in your head will always be different than the version that actually exists in the world! Because you’re not them! Stop pretending people won’t be fuck ups! They will! Always!

This sounds more pessimistic about humans than perhaps it should be. When I say, for example, that people are hypocrites and liars, I don’t mean that people take every single opportunity to be hypocrites and liars. Most people are decent in the moment. But none of us — not one! — has always lived up to our own standard of behavior, and all of us have had the moment where, when confronted with a situation that would become an immense pain in the ass if we stuck to our guns, or demanded the inconvenient truth, decided to just bail instead, because the situation wasn’t worth the drama, or we had somewhere else to be, or whatever. We all choose battles and we all make the call in the moment, and sometimes the call is, fuck this, I’m out.

Every person you’ve ever admired has fucked up, sometimes really badly. Everyone you’ve ever looked up to has secrets, and it’s possible some of those secrets would materially change how you think about them, not always for the better. Everyone you’ve ever known has things about them you don’t know, many of which aren’t even secrets, they’re just things you don’t engage with in your day-to-day experience of them. Nevertheless it’s possible if you were aware of them, it would change how you feel about them, for better or for worse. And now let’s flip that around! You have things about you that even your best friends don’t know, and might be surprised to learn! You have secrets you don’t wish to share with the class! You have fucked up, and lied, and have been a hypocrite too!

You are, in short, a human, as is everyone you know and every one you will know (pets and gregarious wild animals excepted). And all humans are, charitably, a mess. This doesn’t mean there aren’t good people or even exemplary people out there, since there are, along with the ones that are, charitably, a real shit show. What I am saying is that even the good or exemplary people out there are a mess, have been morally compromised at some point in their lives, and have not lived up to their own standards for themselves, independent of anyone else’s standard for them.

One of the aspects of being an “idol,” I think, is that higher standard that other people expect of you — that in every situation where the aspect they idolize you for is in play, you will act in a manner that is right and correct by their standard, which of course you will likely not know about because you don’t actually know them (or often know that they exist). This is, by definition, an impossible standard to be held to — you didn’t agree to it, or to engage with it — and an impossible standard to hold other people to without their direct consultation. Every human made to be an idol is destined to fail at the job. You don’t even have to have feet of clay! You just didn’t know you were on a pedestal to begin with.

(This does not excuse shitty action. The fact people should not be idols in the first place is not exculpatory for the choices one makes on one’s own. If you’re sexually assaulting people, or being a racist or sexist or homophobe or other flavor of bigot, or using your situational power coercively (as just a few examples), then hell yes you are going to be called out on it. And to be clear, it is not unreasonable, to put it mildly, to expect people not to sexually assault other people, or not to denigrate other humans for being who they are, etc. But this only adds to the point about idols, now, doesn’t it. You don’t know what you don’t see, and you don’t know what you’re not seeing, until it is hauled out into the light one way or the other. If it is hauled out into the light at all.)

I don’t think anyone should idolize anyone, ever. It’s not great for them, and it’s not great for you, they probably didn’t ask to be idolized (and if they did, holy shit, fucking run), and in the end unless you’re so completely wrapped up in their lives that they have no secrets from you — which is never — you don’t know enough to make that call. People do it anyway, and then disappointment happens, but they shouldn’t have done it in the first place. Stop idolizing people. It’s not fair for anyone.

What to do instead? Enjoy their work, if they’re a creative person. Appreciate the kind and good aspects of their life that you can see, and the decent actions they undertake in public, with the knowledge that what you see of them is a mediated and elided version. Understand that we all have a different version of ourself for every person we meet, and that every person we meet has a different vision of ourselves in their head, and very often, those two versions are not the same. Like them, based on what you know of them! Love them, if it comes to that. And when and if you learn something new about them that you didn’t know before, let empathy guide you to a new understanding of them and what they mean to you.

And now, taking all of the above into consideration:

3. Absolutely 100% do not idolize me. I don’t deserve to be idolized because no one deserves to be idolized, but also, holy fuck, I do know me and I’m a mess. There have been lots of things in my life that I’ve done that have not been admirable or kind. I can be petty and shitty and competitive and cruel. I am lazy and inattentive and when I let things slide (which is often), I end up jammed up on my responsibilities, which makes me irritable and no fun to be around. I have a temper which goes from zero to sixty almost instantaneously; if I’m not actively paying attention to it, I can become a sudden, unreasonable rage monster, which is a burden to people I love, and I hate that fact about myself (pro tip: don’t travel with me, the rage monster comes out a lot then).

I can be controlling and demanding but I want other people to handle the details, i.e., executive asshole. I am strategic in a way that can be bloodless. When I’m insecure I brag a lot, which is unflattering. If you cross me, I won’t go out of my way to make your life miserable (that would require effort on my part), but I will absolutely enjoy when you take a literal or metaphorical tumble down the stairs. God knows I’ve enjoyed the failures of the people who have spoken ill of me, almost as much as I’ve enjoyed the fuming, spittling rage they’ve felt when I’ve succeeded. I spent years cultivating a snarky persona online and while that was fun (for me), I’m increasingly aware that when the tally is added up for Who Ruined the Internet, I’m not necessarily going to be where I want to be on that particular ledger.

And these are only the bad qualities of mine I wish to admit to you at the moment. There are others, I assure you.

So, yes: Who wants to idolize me now?

“But you seemed so nice when I chatted with you online/met you at the convention/saw you at that one place that one time.” Well, thank you, I’ve been in the public eye in one manner or another for three and a half decades now and I understand my assignment; my public persona is friendly and engaging and sociable and mostly fun to be with. It’s not a fake version of me — I am all those things! Honest! — but, again, it’s a mediated version of me designed not only to be a positive experience for the people who meet me but also to get my actually introverted ass through a whole day of events at a convention/festival/book tour/whatever. When I’m done I collapse into an introverted hole. When I came back from Worldcon this week, I slept for 15 hours the first day I was home. It wasn’t just because of jet lag or con crud.

I rather famously call my public face “performance monkey mode,” and likewise what I say about my (current) online mode is that I’m cosplaying as a better version of myself, one that is kinder than I used to be online, and more patient than I am in the real world. If you meet me when I am “off” then you will find that, again, these versions of me are me, just with some things dialed up and other things dialed down. But even that is still a different version of me than, say, the version of me which is at home (which is in fact extremely boring; that version of me doesn’t talk much and mostly stays in my office).

Many of you who have followed me over the years are familiar with me saying things like this, of course, and are likewise familiar with me pointing out that there are a number of things about my life that I don’t mention in public, for whatever reasons I choose. But it’s also true that I’ve been actively online for 30+ years now, and people feel reasonably confident that they have a good bead on me and that there’s not much about me that will surprise them or change their understanding of me. So to bring home the point there are indeed things you don’t know, allow me to surface just one previously unaired fun fact:

I have a concealed carry license.

(Or did; it expired this year and I didn’t renew it, because Ohio changed its laws so that you no longer need a permit to conceal carry in the state. These days in Ohio you can just wander about with a handgun stuffed down your trousers without training or licensing because that’s a real good idea, now, isn’t it. Nevertheless, the license is not necessary anymore so there was not much point in renewing it, although if the law had not changed, I probably would have renewed.)

Why did I have a concealed carry license? Well, ultimately that’s not important. The point is I had one. I didn’t talk about it before because, among other things, the point of a concealed carry license (to me, anyway) is that its existence is not meant to be known by anyone other than that great state of Ohio itself. I am aware, and this is a dramatic understatement, that I am not a person most people would expect to have had such a thing. That the fact I had one will cause a number of people to reconsider what they know about me, for better or for worse. Which is also my point. All y’all have just learned this thing about me! Think about all the other things you don’t know!

Oh, God, this is where Scalzi starts admitting to terrible, terrible things. No. I feel pretty confident I live a tolerably ethical life. Part of the reason for this is that I have what I think is a decent operating principle, which is: If I’m thinking of doing something, and Krissy called me right then and asked “what are you doing?” and I would be tempted to lie to her about it, then I don’t do that thing. Because Krissy is the most important person in my life, and I don’t want to lie to her about what I’m doing (I have lied to her exactly once. She knew instantly. I haven’t bothered lying to her since). This is not replacing Krissy’s ethics with my own; it’s me knowing whether by my own ethics, I would be ashamed to tell to her what I am up to. It works very well. As such, the Krissy Test is an operating principle I highly suggest to others, although I’d suggest replacing Krissy with whomever your life is most important to you.

Be that as it may, my ethics are not universal and some others might not find them sufficient, for whatever reason. I am well aware I still disappoint many people, and that there are people who find my life choices, known positions or public statements (or lack of them, as the case may be) problematic, or who simply wish I would be other than what I am. I can’t help them with this, but again, this is the point. Given the fact that I am a fallible human who has an entire stratum of his life not visible to the world — and the strata of his life that are visible cause significant numbers of people to be irritated and exasperated — is it not better just to not hold me up as an ideal person, or the “good dude,” much less an idol of any sort?

I mean, shit. What Would John Scalzi Do? Solidly half the time, I have no fucking idea. I have to think about it, whatever it is. I have to think about whether I know enough to do or say something about it. I have to decide whether it’s something I want to engage with at all, and whether my engagement with it is something that would be of value to anyone, me included. I have to decide whether engaging with it is worth the shit I will get for it. And then I have to figure out what it means that I am engaging with it, since like it or not I’m a Dude of Reasonable Significance in My Field. I try to be a decent human, when people are looking at me and especially when they are not. But I also know me, and all my flaws and weaknesses and compromises.

What Would John Scalzi Do? The best he can, in the moment. Is that sufficient? For me, yes, most of the time. Is that sufficient for you? That’s up to you.

The point to this all is that people are just a big fucking mess, including the ones you might for whatever reason find admirable. I am no different than anyone else, and you should not be under the illusion that I am anything other than a shambling collection of flaws embedded inside a human form, which also, in its defense, has some pretty excellent qualities as well. We’re all this way! You too!

And while I want you to like my work, and to enjoy the version of me that you see here and elsewhere, don’t put me, or any other person, on a pedestal. Pedestals are wobbly and and don’t give actual humans a lot of room to move. We will inevitably fall off. Keep us with our feet on the ground. That way, when we stumble, there’s a chance we can get back up, and keep going.

— JS

Read the whole story
RyanAdams
83 days ago
reply
Central Indiana
Share this story
Delete

Drabble by Kevin Fagan for Sun, 21 Jul 2024

1 Share

Drabble by Kevin Fagan on Sun, 21 Jul 2024

Source - Patreon

Read the whole story
RyanAdams
108 days ago
reply
Central Indiana
Share this story
Delete

The SQL Language is Just a Hurdle You Gotta Overcome.

2 Shares

I’m not talking just about Microsoft SQL Server specifically here, nor T-SQL. Let’s zoom out a little and think bigger picture for a second: is the SQL language itself a problem?

Sometimes when I talk to client developers, they gripe about the antiquated language.

The order of a SELECT statement doesn’t make any sense. You shouldn’t state what you’re looking for, before you even say where you wanna get the data from. The FROM should really go first so that query-completion tools like IntelliSense have a fighting chance to help you write the SELECT part. If we started writing our queries like this:

FROM dbo.Users u
INNER JOIN dbo.Posts p ON u.Id = p.OwnerUserId
SELECT ...

Then as you started typing stuff in the SELECT, you could actually get useful stuff out of IntelliSense. How many times have you started typing a query, and query completion tools start throwing all kinds of system functions at you? Idiotic.

Exception handling is a painful mess. Let’s be honest here: the majority of stored procedures and functions out there don’t have error handling. They YOLO their way through the data, hoping and praying that things are as we expect, we have the right permissions, structures haven’t changed, and the data is in a useful state. Everybody looks the other way and mumbles, “We’ll handle errors on the application side,” when in reality those errors are either thrown directly at the innocent user, or simply suppressed and not logged anywhere.

It’s not really a standard. Oh sure, SELECT/FROM/WHERE/ORDER BY works in most databases, but even trivially simple applications break if you try to port them from one database management system to another. Your skills transfer in a similar way: even if you’re great at T-SQL exception handling, you’re still gonna have to tweak the way you do it in Postgres. The concepts are standard, but the specifics are different.

Unit testing is a pipe dream. App code developers know if their code changes will break something. Database developers just punt their stuff into development, run the query a few times, nod because no errors get thrown, and then toss it into production. When code breaks weeks or months later, all we hear is, “Nothing’s been changed.”

So why haven’t we moved on past SQL?

In some ways, we have, with object-relational mapping (ORM) tools like Entity Framework, Hibernate, and Django. The database administrator readers here in the audience usually cringe when they hear those words, but the reality is that developers leverage those tools heavily to build new applications. I don’t blame them. I would too, for all the reasons I talked about above.

What those tools do is translate your desires into SQL, though, which brings us right back where we started. Often, the SQL they generate sucks for performance, thus the typical DBA’s feelings about ORMs. So why haven’t we got a new standard way for applications to talk directly to databases, in a secure, performant, and easy-to-write way?

It’s not for lack of trying: at least once every 6 months, I see a post on HackerNews about a better replacement for SQL. Someone puts a lot of thought into the problems, puts a lot of work into a replacement, and then proudly announces it.

And nobody uses it.

Because SQL is the lowest common denominator that works damn near everywhere, for values of “works.”

It works on the back end. Remember when NoSQL came out, and everybody was all “databases r doomd”? And remember what business users said when they wanted to run their reports? NoSQL persistence layers pretty quickly changed their tune, saying, “Oh, well, uh, we meant Not Only SQL, that’s what we meant,” as they struggled to quickly slap in SQL compatibility. Even MongoDB, king of NoSQL, implemented SQL support.

It works on the front end, especially the reporting front end, which is what managers care about. The people who sign the checks wanna see their data in Power BI and Excel. Every new reporting tool that comes out, in order to check boxes and say they’re compatible with every database, implements SQL support. Oh sure, these tools write horrific queries, but they check the box to say they can get data out of all your different persistence layers, and they do it with SQL first because it’s cheap and easy to support lots of databases that way.

I’ll leave you with an amusing quote from Bjarne Stroustrup:

There are only two kinds of languages: the ones people complain about and the ones nobody uses.

Read the whole story
RyanAdams
133 days ago
reply
Central Indiana
Share this story
Delete

I want it all but, it is impossible

3 Shares

I want to read all the newsletters I subscribed to.

I want to read everything in the ten web dev community slacks I joined.

I want to read everything on the seven Discord servers I am on.

I want to read every blog post in the hundreds of feeds I follow.

I want to read every toot of the people I follow on Mastodon.

I want to find more people to follow.

I want to ensure I didn’t miss your cool and happy announcement.

I want to attend your conference/meet-up virtually.

I want to watch your livestream and support you.

I want to view the videos in the archive of this conference that I missed in person.

I want to listen to that audiobook that I’ve had for months.

I want to listen to your podcast.

But I need to work and live life outside of consumption and entertainment.

And then worry that I am behind.

Then, I worry that I must apply the latest knowledge and wisdom, but I probably have missed it.

And worry that pals could think that I ignored them.

I want it all, but it is impossible.

Read the whole story
RyanAdams
152 days ago
reply
Central Indiana
Share this story
Delete
Next Page of Stories