Author: way0utwest

  • Filetable–Moving files programmatically

    I’ve been playing with Filetable and I was asked an interesting question. Can I move files to a folder programmatically?

    It’s trivial to do this in Explorer. Just drag and drop, and I’d expect that most people using Filetable from the client side would do this. I’d even expect that lots of programmers might use Powershell and the

    However suppose I loaded a bunch of documents into the Filetable folder and I needed to move or process them. I certainly could handle this easily from the client, but it’s actually simpler to do this from T-SQL.

    The Example

    Let’s say I have a few files in the root of my Filetable as shown in this image. My Filetable is the Explorer table inside this path.

    filetable_c

    If I check this from T-SQL, I see four rows I my table. Two jpgs and two pngs. The jpgs are books and I want to move them into a separate folder.

    filetable_a

    I decide to set up a folder inside of this structure. I can do that, using the technique from another post to create a folder from T-SQL. I create the “Books” folder and now If I look at how this appears in the table, it’s like this:

    filetable_b

    In the share it looks like this:

    filetable_d

    What I want is to now set the parent_path_locator of the jpgs to be that of the Books folder. However I can’t update that field as it’s a computed column. However I can update the path_locator of the two rows and compute a new HierarchyID value that includes the path_locator of the Books folder.

    The way to do this is similar to how I would add a file to a folder. I use this code to computer the new HierarchyID and update the existing rows.

    DECLARE @path HIERARCHYID
    DECLARE @new_path VARCHAR(675)
     
    SELECT  @path = path_locator
    FROM    dbo.Explorer
    WHERE   name = 'Books'
    
    SELECT  @new_path = @path.ToString()
            + CONVERT(VARCHAR(20), CONVERT(BIGINT, SUBSTRING(CONVERT(BINARY(16), NEWID()),
                                                             1, 6))) + '.'
            + CONVERT(VARCHAR(20), CONVERT(BIGINT, SUBSTRING(CONVERT(BINARY(16), NEWID()),
                                                             7, 6))) + '.'
            + CONVERT(VARCHAR(20), CONVERT(BIGINT, SUBSTRING(CONVERT(BINARY(16), NEWID()),
                                                             13, 4))) + '/'
     
    Update dbo.Explorer
          SET path_locator = @new_path
          WHERE name = 'Cleankill.jpg'

    Once this is done I see the share looking like this:

    filetable_f

    Here’s the root of the share, and you can see my file has been moved.

    filetable_e

    I repeat this for the other file, though I could potentially have wrapped this all up into one statement. This easily moves my files to the subdirectory in my Filetable.

  • Friday Fun

    Someone at Red Gate sent around a request for the current version of our logo. I’m not sure why it changes so much, but it certainly has a lot over the years. In any case, while they got a real response, I sent this one as a joke.

    rglogo1

    I got chastised by another employee, who said it was clearly this one

    rglogo2

    If you haven’t seen our DBA Team series, here’s article 2. Worth a read.

  • Sabbatical Decisions

    My employer, Red Gate Software, offers a sabbatical to their employees, and this year I’m taking mine. I’ll be gone from June 2 – July 14, away from work, but I’ll be blogging here about my experience.

    I wrote before that I had a sabbatical coming from Red Gate Software this year. It’s a fantastic perk, one that grants all employees 6 weeks of paid time off every five years. The time is supposed to help you grow in some way, not necessarily related to work.

    I had lots of comments on my piece, and I’ve thought about it quite a bit. With my schedule at home, and other items on the agenda, I’ve decided to do the following:

    1. Learn something
    2. Help someone
    3. Wander on my own with a project

    Those broad ideas boiled down into these actual physical items.

    1. Take a class at a local community college. I have an interest in woodworking and I’m looking to go through one of their summer classes. I’ve not made the time in the past, mostly because of the distance to travel to the school, but this is a good time to experiment with the idea.
    2. Volunteer with a charity part time. I have a soft spot in my heard for Habitat for Humanity, and I plan to volunteer with them in both their stores, and on some local builds.
    3. Make something with my hands. As I mentioned, I have an interest in woodworking, but I don’t always get the chance to work through a large project with so many other things happening at the ranch. I decided that I’ve wanted to build a flagpole, strictly for me, and that’s my project.

    Now that my surgery is done and I’m on the mend, I’ll be working through each of these, setting up the details and getting ready for time off.

    My sabbatical is scheduled for Jun 2-July 14, though I won’t be back right away as I will be heading to England right away for SQL Bits XII.

    The blog will likely switch from data topics and SQL Server to some progress on the sabbatical so you can follow along if you like. I won’t syndicate these posts over to SQLServerCentral, as they’re not really relevant, so if you’re interested in how it’s going, subscribe here or keep checking back.

  • The Gadget Itch

    Many of the people that work in technology are interested in gadgets and hardware as much as software. Not all of us, but many of us have had side projects where we’ve melded hardware and software together. For those of us that are older, and started working with computers decades ago, that might have been the only way that we could get a computer system to work.

    I’m glad that I still find people interested in hardware. My son recently built his own gaming computer from parts, and I’m hoping to distract him from some games and get him to help me build some robots with a Raspberry Pi computer and BrickPi add-on board. However it’s not just kids as I’ve seen a number of people at Red Gate working with hardware to build a variety of interesting projects.

    This week I’m wondering if any of you are interested in creating your own devices. If you had the chance to build a device or gadget for work, what would it be? A panic button when there’s a problem that you can press and instantly set of Star Trek “red alert” sirens? A status display based on your continuous integration builds? The question this week is:

    What would you build if you had a parts list like this one?

    Whether you’ve started actually assembling things or you’re just dreaming of something, or perhaps even just seen something that’s intrigued you, let us know. I actually think this might be a fun competition of some sort for an event, perhaps a hacking competition across a couple hours at a SQL Saturday or conference.

    Steve Jones

    The Voice of the DBA Podcast

    Listen to the MP3 Audio ( 1.8MB) podcast or subscribe to the feed at iTunes and LibSyn. feed

    The Voice of the DBA podcast features music by Everyday Jones. No relation, but I stumbled on to them and really like the music. Support this great duo at www.everydayjones.com.