|
title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com Using 89% of the same design the blog had in 2001. |
|
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white. As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green. |
|
|
x
MarkUpDown is the best Markdown editor for professionals on Windows 10. It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support. Features you won't find anywhere else include...
You've wasted more than $15 of your time looking for a great Markdown editor. Stop looking. MarkUpDown is the app you're looking for. Learn more or head over to the 'Store now! |
|
| Wednesday, February 03, 2021 | |
|
StackOverflow flashback... Not sure who wrote this comment, and it's a little strongly worded, but man, they're on the money. ;^)
I hope that makes sense. Sure, it's not bad to include some safety checks client-side, but they really are just niceties. Maybe you check a few things for your user's user input without a round trip to the server, but only after you've already put those same rules into your server's code. (This, btw, is why Node is so intriguing. Write once with both sides in mind and you get client-side niceties for "free". Otherwise, if you push me to shoving, I'd say an mvp should only have input validation on the server [in ways that make it easy to return error packages to the client to display]. (And thus the Honestly, this dev taking me to task by saying people can get Labels: development, security, software, SQL, stackoverflow posted by ruffin at 2/03/2021 10:25:00 AM |
|
| Thursday, May 05, 2016 | |
|
So here I am, happily streaming songs from Prime via Amazon Music, when I hear a song from Garbage I know (#1 Crush*). I know this isn't in my favorites playlist on iTunes. Why not? I check, and sure enough, it's a B-side, and I haven't shelled out for the Garbage 20th Anniversary Super Deluxe edition. ;^) So let's see if I can just buy the single file to "add" to my plain wayne version of Garbage (the album). Search a little, and...
Nothing. I tried a few other options, and still nothing. Lots of crush, not so much crush from Garbage. That's interesting. Surely (Shirley?) they have the song, right?
Yes they do. And now I'm previewing it. (See it, down there at #18?) This is as bad as the "Big Jennifer Null" problem I blogged about a while back. THIS IS NOT LITTLE BOBBY TABLES. It'd be bad enough if it was, as even "real" SQL injection should be caught by anyone worth their salt these days. But not being able to search for special characters? No, past that, not being to able to find a title that contains special characters? That's just sad. Unforgivably sad. It's not difficult to search for a string that begins with "#", dang it. Grow up, Apple. I'm dying to fix this. Please let me fix this. As I said before about J-Null, this isn't Little Bobby Tables. This is stoooopid. Insult to injury? When I started writing this, iTunes decided it'd take 23.7% of my CPU. I'd noticed Garbage had a new release, and was on that page, doing nothing. Not playing any music on a page without even a rotating photo carousel (thanks a lot, Draper) takes 23.7% of my CPU.
Fail, Apple. That's a huge fail.* Ha, I can't even make an affiliate link to #1 Crush. Pro tip: Do not search for "Hooper Mix" on the affiliate link tool for the iTunes Music Store. Borderline NSFW. Thanks again, Apple. Labels: apple fail, coding, fail, iTunes, SQL posted by ruffin at 5/05/2016 11:02:00 AM |
|
| Tuesday, April 19, 2016 | |
|
My new favorite quote of Marc Gravell's from StackOverflow:
I understand having entities for editing and manipulation, but don't know why every read that's done a system that employs a conventional rdbms isn't done with native SQL. Labels: entity framework, orm, SQL, stackoverflow posted by ruffin at 4/19/2016 01:45:00 PM |
|
| Friday, March 25, 2016 | |
|
Caught this gem from the BBC via Michael Tsai's blog:
Sorry to say I pulled a legitimate LOL as soon as I read her last name. Ouch. But my reaction? Gosh, which websites and what horrible programmers? I mean, even if you're a two-equals coder (you should use three, natch) in JavaScript, the weakest place I could think of off-hand, And...
... screwed up nobody ever. Which leads me to say... This is not Little Bobby Tables.This is stoopid.We're all stoopid sometimes, but that's what this is. It's stoopid. ??? After a little more digging... Seems I ran through the same steps in my head as the SO post the BBC includes, but the answer seemed obvious; this is the "worst case" I could think of going in...
Well, duh. Though extend my sympathy for those who have a legacy system that still uses XML, not JSON. ;^) What this really shows is...
If the name "Null" is still an issue three to six months from now, SHAME. No, ALL CAPS SHAME. FOR REAL. Horrible. Wow. Seriously, I'm embarrassed for the profession. At worst, you needed to see why your client-side was "letting through" names that were empty so far that they got serialized to XML. Does nobody check the logs? Or are your logs so chatty you wouldn't see this error? /facepalm posted by ruffin at 3/25/2016 11:33:00 AM |
|
| Tuesday, March 15, 2016 | |
|
I've got an MVC app using Entity Framework that has some complex relationships in a notifications module. I've got different queries to get parameters related to existing vs. new subscriptions to events that potentially produce notifications. For the existing subscriptions, I created a view, and then did a SQL to EF to create an entity based on that view. Beautiful, straightforward, no problems. For the new ones, just for fun, I decided that I'd do it all in EF. What a freaking mess. Here's the flowerbox from the repository method, reformatted a touch for width:
That's right, three SO questions plus an insanely nasty query, where I'm still, admittedly, embarrassingly, also appending a Let's list those SO questions again, just to linkify them more easily.
Nasty. EF is broken. It's enough different from SQL that it's a new, often inferior, (& never, that I recall, superior) paradigm. Better not to support this, and to force you to use SQL for these tasks. Do you hire for SQL competency? Then put as much logic as you can in your code's database. posted by ruffin at 3/15/2016 09:31:00 AM |
|
| Monday, March 07, 2016 | |
|
One thing I've constantly wondered about with ORMs is why they use different mental models than SQL, the thing they're almost always abstracting. We hire for SQL proficiency, but then immediately throw it away with complex edge case stuff. You know, like LEFT OUTER JOINs. /sarcasm From MSDN:
Yes, you heard that right. To perform a left outer join, you perform an inner join into a join table, then fill that join table in with default (null?) values if there's no inner join match. Wth? Their example:
I'm tempted just to write a view and use that instead. This is stupid. The syntax really should be...
I don't get it. I wonder how hard it'd be to write an extension that does that... Labels: ef, noteToSelf, SQL, SQL Server posted by ruffin at 3/07/2016 11:34:00 AM |
|
| Tuesday, November 24, 2015 | |
|
You can find 'em here: https://msdn.microsoft.com/en-us/library/ms190324.aspx Or read 'em from that page here: type char(2) Object type: Applies to: SQL Server 2012 through SQL Server 2016. So to check if a table exists (from here): IF OBJECT_ID('TableName', 'U') IS NOT NULL
DROP TABLE TableName;
Voila. QED. Or something like that. And just to complete what I was fiddling with today, here's how to create the two different types of ids, autoincrementing INT (or other INT type) and GUIDs: TableId [uniqueidentifier] CONSTRAINT DF_SerialID DEFAULT newsequentialid(), -- GUID, natch ... or... TableId INT IDENTITY(1,1), -- INTige Labels: noteToSelf, SQL, SQL Server, t-sql posted by ruffin at 11/24/2015 09:03:00 AM |
|
| Monday, November 23, 2015 | |
|
Why should you use DateTimeUTC and not DateTime in your SaaS systems? 4guysFromRolla actually has a pretty good answer from 2007:
UPDATE Orders SET OrderDate = DATEADD(hh, 3, OrderDate)
To make a long story short, you have two choices:
Seems an easy enough choice to me. posted by ruffin at 11/23/2015 02:43:00 PM |
|
| Wednesday, June 17, 2015 | |
|
I've got a project where I've been "given"[1] code that has lots of display logic in sprocs on SQL Server, and that display logic (colors, in this case) is fairly inextricably tied in with the data I want to use too. That is, we have several tables that hold raw data, and these sprocs both tease out the data and put it, somewhat inextensibly, into what boils down to one giant "row" of data. In other words, the data in the sproc's output is not normalized. That info is, in the original system, passed on to SSRS (SQL Server Reporting Services, a, afaict, sort of SQL Server specific Crystal Reports equivalency) and translated, somewhat painfully, into SSRS's pseudo-html. You can get those results into another table pretty easily, via building a table whose structure matches the output and using something like Because of the way we've got this set up, all the values are in a single row that extends until the end of time, with specialized display column value after specialized display column value interspersed with the raw data we want to operate on.[2] The Right Thing To Do would be to rewrite the sproc to give us normalized data. But The Quick Thing would be to try and get each column name and value along with that value's display info into a single row we can easily JSON up and send, packaged with a little more display info that'll replace the static setup we have in SSRS, to the client. So from this:
We want to have...
We can join on So how to turn the first table into one that can be used to build the second? Generic caseI'm not sure why, but I had to stare at some examples for a while before I kinda got what was going on with
So far, so simple enough...
Here's how you need (or how I needed) to think of what comes next -- Each column is a name and value pair. And we have a choice with each column. We can:
Let's start by unpivoting every
The result is reasonably neat. Remember that, in my use case, there are no ids and only one row, so it'd stop after the third row displayed below.
Just for fun, let's experiment with option 3, "display a column as is", by leaving
Fewer rows, and an extra column.
This shows us that what's explicitly listed in the unpivot clause are the only columns that we're going to "explode" into row values, which allows some interesting uses. There are some crazy caveats, however, like that the cols in the UNPIVOT have to be the same type and length apparently. Check out this link at "If we attempt to use the UNPIVOT operator to do this, we run into trouble". That's pretty painful, and requires some wacky casting to keep up the shortcut charade, below. One row mash-up use case (kludges ahoy!)Let's also create something closer to my original use case, so you can tell exactly how it's useful.
select * from #valuesAndDisplayInfo; That gives us the giant single row of data that parallels what the sproc I talked about gives me.
That's kind of nasty. There are three values with three colors for display, all in the same place. Am I supposed to just JSON that up and look for every label in the format So let's
Whoops!
Remember that we have to have all of the column types the same in our UNPIVOT list. Let's get cast crazy.
Though the casting stinks, that's not puke out loud horrible, but I really wanted the colors to be on the same row as the raw values. Right now, they aren't.
Here's the bullheaded, inefficient, magic string way around that that we probably oughta integrate earlier.
Success. I don't love it, but you can see how unpivoting helped us get here.
Pretty good introduction and further exploration of Again, The Right Way is to rewrite the sproc, which I think I'm going to do, but this is [1] Hrm, not exactly "given". Inherited? What's it called when you have contractors who are hired before you start and pick a stack that's probably not what you would've picked? [2] "... on which we wish to operate"? Labels: SQL posted by ruffin at 6/17/2015 04:12:00 PM |
|
| Thursday, April 02, 2015 | |
|
Getting the text of existing sprocs is apparently pretty easy:
Voila. I've been having trouble with ordering the results of a stored procedure, probably by putting results in a temp table. Seeing, in this case, the code to create the temp table the sproc's giving back should be useful. Although, in my case, no dice. I ended up cheating and trivially rewriting the sproc and the sproc it called.
So a quick change there...
... and I'm working. (Or I could have just overwritten spgetcompositejobinfo with one that sorted different, but that's obviously destructive, and usually A Very Bad Idea.) Labels: sproc, SQL, SQL Server posted by ruffin at 4/02/2015 11:23:00 AM |
|
| Monday, April 30, 2012 | |
|
How can I see all my rejected edits? - Meta Stack Overflow: You can also use data to search for your suggestions that were rejected or approved. I have just created two queries for this: Who knew? You can query stackoverflow with SQL. Neat. Unfortunately I'm apparently going to have to start learning its schema if I want to find "edits not yet accepted or rejected", which is what I'm looking for right now. Labels: SQL, stackoverflow posted by ruffin at 4/30/2012 11:01:00 AM |
|
| Friday, November 04, 2011 | |
|
Every so often I talk myself out of believing I know which JOIN I want to use in SQL-land. "LEFT OUTER doesn't mean "OUTER" from the point of view of the LEFT table does it? There's no way. It's the entire LEFT table's OUTERness. Right? Yes. Right? Well, try it. But it's a compound statement. I don't really want to write a stupid trial statement, do I? I know this. It's all of the LEFT." "Right?" This visual review is great. LEFT OUTER JOIN is exactly what I thought it was. (Thanks Denny Green): Left outer join produces a complete set of records from Table A, with the matching records (where available) in Table B. If there is no match, the right side will contain null. And continue... That'll last me another year or so. Labels: SQL posted by ruffin at 11/04/2011 11:10:00 AM |
|
| Thursday, September 01, 2011 | |
|
Surprising that I couldn't cut and paste from SQuirreL-SQL to phpMyAdmin when using sprocs. But then if you think about it for a second, it makes a lot of sense -- the parser in phpMyAdmin stops at a semi-colon and, Emeril-style, BAM! It runs it. You've got to change your delimiter. Nth Design ยป Using phpMyAdmin to Create Stored Procedures: 1 Open phpMyadmin. So that delimiter spot is here:
Below "sig" from the Chrome BlogThis extension. I don't think Pyra's link ever did this. I'll leave it this time, Google, but I'm not using that extension again unless I'm really bored and have Chrome's bookmark toolbar off again. 'via Blog this' Labels: phpMyAdmin, problem solved, SQL posted by ruffin at 9/01/2011 10:10:00 AM |
|
| Wednesday, January 19, 2011 | |
|
oracle - SQL - fetch the row which has the Max value for a column - Stack Overflow: I see many people use subqueries or else vendor-specific features to do this, but I often do this kind of query without subqueries in the following way. It uses plain, standard SQL so it should work in any brand of RDBMS.SELECT t1.* Well played, Mr. Karwin. Labels: code, problem solved, SQL posted by ruffin at 1/19/2011 11:18:00 AM |
|
|
| |
|
|
All posts can be accessed here: Just the last year o' posts: |
|||||||||||||||||||||
|
||||||||||||||||||||||
|
|
|
|