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.

 

Rev 1.0.0 02/28/2020 PBrooks

 

  • Modified the binary data type to create an array control of U8 with the size defined in the DB table
  • Modified to name and create a Control VI ( no block diagram ) for the specified table name
  • Added the DB column data type and size as caption and tip info for the controls
  • Added input to allow setting the Caption as Visible in the Control VI
  • Added input to allow setting the Control VI typdef as a strict

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
PhillipBrooks
Active Participant
Active Participant
on

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

dsv4
Member
Member
on

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!

PhillipBrooks
Active Participant
Active Participant
on

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

AristosQueue (NI)
NI Employee (retired)
on

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.

KrisnaWisnu
Member
Member
on

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 2021
PhillipBrooks
Active Participant
Active Participant
on

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

T@nvi143
Member
Member
on

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
on

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.

maurizio.bollini
Member
Member
on

Thanks Phillip, a great VI. It saved me a lot of time!

 

Maurizio.

Maurizio Bollini
Certified LabVIEW Architect
http://www.met.it
https://www.linkedin.com/in/mauriziobollini/
Contributors