0

I have been having some really weird issues with my app over the past 24 hours. I think I have narrowed it down to some issues with scriptDB.

My database is empty yet results.getsize() says it is not empty.

Here is what I run in my code:

var db = ScriptDb.getMyDb();
var results = db.query({});

Logger.log(results.getSize());

while (results.hasNext()) {
      var result = results.next();
      Logger.log(Utilities.jsonStringify(result));
}

My log shows:

38.0

but nothing else is logged. So where are those 38 results?

  • Apologies if you've tried this already. Are you SURE it's empty, not just full of things that don't stringify? Try a breakpoint inside the `hasNext()` loop, if it gets hit, then there's something. Then try [the deleteAll example](https://developers.google.com/apps-script/scriptdb#deleting_all_items_from_the_database) to clear it. – Mogsdad Jan 30 '13 at 21:40
  • I put a breakpoint on the following line: `var result = results.next();` and the script ran right through. I also tried the deleteAll() example and the script hangs and times out. – ksalling Jan 30 '13 at 21:46
  • Oops - with your symptoms deleteAll() would end up in a continuous loop, I should have noticed that. Regardless, though, that has ensured there's nothing in ScriptDB. At least, nothing that is PROPERLY in it. What happens if you add & delete another object? Too bad `removeBatch()` doesn't work... – Mogsdad Jan 30 '13 at 22:53
  • I've got exactly the same issue. Code that was working fine a month ago is now stuck in an infinite loop. getSize() is returning 182 when the database is empty. I've had to modify my code to detect a getSize() > 0 with hasNext() == null as an empty ScriptDb condition. Nasty! – user1507720 Feb 02 '13 at 18:33
  • Yeah my database has cleared up. I am not sure if the server did it on it's own or was due to submitting a bug to google. http://code.google.com/p/google-apps-script-issues/issues/detail?id=2386 take a look at that though it seems that this can somewhat be prevented by using the lock command and controlling reads/writes a bit better. Google also said they were experiencing some issues on the same day my issues started so maybe it was bad timing as well. – ksalling Feb 03 '13 at 00:12

1 Answers1

0

Not sure how you got into this state, but your ScriptDb appears to be corrupted, and you're in a similar situation as described in Trying to erase a ScriptDb database that is faulty due to my error.

If you're fortunate, things will right themselves, as they did in that other case.

If you can, copy your code to a new script, and start over.

And the only remaining option is to report the problem.

You'll want to star "Feature Request....ScriptDB.removeBatch() function" in the Issue Tracker. If it gets implemented, your problem will be a great test case for it.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • This script deletes and reloads from a spreadsheet. I attempted to do this by using triggers but at the time did not have a lock on the update so I believe the script tried to update the database with the same information concurrently. The very troublesome part of this problem is that some of the 'ghost' entries are tied to my data silos so it really does a number on my whole app. I think I am going to attempt a rebuild on the whole app but there is no way to transfer my incredibly complex gui (I used gui builder) into the new app. So I guess I am going to recode the gui from scratch. – ksalling Jan 30 '13 at 23:30
  • It would be worth your time raising an issue, then - especially if a google engineer is able to reset your ScriptDb. The backup issue was discussed in [Q14385008](http://stackoverflow.com/questions/14385008/backing-up-gapps-source/14391626#14391626). You could star [the problem report](https://productforums.google.com/forum/#!category-topic/drive/report-a-problem/JzLLDpAvses), perhaps it will get some attention. – Mogsdad Jan 31 '13 at 00:00