question

Will Bishop avatar image
2 Likes"
Will Bishop asked BenJoaquin Gouverneur commented

cannot pass Global Table node to 'query' command

Ahoy! I am using the query() command a lot to access Global Table data, and I love the $ syntax for building parameterized queries. However, it seems like I can only pass in a parameterized table via reftable(). If I try to pass in a treenode of a Global Table or a Global Variable pointing to a Global Table, I get an error. This is confusing, since I thought that reftable() was a node reference. See below for my example code querying a "sample_table".

I'd like to be able to save my table to something like a global variable to make updating it easy/centralized; I could do this with reftable() and a Global Macro for table-name, but a node reference would ideally be a faster.

This parameterized query works fine:

query("SELECT * FROM $1 WHERE PART_NUMBER = 'E'", reftable("sample_table"));
int rows = getquerymatchcount();
if (rows > 0) {
	string res = getqueryvalue(1, "MATERIAL_LOC");
	pt(res);
} else {
	pt("no matches");
}

This query with a table node reference doesn't work.

query("SELECT * FROM $1 WHERE PART_NUMBER = 'E'", 
	node("Tools/GlobalTables/sample_table", model()));
int rows = getquerymatchcount();
if (rows > 0) {
	string res = getqueryvalue(1, "MATERIAL_LOC");
	pt(res);
} else {
	pt("no matches");
}

This surprisingly also doesn't work if I pass in a Global Variable set to reftable("sample_table").

FlexSim 16.2.0
user command
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matthew Gillespie avatar image
4 Likes"
Matthew Gillespie answered BenJoaquin Gouverneur commented

The actual table of a global table is stored on the "data" variable of the Global Table object. If you put your reftable() command in the script console and execute it you'll see the full path.

· 4
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Will Bishop avatar image Will Bishop commented ·

Thanks @Matthew Gillespie -- the reftable call does point to the variable/data path you describe (shown below).

reftable("sample_table") --> MODEL:/Tools/GlobalTables/sample_table>variables/data

When I set a Global Variable to this treenode (the ...table>variables/data), then passing the Global Variable to the query works. Thanks!

1 Like 1 ·
BenJoaquin Gouverneur avatar image BenJoaquin Gouverneur commented ·

@Matthew Gillespie, I'm confused why I can't pass a Global Variable set to reftable("sample_table") into a query. As @Will Bishop mentions, it doesn't work. Please explain why.

Thanks.

0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ BenJoaquin Gouverneur commented ·

It's working fine for me. Check out this sample model.

Are you trying to put the reftable command in the Value field of the global variable? That's not a code field, the code will never get evaluated.

1 Like 1 ·
BenJoaquin Gouverneur avatar image BenJoaquin Gouverneur Matthew Gillespie ♦♦ commented ·

Yes @Matthew Gillespie, I was putting the command in the value field. Instead I'll assign the global variable in a script with gv_table = reftable("sample_table");.

Thanks for the help!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.