LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C library function call - Unavailable Type for one of the parameters in the Function Prototype.

Solved!
Go to solution

Hi,

 

I'm doing a job that has been already done by some others: implementing a LabVIEW SQLite Wrapper, I know how to do that with .NET alas I would like to do that in C, mostly for performance purposes and my poor pointer knowledge is kinda make me stuck.

 

A couple of informations are kindly provided here:

 

What I would like to do, is just to open a connection to a SQLite Database (if not existing, the SQLite engine will create the embedded Database and the related file to save the data and everything). The function to perform the operation is given in page below:

 

It seems pretty simple:

int sqlite3_open(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);
int sqlite3_open16(
  const void *filename,   /* Database filename (UTF-16) */
  sqlite3 **ppDb          /* OUT: SQLite db handle */
);
int sqlite3_open_v2(
  const char *filename,   /* Database filename (UTF-8) */
  sqlite3 **ppDb,         /* OUT: SQLite db handle */
  int flags,              /* Flags */
  const char *zVfs        /* Name of VFS module to use */
);

 

However I'm struggling a bit about the following type:

sqlite3 **ppDb          /* OUT: SQLite db handle */

 

And I'm not really sure about which type to use when I'm calling this function from LabVIEW

 

 

Any idea, I guess it's real easy, but I'm not really used to have a type which is I suppose the DataInstance but as it's not clearly explicted in the LabVIEW interpreted C Library Function prototype (InstanceDataType makes sense but not sure though) I'm not really sure what I'm showing in the attached screenshot is valid or not.

 

My VI seems to work like a charm, but don't really know if I'm doing something wrong.

 

Another prototype that I have no idea about the proper LabVIEW call is the close function:

Let me get this traight, usually a parameter has a name, right? but seems that nope:

int sqlite3_close(sqlite3*);
int sqlite3_close_v2(sqlite3*);

So also no idea about the parameter setting for this one... has to be considered as the self instance like the one calling this function is this... but I'm not passing any object?

Really confusing...

 

sqlite3*

 

I might sound really silly, but if anybody could point me some directions, I would be really grateful for that.

 

Thanks

 

Message 1 of 5
(3,030 Views)
Solution
Accepted by topic author Ehouarn

Ehouarn wrote:

However I'm struggling a bit about the following type:

sqlite3 **ppDb          /* OUT: SQLite db handle */

And I'm not really sure about which type to use when I'm calling this function from LabVIEW


This parameter should be a pointer-sized integer, passed by pointer. Doesn't matter if it's signed or unsigned. The SQLite library will allocate memory for you, then put a pointer to that memory location into the pointer-sized integer that you pass in.

 

As for the close function, you should pass that same pointer-sized integer, but this time pass it by value (because it's referenced with a single *, not two). There's nothing wrong with the documentation omitting the parameter name. For the purposes of a function prototype, the parameter name is unimportant, since all you need to know is the type of the data. How the function chooses to refer to that parameter internally is irrelevant.

Message 2 of 5
(2,936 Views)

Thanks, this helps a lot!

It seems that works like a charm except one thing: LabVIEW is still using the file when I'm attempting to delete the sample database file.

 

 

 

0 Kudos
Message 3 of 5
(2,917 Views)

As I noted in my previous post, in the close function, pass the parameter by value, not by pointer to value.

 

In the Open function, you need to pass the value by pointer, because the function modifies the value (you pass in a value of 0, and it updates it with the memory location of the structure that it allocated). The close function doesn't modify the parameter, so it should be passed by value. The reason it's not closing properly right now is because you're not passing the correct value, so it doesn't properly deallocate the structure.

Message 4 of 5
(2,890 Views)

Yeah you are right, sorry, my bad.

 

I dunno why for some reasons my brain was reading

"you should pass that same pointer-sized integer, but this time pass it by pointer to value."

instead

"you should pass that same pointer-sized integer, but this time pass it by value."

 

Anyway it makes sense now, and everything works like a charm!

 

Everything is deallocating and finally I start to understand a bit better how it works behind the scenes.

 

 

Thanks again for your great support Nathand!

 

0 Kudos
Message 5 of 5
(2,862 Views)