04-23-2020 08:25 AM
Hello,
I'm using Dr. Powell's LabVIEW to SQLite toolkit and it works well. I'm trying to create a LV DataLogger Object with N data logging channels so I need to be able to bind an arbitrary number of parameters into an SQL INSERT statement.
I've attached my re-creation of the original LabVIEW to SQLite example which I got working just fine, thanks Dr. Powell. I'm just unsure of how to programmatically bind an arbitrarily long parameter list using the SQLite Bind Parameters block.
Maybe if I ask a few questions:
In the loop where the three parameters are inserted, time, sine and cosine; Its pretty clear that each parameter matches a question mark in the SQL code. What I'm not totally clear on is why you need the loop. Can someone elaborate on that?
My plan on developing this is to gradually add features I know how to do until I'm finished, but this one has me stumped. Thanks in advance.
-John C.
Solved! Go to Solution.
04-23-2020 09:29 AM
The loop is looping over many rows to INSERT. Such as if you are inserting many sets of values. If you only have one set of values to insert, then you don't need a loop. The code is Preparing an SQL Statement, then using it once for each row to insert.
04-23-2020 09:42 AM - edited 04-23-2020 09:56 AM
OK, that makes sense.
If I had a SQL statement like "INSERT INTO MyTable (Col1, Col2, Col3) VALUES (?, ?, ?); INSERT INTO MyTable (Col1, Col2, Col3) VALUES(?, ?, ?)" where two statements are inserting a new row each, then you need the loop.
But, if I have N parameters to bind for N columns, is there a way to do that?
Obviously, I could do it with some fancy string manipulation and loops but this strikes me as klunky.
Thanks.
04-23-2020 10:11 AM
@JohnCook wrote:But, if I have N parameters to bind for N columns, is there a way to do that?
Sure, just Bind in a loop. That seems too obvious; am I misunderstanding the question?
04-23-2020 10:20 AM
Apologies, I was assuming the only way to bind was to use the Bind block and all the parameters had to be listed in the parameters list. I'll play with it a while and see what I can figure out.
04-24-2020 08:49 AM
Thank you Dr. Powell, I did some more reading and fiddling and am good to go.
I had mistakenly assumed that all binding had to be done in one step with one call to the Bind Parameters block. Not so. I just made an array-driven for loop and bound all the array parameters one at a time in the loop.