View Full Version : Databases Queries and NR

September 23rd, 2008, 09:27 AM
Now that Girder supports SQLite, if I query a database what is the best way to deliver that information to NR.

Example: Query returns 25 rows
Field 1, Field 2, Field 3, Field 4, etc...

Would I just put the returned data into a table, pickle it up and send it to a NR variable?

Or is there a better way?

Rob H
September 23rd, 2008, 09:53 AM
There are a number of functions in the NetRemote table that can be used to send a table to NR.

If you want the table to be copied across to NR's Lua variable space you can use NetRemote.SetVariable(basename, tableValue) which will copy the table across and update an NR variable called basename .. '.changed'. You can use NetRemote.RegisterVariableWatch() on this NR variable to monitor changes to the table.

If, on the other hand, you want the values in the table to be sent to NetRemote variables then you can use SendStemmedTable(baseLabel, aTable) which will iterate over the key, value pairs in the table and send the value to variables constructed from baseLabel .. '_' .. key. This will work for nested tables.

There's also SendMappedTable, but that's a more complex function that is more suited to the situation where you need to match the names in the table to differently named NR variables. This is probably overly complicated for this case.

December 4th, 2008, 04:56 PM
Did you ever try this out? I am looking at doing something like this for a recipe database. I was wondering if maybe you could post a little code to show how you did it. I already know sql and i can read the data from the table i just want to be able to display it in nr2. Thanks for any help.