Question about named query updates vs selects

Is this a hard rule?

I observed that it still execute the named query Insert. ??

You may be able to but I wouldn't advise it and there's no reason to go against this advice. Presumably when you insert, many times you want the id of the record you just inserted in case you need to use it elsewhere, and that's only possible with the update queries functions and leveraging the getKey=1 kwarg.

1 Like

Thanks.
My team expect to use named Query all the way.

I just read the manual on the command.

If I understood correct, the order of ? to list must be strictly in order?

With named queries you still have to select whether its a "Query" (for SELECTs) or "Update Query" (for INSERT/UPDATE/DELETE) so that you can get the right info out - either a dataset for the SELECT, or the id/number of rows affects for the others depending on if yo use getKey or not.

Yes, the ? are filled in, in order, by your list of arguments, and the ? cannot be used for SQL keywords like the table name but only actual values. More about it in the documentation - system.db.runPrepUpdate - Ignition User Manual 8.1 - Ignition Documentation

1 Like

when getKey=1
the PrepUpdate command returned error "A result set was generated for update."

Otherwise when getKey=0
PrepUpdate return -1 (what does -1 means)

I'm still pretty new to Ignition but here's what it sounds like:

When getKey = 1, the query tries to return "the newly generated key value" i.e., it's attempting to return one number but instead is getting an array or list as a "result set". If you've not assigned a Primary Key to the table you're updating, it may not know which column to treat as the key and so returns all columns, giving more values than it expects. Honestly, just a guess though.

I'm unsure what the -1 return means when getKey = 0. Usually, I've seen a -1 used as no-selection, like in the selected row component of a power table. I would think if no rows were affected, however, that getKey=0 would return 0, so maybe it means ALL rows? Even then I would think it would just return the actual row count. I'll try and do some testing to replicate.

What is the query you are putting in your prepUpdate ststament? Share that

1 Like

Was also wondering about the query. I've been unable to reproduce either result.