Help Bites



  • @Captain said in Help Bites:

    Hi all, having a problem with T-SQL truncating some text that I am building up. I'm not really even sure which line it is happening on, but I have some clues.

    I can't post the text I am building, but I was given a couple of pages of plain text to prepend to a database field. The database field is set to be a varchar(max). In the specific case I am working on, the database is already strong somewhat "long" text (another couple of pages), but it's not anything crazy like 2GB.

    Because T-SQL is somewhat braindead about strings that contain new lines, I am building up the prepend string by appending paragraphs together, with appropriate newlines between them (i.e., char(13) + char(10)).

    Then, I am applying an update of the form:

    update dbo.Narrative
       set TX_NARRATIVE = concat( isnull(@PrependText,'')
                                , TX_NARRATIVE
                                , isnull(@PostpendText, '') 
                                )
    where ...
    

    but I am getting an error:

    8152: String or binary data would be truncated.

    Any ideas? I have switched between + and concat, did some googling and found suggestions to cast things to varchar(max), etc. But I am stuck now.

    My suggestion would be to cast.

    Based on my very experience of trying to get a large amount of JSON data out of SQL server a very convoluted way to use SSIS to write to a flat file, letting SSIS do the concatenate and then updating the TX_NARRATIVE column.

    I'm just spit-balling with WAGs.

    So I didn't try anything, it's late and :kneeling_warthog: .



  • Could someone enlighten me on the topic of Christmas postcard etiquette in Western Europe? I'd like to send one to a prof I worked together with this summer. They are currently on parental leave; I've seen their spouse once but never spoke with them because they were engaged in a conversation with someone else. How should I address the postcard: should I send it to the prof, the prof and spouse or the whole family? (How to address the family if they both kept their last names?)



  • I'd send it to the prof and write something like:
    "Hello Prof X,
    bla bla
    I'd like to wish you and your family a merry Christmas."


  • Banned

    @aitap what @Zerosquare said. Write it only to the professor but wish the whole family. It also saves you from awkwardness if he and his wife are separated or something.


  • Notification Spam Recipient

    @Captain said in Help Bites:

    isnull(@PrependText,'')

    Yeah that's probably going to need a cast. Iirc SQL server just assumes the lowest possible storage size when doing things like this so it's taking that empty string and trying to shove the MidlandText into it. Or something similar.



  • @Zerosquare @Gąska Thanks for the advice!


  • Notification Spam Recipient

    @Tsaukpaetra said in Help Bites:

    @aitap if you're into running a Windows desktop (not service, mind!) application, HFS by rejetto should have you covered!

    ... it's guaranteed to contain no malware

    I'll take my business elsewhere.


  • Banned

    @DogsB no need - it already has been!



  • I have a spreadsheet on an external USB drive. I am unable to save it after editing.

    Win 10

    Libre Office 7.1.5.2
    708a4519-b4c4-43ce-975a-c40bfd9c9438-image.png

    The drive is almost full, but it still has 13 GB free. The file I am trying to save is <100 kB.

    I am the owner and have full control of the folder and all files in it.

    Other programs (Explorer, Vim, Gimp, Notepad, etc.) have no problem writing to files in this folder.

    I can save the spreadsheet to a different disk, then copy it to the desired location.

    AFAICT, Libre Office is unable to write any file, existing or new, to any folder on this disk, and it gives me such a helpful, specific error message.
    c11060bb-cefe-4ae9-b307-c86cd5436894-image.png

    Any clues what might be going on here?


  • Considered Harmful

    @HardwareGeek said in Help Bites:

    I have a spreadsheet on an external USB drive. I am unable to save it after editing.

    ...

    The drive is almost full, but it still has 13 GB free. The file I am trying to save is <100 kB.

    I am the owner and have full control of the folder and all files in it.

    Other programs (Explorer, Vim, Gimp, Notepad, etc.) have no problem writing to files in this folder.

    I can save the spreadsheet to a different disk, then copy it to the desired location.

    AFAICT, Libre Office is unable to write any file, existing or new, to any folder on this disk, and it gives me such a helpful, specific error message.
    c11060bb-cefe-4ae9-b307-c86cd5436894-image.png

    Any clues what might be going on here?

    What does file say about the folder, and the existing file if any? Does lsof -p for that PID , grep that folder/ file, show any opening processes?


  • Considered Harmful

    @Karla said in Help Bites:

    Anyone with any experience with pomade?

    Have you got this sorted out yet? I know an Italian.



  • @HardwareGeek If you're able to save to another USB drive just fine, then the first thing that comes to mind is path shenanigans. On Linux, the name of the drive is part of the path. But you're on Windows so the file path would be <letter>:\folder\file , right?

    ...What is the USB device class of that drive? Because AIUI some USB drives are not of the block-device class, but something else. And that... might make a difference.



  • @HardwareGeek Do you get any interesting results if you capture LibreOffice trying to save the file there vs saving it anywhere else using Process Monitor? The problem with this is the sheer amount of stuff happening at this level. You will definitely need to filter by process ID, maybe something else too.


  • Notification Spam Recipient

    @HardwareGeek said in Help Bites:

    Any clues what might be going on here?

    It's trying to open for write when it already has it open for read? Does it happen if you open it from not-that-drive and then save-as to the drive?



  • @Tsaukpaetra He did say:

    @HardwareGeek said in Help Bites:

    AFAICT, Libre Office is unable to write any file, existing or new, to any folder on this disk,


  • Notification Spam Recipient

    @acrow said in Help Bites:

    @Tsaukpaetra He did say:

    @HardwareGeek said in Help Bites:

    AFAICT, Libre Office is unable to write any file, existing or new, to any folder on this disk,

    Ah, right, something happened. :(
    Something happened.



  • @Tsaukpaetra said in Help Bites:

    @acrow said in Help Bites:

    @Tsaukpaetra He did say:

    @HardwareGeek said in Help Bites:

    AFAICT, Libre Office is unable to write any file, existing or new, to any folder on this disk,

    Ah, right, something happened. :(
    Something happened.

    You aren't by any chance visiting TX, are you? :tro-pop:



  • @acrow said in Help Bites:

    What is the USB device class of that drive?

    @aitap said in Help Bites:

    Do you get any interesting results if you capture LibreOffice trying to save the file there vs saving it anywhere else using Process Monitor?

    Interesting questions. I'll take a look later, when I get a chance. It's a bit lower priority than the work I'm supposed to be doing to earn my paycheck.

    One other thing I just thought of that I haven't tried yet. It's an external drive, so disconnecting and reconnecting might do something.


  • Considered Harmful

    @Tsaukpaetra said in Help Bites:

    @acrow said in Help Bites:

    @Tsaukpaetra He did say:

    @HardwareGeek said in Help Bites:

    AFAICT, Libre Office is unable to write any file, existing or new, to any folder on this disk,

    Ah, right, something happened. :(
    Something happened.

    It only looks that way. It was something else.


  • Banned

    Looking for app recommendations:

    A Linux calendar app that can synchronize with MS Exchange to download all the meetings and show very annoying reminders, but absolutely does not interact with the emails in any way whatsoever, not even downloads them. Everything I could find so far is either full package or zero integration.

    Alternatively, a Chrome/Firefox addon for Outlook Web App that reminds me of meetings in a more aggressive way than just a single desktop notification 15 minutes before start.

    (Obviously if I had a choice I'd just use Windows but I don't have a choice.)


  • Java Dev

    @Gąska The 15 minutes is configurable by the meeting organizer. One meeting I'm on is configured to notify a day in advance. So every Tuesday at 11:30 there is a repeating pattern where I get a reminder, think "Isn't that meeting on Wednesday", then remember the retarded notification setting. And then on Wednesday I forget the meeting.

    Attempting to change the notification setting invites everyone on the meeting to a second instance, with all other details the same including the name of the organizer.


  • Banned

    @PleegWat said in Help Bites:

    @Gąska The 15 minutes is configurable by the meeting organizer.

    I don't mean the literal reminder time set up in the meeting invite. I mean the annoying pop-up that shows in the desktop version of Outlook which has a "dismiss" button and a "snooze until 0/5/10 minutes before start" button. I've become very reliant on it telling me when it's time to join the call.


  • 🚽 Regular

    If you're dealing with hypotheticals you might as well go all the way.

    @Gąska said in Help Bites:

    (Obviously if I had a choice I'd just use Windowsignore all meetings but I don't have a choice.)


  • BINNED

    @HardwareGeek said in Help Bites:

    Libre Office

    :there_is_your_problem:

    AFAICT, Libre Office is unable to write any file

    :called_it:



  • Hmm.

    Is encapsulating a canvas inside a React or Vue component a good idea? And, if it is, React or Vue?


  • Banned

    @Arantor both React and Vue are little more than DOM generators. You can encapsulate anything you want in them if it's normally available in the browser. Just remember to keep the same canvas instance between updates, as both libraries love to delete and recreate elements without notice. For React, you use useRef function and ref property (tutorial)Nevermind, this actually does something else than I thought. Seems like there's no way to force the same canvas instance permanently.. No experience with Vue.


  • Considered Harmful

    @Arantor said in Help Bites:

    Hmm.

    Is encapsulating a canvas inside a React or Vue component a good idea?

    Yes. If not, beat things until it is, because it should be a good idea.

    And, if it is, React or Vue?

    Whichever one you're already using, unless it already sucks.



  • @Gribnit completely new greenfield project, so I have pick of frontend tech.


  • 🚽 Regular

    I have no real experience with React or Vue (specially the former), but for canvas/SVG stuff I'd like to ask if you've considered d3?

    It's not an actual suggestion. I'm really asking out of curiosity.


  • Notification Spam Recipient

    @Arantor said in Help Bites:

    Vue?

    Google suggests this hack to have Vue leave an element alone:

    : https://gist.github.com/loilo/a3ec6dbb78d42594b45ec7ebd00139c7

    Breaking the link because apparently iFramely doesn't like gists....?



  • @Zecc I hadn’t but mostly because I need to draw something that approximates a subset of Excel, mostly the pretty griddy formatty shit and cope with potentially 40k cells on screen at once. Canvas will suck but it’ll suck less than maintaining something actively with that many DOM elements.

    D3 always seemed good for drawing but I dunno, feels a bit orthogonal to my use case. That said I did find https://bost.ocks.org/mike/miserables/ which superficially resembles my use case technically even if I have another 6-8x the cells being drawn.

    I dunno. The whole Vue/React debate is mostly for the state management of things around the canvas and to try to box the canvas in with some kind of sensible API.

    The reality is that there will be redraws, filtering of columns and rows and/or redrawing elements as things change.


  • Banned

    @Arantor if you're drawing all the time, then the fleeting nature of React/Vue components doesn't really hurt you. It's when you want the drawn canvas to persist between renders that you'll have a problem.

    You can counteract it with a kind of double buffering. Keep one canvas in persistent state and draw your shit on it, then copy it to the real (in-DOM) one. In React, create a canvas and store it using useState() or whatever is in the vogue this week. This is the one you'll be operating on. The other will be returned from your render() method like normal component, and using useRef() and useEffect() you can call drawImage() to copy one to the other after render.



  • I came back from a week away from home and found that a power cut happened while I was away. The power came back, so I only knew because of stuff like :broken_clock:.

    The only reason this bothered me is that I don't know how long the power was down, and thus if stuff I left in the fridge/freezer was affected. It didn't look like it was but without knowing how long it was, I can't be sure. I'm not overly bothered, but still a tiny little bit.

    So, my question is, is there a gizmo that I could leave in a socket and that would tell me when I come back if there was a power cut, and if so for how long?

    I can easily imagine some sort of complicated IoTS thingy, with an alarm on my phone (and for it to :airquotes:work:airquotes: it would include a SIM card for connectivity while the power is down and what-not), but really that would be overkill. Well, maybe it might be useful, but at the most basic I imagine some sort of semi-passive device with a tiny capacitor, when the power goes down it just records the time (possibly even in some sort of mechanical fashion, although nowadays a chip is likely cheaper) and again when the power comes back up.

    Another way to do it might be to use some sort of heartbeat app on e.g. my phone, but that would only monitor the state of my ISP connection, not overall power to the house, plus to be useful it would need to probe fairly often which would end up being costly on the phone itself.

    Yet another solution is to go and talk to my neighbours (if there was a cut long enough to be an issue, it would have also affected them and they'd have noticed it) but obviously that's :doing_it_wrong:.


  • Java Dev

    @remi Traditionally a wall-powered analog clock is a reliable solution, though that requires knowing the outage wasn't longer than 12 hours.

    My previous freezer would (mechanically) trip a warning light if the internal temperature went above freezing, with manual reset. It might have included a buzzer as well.



  • @PleegWat said in Help Bites:

    @remi Traditionally a wall-powered analog clock is a reliable solution, though that requires knowing the outage wasn't longer than 12 hours.

    That's a smart and simple way to do it. Too smart and simple, no wonder I never thought about it.

    Though it wouldn't detect several outages (or rather it would, but it would lump them all together). Still, probably by far the simplest/most robust solution.

    My previous freezer would (mechanically) trip a warning light if the internal temperature went above freezing, with manual reset. It might have included a buzzer as well.

    Yeah, the day I'll change my freezer I'll probably watch out for this kind of feature. Though the buzzer wouldn't really be helpful here (and it would probably get annoying very quickly), but the light is a neat idea.


  • Discourse touched me in a no-no place

    @remi said in Help Bites:

    My previous freezer would (mechanically) trip a warning light if the internal temperature went above freezing, with manual reset. It might have included a buzzer as well.

    Yeah, the day I'll change my freezer I'll probably watch out for this kind of feature. Though the buzzer wouldn't really be helpful here (and it would probably get annoying very quickly), but the light is a neat idea.

    You can also just buy freezer thermometers which record the highest/lowest temps and alarm if it goes outside of the safe range.



  • @loopback0 That's a good (and simple) idea, thanks. I probably wouldn't care for the alarm thing, just something that can record the highest temp would be enough for this specific purpose.

    We had one regular thermometer (no electronics nor anything, just an old-school thermometer with some sort of indicator that stuck to the highest point it reached until we reset it) like this when I was a kid, it was fun to play with (heat it in your hands, watch the mercury raise, then let it cool and watch the max-temp indicator stay up). Well, maybe not "fun" but it was a way to kill some time ("mom, I'm bored...").

    Knowing the timing/length of power cuts would be interesting, but apart from the freezer there isn't really much that can be affected by it, so it would really be curiosity more than anything else.



  • @PleegWat said in Help Bites:

    Traditionally a wall-powered analog clock is a reliable solution, though that requires knowing the outage wasn't longer than 12 hours.

    As an alternate... I have a couple analog timers for turning some lights on/off.

    I haven't looked, but my UPS for the computer probably logs the events too.



  • I have some C# classes in a chain of inheritance, and some virtual/override methods. This is essentially how they're set up, but the details here have been extremely anonymized (so please disregard the fact that the inheritance structure is basically upside down).

    class Square {
        private int side1;
        public virtual int getCircumference() {
            return side * 4;
        }
    }
    
    class Rhombus : Square {
        public int getSideLength() {
            return getCircumference() / 4;
        }
    }
    
    class Quadrilateral : Rhombus {
        private int side2, side3, side4;
        public override int getCircumference() {
            return side1 + side2 + side3 + side4;
        }
    }
    

    If I have an object quad of type Quadrilateral, why doesn't its getAverageSideLength() (inherited from Rhombus) call the Quadrilateral version of getCircumference()?

    Isn't that one of the touted strengths of inheritance?

    Do I really need to override getSideLength() in Quadrilateral in order for quad.getSideLength() to call Quadrilatleral.getCirfumference()?



  • @djls45 I've tried it on dotnetfiddle just now, and it seems to work the way it should. I made everything public because :doing_it_right: :kneeling_warthog:

    
    class Square {
        public int side1;
        public virtual int getCircumference() {
            return side1 * 4;
        }
    }
    
    class Rhombus : Square {
        public int getSideLength() {
            return getCircumference() / 4;
        }
    }
    
    class Quadrilateral : Rhombus {
        public int side2, side3, side4;
        public override int getCircumference() {
            return side1 + side2 + side3 + side4;
        }
    }
    
    public class Program
    {
    	public static void Main()
    	{
    		var quad = new Quadrilateral() { side1=10, side2=20, side3=30, side4=40};
    		var sq = new Rhombus() { side1=10 };
    		
    		var f = sq.getSideLength();
    		var g = quad.getSideLength();
    		
    		Console.WriteLine("square " + f + " and quad " + g);
    	}
    }
    
    // output: square 10 and quad 25
    


  • @hungrier Oh, yeah, you're right. I am the doy.

    So any explanation why Visual Studio would say that there's no references to Quadrilateral.getCircumference()? (It does show references to Square.getCircumference().)
    Or is that just VS being dumb, too?


  • 🚽 Regular

    I have the following method:

    public void UpdateThingyDimensions(int thingyId, decimal? weight, decimal? length, decimal? height, decimal? width)
    {
        var assignments = new Dictionary<string,decimal?>(4);
        if (weight != null) assignments["Weight"] = weight;
        if (length != null) assignments["Length"] = length;
        if (width  != null) assignments["Width" ] = height;
        if (height != null) assignments["Height"] = width;
        if (!assignments.Any()){
            return;
        }
        
        string sql =
            "UPDATE Thingy SET "
            + string.Join(", ", assignments.Keys.Select(colname => $"{colname} = @{colname}")
            + " WHERE ID = @thingyId ";
        
        using(SqlConnection conn = new SqlConnection(ConnectionString))
        using(SqlCommand command = new SqlCommand(sql, conn)))
        {
            conn.Open();
    
            command.Parameters.Add(new SqlParameter("@thingyId", SqlDbType.Int) { Value = thingyId });
            foreach(var kvp in assignments)
            {
                command.Parameters.Add(new SqlParameter("@"+kvp.Key, SqlDbType.Float){ Value = kvp.Value });
            }
            
            command.ExecuteNonQuery();
        }
    }
    

    This thing threw a "Connection property has not been initialized." exception on the command.ExecuteNonQuery() line.

    But it was! The connection is passed to the command in its constructor and SqlConnection.Open() is called before executing the command

    The connection string is also correct, or the program would have crashed and burned much early on, never mind that the exception would have been different.

    I'm scratching my head at this. Any ideas what could have happened here?

    PS: unfortunately I have no idea what the values of the method parameters were, other than at least one of the decimals was not null and that thingyId was valid.


  • Considered Harmful

    @Zecc No idea what could cause connection not to be initialized, BUT...

    I have no idea what the values of the method parameters were, other than at least one of the decimals was not null

    Gotta use DBNull.Value for null values in nullable columns, otherwise parameter Value is not initialized. Misread the prophecy error message might have been.


  • 🚽 Regular

    @Applied-Mediocrity Not gonna lie. I've fallen for that one before.
    But in this case if the values are null I simply don't add the corresponding assignment. In this case null means "don't update".

    I've been able to replicate this with weight=5, length=0, width=0, height=0, btw.


  • Considered Harmful

    @Zecc Never mind. Misread your code might have been 🦕



  • I don't know what the problem is, but I bet it's going to make you mad when you figure it out.


  • I survived the hour long Uno hand

    @Zecc said in Help Bites:

    I have the following method:

    public void UpdateThingyDimensions(int thingyId, decimal? weight, decimal? length, decimal? height, decimal? width)
    {
        var assignments = new Dictionary<string,decimal?>(4);
        if (weight != null) assignments["Weight"] = weight;
        if (length != null) assignments["Length"] = length;
        if (width  != null) assignments["Width" ] = height;
        if (height != null) assignments["Height"] = width;
        if (!assignments.Any()){
            return;
        }
        
        string sql =
            "UPDATE Thingy SET "
            + string.Join(", ", assignments.Keys.Select(colname => $"{colname} = @{colname}")
            + " WHERE ID = @thingyId ";
        
        using(SqlConnection conn = new SqlConnection(ConnectionString))
        using(SqlCommand command = new SqlCommand(sql, conn)))
        {
            conn.Open();
    
            command.Parameters.Add(new SqlParameter("@thingyId", SqlDbType.Int) { Value = thingyId });
            foreach(var kvp in assignments)
            {
                command.Parameters.Add(new SqlParameter("@"+kvp.Key, SqlDbType.Float){ Value = kvp.Value });
            }
            
            command.ExecuteNonQuery();
        }
    }
    

    This thing threw a "Connection property has not been initialized." exception on the command.ExecuteNonQuery() line.

    But it was! The connection is passed to the command in its constructor and SqlConnection.Open() is called before executing the command

    The connection string is also correct, or the program would have crashed and burned much early on, never mind that the exception would have been different.

    I'm scratching my head at this. Any ideas what could have happened here?

    PS: unfortunately I have no idea what the values of the method parameters were, other than at least one of the decimals was not null and that thingyId was valid.

    What if you move conn.Open(); up above the using statement that sets up command? Maybe new SqlCommand is creating a copy rather than passing a reference since it hasn't been opened yet?

    Disclaimer: totally spitballing and no attempts at finding documentation have been made :kneeling_warthog:


  • Considered Harmful

    @izzion fits in (sideways) to the error message - how are you gonna know if the SqlCommand was validly created if you don't know the connection properties?



  • @izzion I got nothing. I do a lot of this stuff and I can't see any problems, though I use conn.CreateCommand() instead of the SqlCommand constructor. Is there anything useful in the exception?


  • Considered Harmful

    It's too bad there's no way to put documentation right on the method in question, but the test machines keep exploding when we try it.


Log in to reply