LabVIEW APIs Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

DB Tools Create Cluster from Table.vi

If you are asked to interface to an existing database from LabVIEW using the Database Connectivity Toolkit, the first idea you probably have is to create typdef clusters to represent a record. If your database table list is large or uses long field names, it can be tricky to create all of these typdefs manually.

This example uses scripting (my first attempt!) to automatically create a cluster of a specified table name. Each element of the cluster matches the column name and datatype from the table. Save the created cluster as a typedef and then use from your code with the NI DB Tools library.


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Comments
Active Participant PhillipBrooks
Active Participant

Thought it might be useful to show an example of how to use this VI.

You use an open connection reference and table name to create a new VI that contains a cluster that represents the structure of the table as a record. Data types are adapted to DB Toolkit supported types.

Save the cluster as a typedef, then use it to convert a table query into an array of records.

This uses scripting, so you can't include it in an executable.

If you have a large or complex database table, this will save you from manually constructing the cluster and testing over and over.

How to use DB Tools Create Clusters from DB.png

How to use DB Tools Create Cluster from Table.png


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Member dsv4
Member

Absolutely great - Just used this to create a cluster from a table with 72 columns.  Saved me a bundle of time and worked first try.  Great utility - thanks for posting it!

Active Participant PhillipBrooks
Active Participant

Thanks! Glad it was useful.


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Proven Zealot
Proven Zealot

Have you considered making this a right-click plug-in? Users could pop up on a cluster and then the tool could open a dialog where the user specifies the database to use.

Member KrisnaWisnu
Member

oh my god... you save a lot of my time. Thanks PhillipBrooks!

Certified LabVIEW Developer (CLD)
Certified TestStand Developer (CTD)
Using LabVIEW 8.5.1 (2008) to LabVIEW 2016
Active Participant PhillipBrooks
Active Participant

Aristos, the function uses an open db toolkit session to retrieve an existing table by name, then uses the list columns db toolkit function to get the names and types of fields.

I think there are already some lower level functions in the toolkit that create a new table from within LabVIEW if none exists, but I usually define the database first outside of LabVIEW or have to interface to an existing one. It could probably be used as s starting point to create a plug-in, never tried to make one of those before.

If I save my created clusters as typdefs, I can just re-run the tool and resave the output clusters to make my code match the db table structures.

KrisnaWisnu, glad it was able to help you.


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

Member T@nvi143
Member

Hello, I am not able to open the example. As its says sub-VI ' DB Tools List Columns.vi' are missing. As I am new in LV. trying to learn through this example but ..

Not applicable

If you have installed the "LabVIEW Database Connectivity Toolkit" you will find it under "C:\Program Files (x86)\National Instruments\LabVIEW 2013\vi.lib\addons\database\Auxilliary.llb\DB Tools List Columns.vi" if you use LabVIEW 2013. You need this Toolkit for the example.

Contributors