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...

  1. Array myracks = ["Rack_D40_A"];
  2.  
  3. // cycle thru array of racks
  4. for (int i = 1; i <= myracks.length; i++) {
  5.  
  6. Storage.Object rack = Model.find(myracks[i]);


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

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

but get these errors..

1662561109094.png

1662561253613.png


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

  1. 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..

  1. 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:

  1. 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.

Jordan Johnson avatar image
1 Like"
Jordan Johnson answered Jason Lightfoot commented

The correct syntax would probably be something like this:

  1. 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.