system.db.runNamedQuery [tx] syntax

The syntax is documented as
system.db.runNamedQuery(project, path, parameters, [tx], [getKey])

I want to set [getkey] to 1 so I can get the id of the inserted row and feed it back to my table data.

When I run without a [tx] parameter as in

newRowId = system.db.runNamedQuery('queryInsertRow', {}, , 1) # getKey = 1

I get an error:

SyntaxError: ("mismatched input ',' expecting RPAREN", 
('<function:runAction>', 9, 58, "\tnewRowId = 
system.db.runNamedQuery('queryInsertRow', {}, , 1) # getKey = 1\t \n"))

I’ve tried Null, (), {}.

Any ideas?

You can’t leave empty elements in a list of function arguments. Supply getKey as a keyword argument if you want to skip the transaction ID.

Thanks, Phil.

	params = {}
	newRowId = system.db.runNamedQuery('queryInsertRow', params, getKey=1)	 

generates an error

ProjectNotFoundException: project not found: queryInsertRow

queryInsertRow is a named query in the project and it operates correctly in named query testing.
Why is the runNamedQuery looking for the project name?

You must be running it in the gateway. The named query api was misdesigned to not default to its own project when in project scope in the gateway. And the order of parameters established at that time prevents fixing it. ):

All of the other system.db functions take a datasource argument that is optional in any project context, including gateway project contexts.

Thanks, Phil.

  1. So how would I determine where it’s running? There’s no clue in the Query Editor.
  2. If I have to provide the project name can I get that as a project variable so my code is portable?

Adding in the project name parameter seems to allow runNamedQuery to run.

  1. What is the datatype of my variable newRowId? (I want to inspect it.)
  1. Well, it isn’t convenient:
  1. system.project.getProjectName()

  2. Depends on your JDBC driver and primary key column type(s).

Thank you again for your friendly and excellent assistance.

system.project.getProjectName() does exactly that.

I’m using the MySQL JDBC driver and type(newRowId) showed me that it’s just an int.

I’ve learned quite a bit with your assistance and it’s coming together in my head. I’m actually teaching this stuff in work! “In the valley of the blind the one-eyed man is king.”

1 Like