question

Stan Davis avatar image
0 Likes"
Stan Davis asked Stan Davis commented

How to Use INSERT INTO to Insert Pointer Data Into Global Table

I am unable to insert a pointer to a rack object using INSERT INTO in a script.

I have assigned pointer data to the 'Rack' column...

1662560899029.png

In my script, I have a valid reference to a rack object. Here is a snippet...

Array myracks = ["Rack_D40_A"];

// cycle thru array of racks
for (int i = 1; i <= myracks.length; i++) {

    Storage.Object rack = Model.find(myracks[i]);  


later in the script, I attempt to insert a pointer to the 'rack' object..

Table.query("INSERT INTO RackVolumeTable2 (Rack) VALUES ( " + rack + " )" );

but get these errors..

1662561109094.png

1662561253613.png


I've even tried hard coding the object...

Table.query("INSERT INTO RackVolumeTable2 (Rack) VALUES ( " + Model.find("Rack_D40_A") + ")" );

but get same errors.


If I assign the column as string data, I can successfully insert the name like this..

Table.query("INSERT INTO RackVolumeTable2 (Rack) VALUES (' " + rack.name + " ')"); 

1662561385931.png


However, I prefer to insert a pointer to the object itself. I believe part of the issue is that 'rack' is a Storage.object and not a node (?), but hard coding the object using Model.find should have worked. What am I missing?? - Stan



FlexSim 22.2.1
global tablesql queries
1662560899029.png (3.1 KiB)
1662561109094.png (10.2 KiB)
1662561253613.png (4.8 KiB)
1662561385931.png (2.3 KiB)
5 |100000

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

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Stan Davis commented

Try:

Table.query("INSERT INTO RackVolumeTable2  SELECT Object FROM Objects() WHERE Object.name='"+rack.name+"'");
· 1
5 |100000

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

Stan Davis avatar image Stan Davis commented ·

Thanks again Jason.

Expanding it further...

Table.query("INSERT INTO RackVolumeTable (Rack, Bay, Level, Slot) SELECT Object, " + myslot.bayID + ",'" + myslot.levelID + "', " + myslot.slotID + "  FROM Objects() WHERE Object.name='"+ rack.name+"'");

note that address scheme uses letters for level (e.g. A)

Appreciate the support - Stan

0 Likes 0 ·
Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Jason Lightfoot commented

The correct syntax would probably be something like this:

Table.query("INSERT INTO RackVolumeTable2 (Rack) VALUES ($1)", Model.find("Rack_D40_A"))

However, in my testing, this query threw an exception. I wasn't able to find an alternative that worked. I'll add this issue to the dev list.

· 1
5 |100000

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

Jason Lightfoot avatar image Jason Lightfoot ♦ commented ·
Yes the OP knows the correct syntax but was having trouble with numeric and string parameters in another post which were circumvented by using string concatenation - which cannot be done with pointers. Hence my workaround answer.
1 Like 1 ·

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.