Delete Query Returning NullPointerException

I am getting this error that doesn’t seem to make sense at all. I have a query set up to delete rows from my database (using runPrepUpdate) but whenever I run it, it will give me an error saying NullPointException. I recognize this as a Java error, and I checked anywhere I could think of that might have something missing. I have made sure that it is not the WHERE clause in the DELETE query, or the possibility of there being no rows to delete. If you guys need me to paste code and a table or if I missed a detail, let me know.

Link to full Error Report:
http://pastebin.com/rRydHTp0

I am running:
Ignition v7.6.1 (b2278)
Java: Sun Microsystems Inc. 1.6.0_35

Looks like one of your query parameters is null, the 2nd one maybe…

What’s the script/query look like?

[quote=“Kevin.Herron”]Looks like one of your query parameters is null, the 2nd one maybe…

What’s the script/query look like?[/quote]

system.db.runPrepUpdate("DELETE FROM telephone WHERE Contact = %i" % (CDPrimaryKey))

I know that it is not the CDPrimaryKey as I tried manually replacing it with an int in the code. E.G:system.db.runPrepUpdate("DELETE FROM telephone WHERE Contact = 15")And I also tried having it delete everything with a primary key above 0 (which is everything) using this code: system.db.runPrepUpdate("DELETE FROM telephone WHERE Contact > -1")

Side note: Is there an easy way to copy and paste a table with its data with ignition? I tried copying it with the Database Query Browser, but it just gave me the data and it was in an ugly format.

Oh, err, you’re just using this wrong. You’re not supposed to do the substitution of the values into the query yourself. See inductiveautomation.com/support/ … update.htm

Use ‘?’ for the args, pass in an argument array to the runPrepUpdate() function, etc…

[quote=“Kevin.Herron”]Oh, err, you’re just using this wrong. You’re not supposed to do the substitution of the values into the query yourself. See inductiveautomation.com/support/ … update.htm

Use ‘?’ for the args, pass in an argument array to the runPrepUpdate() function, etc…[/quote]

  1. That link gave me a 404
  2. I know that’s not the way I’m supposed to use the runPrepUpdate, been too lazy to change, but I also noted, that I tried the query without the variable at all, and it still gave me an error. See the 2nd strip of code.

EDIT: Just tried the query using the proper arg syntax, again it gave me an error. Side Note: I haven’t been using that syntax so that the syntax for runPrepUpdate and runUpdateQuery were more universal, which gives me one less thing to think about. But I upon your suggestion, I think I’ll start switching over, as it does look a bit cleaner.

My point is you can’t use runPrepUpdate that way, apparently. The function is expecting a non-null args array to use. Even empty would probably do, but null isn’t cutting it. Not sure why the user manual link is b0rked…

inductiveautomation.com/support/ … update.htm

[quote=“Kevin.Herron”]My point is you can’t use runPrepUpdate that way, apparently. The function is expecting a non-null args array to use. Even empty would probably do, but null isn’t cutting it. Not sure why the user manual link is b0rked…

inductiveautomation.com/support/ … update.htm[/quote]

If you look at my previous post, I edited in that I tried it with the proper syntax, and I’ll say in this post that I also tried it with the args parameter as empty “xxxx, [])”

EDIT: The link is working now.
EDIT2: I tried the using the runUpdateQuery instead of the runPrepUpdate, and for some reason, using the same code I did earlier, it worked. Here is the code that I used:

system.db.runUpdateQuery("DELETE FROM telephone WHERE Contact = 37")

But that makes me wonder, why is that working, when the other one isn’t.

Hmm… Can you post the error from when you tried it with the empty args parameter?

It gave me the same error.

system.db.runPrepUpdate(“DELETE FROM telephone WHERE Contact = ?”,[CDPrimaryKey])

After doing the runUpdateQuery I tried the runPrepUpdate with the empty [] again, to do a text comparison with the error reports, and this time it worked for no apparent reason. I can’t possibly guess what changed, but this has happened once before, where something isn’t working, I try the other query (which works) then I uncomment the one that wasn’t working before and try it again, which then works. I would like to say that it is a tricky bug in ignition, but I don’t want to point the finger at a programmer who probably knows more than me. Thanks for the help. . . although, I still don’t know what the problem was :slight_smile: (But I’m not about to complain when something starts to work)

Can’t explain the sequence of events that resulted in the line of code working and then working as I have yet to experience same. The original code line had incorrect syntax. The argument placeholder needs to be a ?, not a format code %i (although a format code is required if you are working with dynamically replacing db attributes such as table name, column name, etc.), a comma ‘,’ is required after the final " and before the first arg bracket, and the args go in brackets [], not parens (),

Original:
system.db.runPrepUpdate(“DELETE FROM telephone WHERE Contact = %i” % (CDPrimaryKey))

Correct:
system.db.runPrepUpdate(“DELETE FROM telephone WHERE Contact = ?”,[CDPrimaryKey])

[quote=“markdobtech”]Can’t explain the sequence of events that resulted in the line of code working and then working as I have yet to experience same. The original code line had incorrect syntax. The argument placeholder needs to be a ?, not a format code %i (although a format code is required if you are working with dynamically replacing db attributes such as table name, column name, etc.), a comma ‘,’ is required after the final " and before the first arg bracket, and the args go in brackets [], not parens (),

Original:
system.db.runPrepUpdate(“DELETE FROM telephone WHERE Contact = %i” % (CDPrimaryKey))

Correct:
system.db.runPrepUpdate(“DELETE FROM telephone WHERE Contact = ?”,[CDPrimaryKey])[/quote]

The difference between those two methods of inserting the variable (the %i and ?) is the %i is pythons string management system while the ? is ignitions. And to note to you, I also tried:
system.db.runPrepUpdate(“DELETE FROM telephone WHERE Contact = %i” % (CDPrimaryKey),[])
to satisfy syntax requirements. Although, it looks like I forgot to post that one.