Sunday, 7 June 2015

Empty data array returned by ssp.class.php

I've just been reading a fantastic article and this is by far one of the best quotes in it:

"A senior developer is intimately familiar with their own failure."

It is perhaps because of the week I've just had that makes me feel like it's particularly brilliant. Let me explain: I've spent a week trying to re-code a really rather cool application (which my team wrote and which we're rightly proud) for another format… and, as you might've guessed, failed. It is not an insurmountable collection of issues but still issues that will take longer than I have to fix. I know just how I would fix them and the time involved in the fixing and I know the number of heartwarming highs and heartbreaking lows that effort would involve. The highs and lows I can live with but the time isn't something we can bear so it'll have to take a sprint or two or perhaps a re-examination of the whole solution just for that one format.

I'm balding and have dry-skin… I also have to moderate my diet and drink intake… I'm this close to dropping my cigarette intake to 3-a-day (I would give up but I sometimes think it's my vices that make me and 3-a-day sounds like I'm not really smoking at all!). Despite all this, when I sort out an issue in a project, I feel like I have the stature of a god (no, not Bhudda, some handsome Greek god). When I'm confronted with something that just doesn't work I feel each and every one of those extra pounds; each and every-flake of skin that lands on my t-shirt is indicative of my failure as not only a coder but member of the human race and each and every drink is a balm to my tortured soul.

I guess what I'm trying to say is that that there article by Matt Briggs has warmed my heart in that what I constantly feel is indicative that I deserve the title of Senior Developer… I guess. Perhaps as I ease myself into it I'll get myself down to 3-a-day, drop some pounds, shave my head and moisturise more. The drink intake has been successfully moderated as I really, really can't code with a hangover and drunken coding is a recipe for disaster!

Getting back to the title of this post though I noticed that a server-side script written to return rows for a DataTable wasn't. It was returning the number of results but the data array was stubbornly empty. I checked the variable array being sent to the server in the ajax code and everything seemed to be fine. I echoed out the queries that the server-side script was making and clocked that the SQL was limiting the result to 0… this was despite the length variable being set… I took to echoing out individual values from the array and everything seemed to be okay until I got to the length… I'd not long ago changed the table as I was showing too much data which wasn't relevant and wasn't showing some data that the client felt was relevant. But I was still returning that data, the new stuff was simply tacked onto the end of the query so the resulting variable was huge. And that was the answer, I was asking far too questions and because the variable array was so large it was getting truncated and I was losing the pagination data, effectively making the query end like this:



LIMIT 0, 0

No wonder I wasn't getting any data despite the pagination still working. I knocked off the extraneous fields from the table columns array and all was well. Always pays to check the length of the data being sent in a GET request though!

Actually I had a brain-wave while I was looking at what I'd just written and clocked that I use that extra data to populate modal dialogs should the user want to edit the data. But I can still return the data and then act upon it, the issue is in the asking for it. I can add all sorts of data to the row but I need to be careful about what I ask for! There was me getting ready to prune the dialog and the returned data and I don't need to, everything it still gravy: I just need to ask for the absolute minimum of what I need.

No comments:

Post a Comment