LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binding N Parameters in SQLite query statement

Solved!
Go to solution

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.

 

0 Kudos
Message 1 of 6
(3,656 Views)

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.

0 Kudos
Message 2 of 6
(3,634 Views)

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.

0 Kudos
Message 3 of 6
(3,627 Views)
Solution
Accepted by topic author JohnCook

@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?

Message 4 of 6
(3,618 Views)

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.

0 Kudos
Message 5 of 6
(3,614 Views)

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.

0 Kudos
Message 6 of 6
(3,556 Views)