Create a Table on the Fly

Is there a way to create a table (or any variable for that matter) from a command? I want to be able to create new tables from within my program without having to declare them ahead of time.

Thanks,

Dave

Hi Dave,

Short answer: No.

Longer answer: The closest we come to letting you do this is when you us a subroutine. Can you tell us more about what you’re up to here? Perhaps whatever you need the on-the-fly table for can be done in a subroutine?

MWTMI (maybe way too much info, because I know how it’s built):
What happens when you compile and download your strategy, is the controller (at download time) calculates if what you’ve asked it to do will fit in memory. If not, you’ll get at “out of memory” error at that time, vs. later during “runtime” when it might be a little late to do anything about it. Since subroutines can be called by all or none of your charts at once, the controller calculates a “worst case” (most memory used) scenario during that download process.

In any case, can you tell us more about what you’re actually trying to do? Perhaps a subroutine and/or pointer or pointer table could help here!

Thanks,
OptoMary

I need to be able to create tables that can be created, saved, and edited. I’ve posted a companion post which Ben responded to re: using a SQL database. If I can read and write the database in my code using SQL and the Opto Data Link then my problem is solved. Otherwise it seems I have to create a bunch of tables ahead of time and have them waiting when the user needs to create another one.

Dave

If you’ve got a groov Box in the mix for this project, might be easier to write some Node-RED code for what you’re trying to do here. Have you tried Node-RED yet? Fun stuff, and a much bigger set of examples/user-contributed code than our OptoScript examples.

I want to use PAC Control//PAC Display for this particular project,. Will Node-RED work with it? If so, and I can use traditional SQL queries (which it appears I can from the docs),then that will work.

Dave

It is now possible to read/write directly from MS Sql 2016 as I understand it using the REST interface.
Also, it might be possible to have a set of tables standing by that you can write/read from a txt file to use/store the tables as needed to ftp on the microSD.

Thanks! I’m new to the Opto world. Thanks for pointing me to the REST interface. It’s exactly what I need.

Dave

Hi Guys,

Check out the various SNAP PAC REST Api examples (over on the left side of the page), here: Getting Started with the PAC Control REST API for SNAP PAC | Opto 22 Developer

These include a couple of database options. But to be clear, the request is coming from SQL (or Access), which reads/writes to/from the tags in your strategy via the REST API. (Rather than a request/query being initiated by your strategy.)

Beno had an old example where the strategy initiated things, but there was a php layer in it (so your strategy would hit a server running the php code which connected to your database) but that’s got more moving parts.

Of course there’s also OptoDataLink but that costs extra $$ and is pretty much just a pipe between your PAC and a database. It is super easy to set up, basically a wizard where you check the boxes for what you want to move from/to where and when.

And then with groov there’s the whole Node-RED option, which is fun, too! Like most things w/Opto, we have lots of options to choose from…

Hope that helps,
-OptoMary