SlideShare uma empresa Scribd logo
1 de 18
Efficient Working with Databases
Sam Sharp
MediaMongrels Ltd
sam@mediamongrels.com
WebSockets API
• New version (V2.X) coming soon!
– New OO-based API
– Available on NI Tools Network
Client:
Server:
WSS Support?!
Introduction
• Considerable amount of LabVIEW & Database exposure:
– PHP/MySQL Web Development (4-5 years)
– UK Fuel Cell Company
• Test Station Monitoring System (~100 Test Stations)
• 60s Update Resolution (Test/Asset Status, PC Health)
– Swiss Light Source Company
• Design & Rollout of Production Test Database (10-15 tables)
• TestStand Results Processing Plugin & LabVIEW API
• Reporting & Analysis Tool in LabVIEW
• Legacy Data Import
• Writing VIs to talk to databases in LabVIEW is tedious.
Databases Overview
• Database Advantages:
– Store large amounts of information
– Sharing of information
• Concurrent multi-user access
– Quick access to information
– Eliminate duplication of data
– Information Security
– Backup/Restore
• Common DBMS:
– Relational
• Linked Tables (Rows & Columns)
• Examples: MySQL, MS-SQL, Oracle,
PostgreSQL, SQLite
– NoSQL
• Unstructured/Semi-Structured Data
• Examples: MongoDB, Redis,
Cassandra
• LabVIEW <-> Database
– Database Connectivity Toolkit
– 3rd Party Toolkits (SQLite,
GDatabase)
Database Toolkit Basics
ODBC Drivers
MySQL: MySQL ODBC X.X ANSI Driver
MS-SQL: SQL Native Client
LV 32-bit
Best Practice Hints & Tips
• Security
– Use parameter binding for user
input (SQL injection)
– Passwords in VIs?
– Limit application access to
databases by user roles
• Performance
– Do not repeatedly open/close
the connection
– Database design…
…but what if the username & password is: “ OR “1”=“1
SELECT * FROM operator WHERE username = ““ OR
“1”=“1” AND password = ““ OR “1”=“1”
Any username/password will grant access!
Looks harmless (and I have seen this done in many places!)
https://xkcd.com/327/
Database Design
• Database design is important
– Poorly designed database issues:
• Poor quality data
• Poor performance
– Especially when volume of data increases
• Redundant data
• Poor data integrity
• Difficult to extend/improve
• Normalisation Principles
– 1NF, 2NF, 3NF etc.
– Guide good relational database design
• Each relation adds complexity –
sometimes it is sensible to break to
rules.
– e.g. execution_id in step_measurement
– Storing JSON configuration (for audit
purposes only)
Question:
How long would it take to
write code to
Create,
Read,
Update &
Delete
rows for these five tables?
In ~90 seconds* we have:
• Configured a database connection
• Generated model classes for 5 tables
– One model class per table
– Columns as model properties
– Basic validation (e.g. required fields)
• Created a user interface to create, view, update and delete rows
from our Operator table
… without writing a single SQL query or line of PHP code
…leaving more time to develop the ‘meat’** of the application
…the joy of frameworks!
A prize for anyone that can rewrite as a Haiku!
*sequences have been shortened (no lawsuits please!)
**or your favourite soy-based substitute
Yii PHP Framework
• Popular framework for
developing web-based
applications
– PHP & MySQL
– Based on Model-View-Controller
(MVC) architecture
• Model classes represent object/table
data (e.g. customer, order)
• Views display data to the user
• Controllers implement the ‘business
logic’ by interacting with the models
and preparing the views
– Contains tools for auto-generating
code from a database schema
What if we could do some of
this in LabVIEW?
ActiveRecord
• ActiveRecord implements the Models
in Yii’s MVC
– ActiveRecord objects contain persistent
data and behaviours operating on that
data
• Class = Table
• Object = Row
• Properties = Columns
• Methods = Behaviours (e.g. create, read,
update, delete, business logic)
• Purpose:
– Representing models and their data
– Representing relations between models
(e.g. foreign keys)
– Validating models
– Performing database operations
+Insert()
+Update()
+Delete()
+GetByID()
+CheckPermission()
-id
-username
-full_name
-level
Operator
In ~150 seconds* we have:
• Configured a MySQL connection (ish)
• Generated model classes for 5 2 tables
– One model class per table
– Columns as model properties
– Basic validation (e.g. required fields)
• Created a user interface VI to create, view, update and delete rows
from our Operator Test Execution table
… without writing a single SQL query or much LabVIEW code
…leaving more time to develop the ‘meat’** of the application
…the joy of frameworks!
*sequences have been shortened (no lawsuits please!)
**or your favourite soy-based substitute
Current Features
• ActiveRecord base class
– Create, Read, Update & Delete
of Objects
– Automatic creation of model
classes using Scripting
• Supporting Libraries / Tools
– Database Connection Class
• Database Connectivity Toolkit
– Query Command Library
• Builds SQL queries from VIs
– Integrated into LV Tools folder
Future Functionality
• Query Options
– FindAll, FindByAttributes etc.
• Model Validation
• Foreign Key Relations
– Test_Execution.Test_Steps
• User Interface Binding?
Thanks for listening!
Questions?

Mais conteúdo relacionado

Mais procurados

SQL Server パフォーマンスカウンター
SQL Server パフォーマンスカウンターSQL Server パフォーマンスカウンター
SQL Server パフォーマンスカウンター
Masayuki Ozawa
 
AIXpert - AIX Security expert
AIXpert - AIX Security expertAIXpert - AIX Security expert
AIXpert - AIX Security expert
dlfrench
 
Direct accessったい 121222
Direct accessったい 121222Direct accessったい 121222
Direct accessったい 121222
wintechq
 

Mais procurados (20)

Oracle REST Data Services: Options for your Web Services
Oracle REST Data Services: Options for your Web ServicesOracle REST Data Services: Options for your Web Services
Oracle REST Data Services: Options for your Web Services
 
SQL Server パフォーマンスカウンター
SQL Server パフォーマンスカウンターSQL Server パフォーマンスカウンター
SQL Server パフォーマンスカウンター
 
とっておきの方法! Oracle Databaseの自動アップグレードのお勧め手法 省力・最新化 概要編 (Oracle Cloudウェビナーシリーズ: ...
とっておきの方法! Oracle Databaseの自動アップグレードのお勧め手法 省力・最新化 概要編 (Oracle Cloudウェビナーシリーズ: ...とっておきの方法! Oracle Databaseの自動アップグレードのお勧め手法 省力・最新化 概要編 (Oracle Cloudウェビナーシリーズ: ...
とっておきの方法! Oracle Databaseの自動アップグレードのお勧め手法 省力・最新化 概要編 (Oracle Cloudウェビナーシリーズ: ...
 
ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기ECS+Locust로 부하 테스트 진행하기
ECS+Locust로 부하 테스트 진행하기
 
Jenkinsとamazon ecsで コンテナCI
Jenkinsとamazon ecsで コンテナCIJenkinsとamazon ecsで コンテナCI
Jenkinsとamazon ecsで コンテナCI
 
AIXpert - AIX Security expert
AIXpert - AIX Security expertAIXpert - AIX Security expert
AIXpert - AIX Security expert
 
IIJにおけるGlusterFS利用事例 GlusterFSの詳解と2年間の運用ノウハウ
IIJにおけるGlusterFS利用事例 GlusterFSの詳解と2年間の運用ノウハウIIJにおけるGlusterFS利用事例 GlusterFSの詳解と2年間の運用ノウハウ
IIJにおけるGlusterFS利用事例 GlusterFSの詳解と2年間の運用ノウハウ
 
Direct accessったい 121222
Direct accessったい 121222Direct accessったい 121222
Direct accessったい 121222
 
Ceph issue 해결 사례
Ceph issue 해결 사례Ceph issue 해결 사례
Ceph issue 해결 사례
 
AWS Organizations連携サービスの罠(Security JAWS 第26回 発表資料)
AWS Organizations連携サービスの罠(Security JAWS 第26回 発表資料)AWS Organizations連携サービスの罠(Security JAWS 第26回 発表資料)
AWS Organizations連携サービスの罠(Security JAWS 第26回 発表資料)
 
Website Demo Presentation
Website Demo PresentationWebsite Demo Presentation
Website Demo Presentation
 
Redis勉強会資料(2015/06 update)
Redis勉強会資料(2015/06 update)Redis勉強会資料(2015/06 update)
Redis勉強会資料(2015/06 update)
 
Azure Antenna はじめての Azure Data Lake
Azure Antenna はじめての Azure Data LakeAzure Antenna はじめての Azure Data Lake
Azure Antenna はじめての Azure Data Lake
 
X-DB Replication Server and MMR
X-DB Replication Server and MMRX-DB Replication Server and MMR
X-DB Replication Server and MMR
 
MySQL SYSスキーマのご紹介
MySQL SYSスキーマのご紹介MySQL SYSスキーマのご紹介
MySQL SYSスキーマのご紹介
 
Oracle Exadata Cloud Services guide from practical experience - OOW19
Oracle Exadata Cloud Services guide from practical experience - OOW19Oracle Exadata Cloud Services guide from practical experience - OOW19
Oracle Exadata Cloud Services guide from practical experience - OOW19
 
VMware vSphere Performance Troubleshooting
VMware vSphere Performance TroubleshootingVMware vSphere Performance Troubleshooting
VMware vSphere Performance Troubleshooting
 
Hash join in MySQL 8
Hash join in MySQL 8Hash join in MySQL 8
Hash join in MySQL 8
 
DatadogでAWS監視やってみた
DatadogでAWS監視やってみたDatadogでAWS監視やってみた
DatadogでAWS監視やってみた
 
コンテナ環境でJavaイメージを小さくする方法!
コンテナ環境でJavaイメージを小さくする方法!コンテナ環境でJavaイメージを小さくする方法!
コンテナ環境でJavaイメージを小さくする方法!
 

Semelhante a Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) - GDevCon#2

Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
Jakir Hossain
 
Wei's Self Intro
Wei's Self IntroWei's Self Intro
Wei's Self Intro
sunmast
 

Semelhante a Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) - GDevCon#2 (20)

Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
SQL Server and SharePoint - Best Practices presented by Steffen Krause, Micro...
SQL Server and SharePoint - Best Practices presented by Steffen Krause, Micro...SQL Server and SharePoint - Best Practices presented by Steffen Krause, Micro...
SQL Server and SharePoint - Best Practices presented by Steffen Krause, Micro...
 
D Maeda Bi Portfolio
D Maeda Bi PortfolioD Maeda Bi Portfolio
D Maeda Bi Portfolio
 
Lecture 9: Dynamic web application
Lecture 9: Dynamic web applicationLecture 9: Dynamic web application
Lecture 9: Dynamic web application
 
Data Handning with Sqlite for Android
Data Handning with Sqlite for AndroidData Handning with Sqlite for Android
Data Handning with Sqlite for Android
 
An introduction to QuerySurge webinar
An introduction to QuerySurge webinarAn introduction to QuerySurge webinar
An introduction to QuerySurge webinar
 
Revision
RevisionRevision
Revision
 
Introduction to SQL Server Analysis services 2008
Introduction to SQL Server Analysis services 2008Introduction to SQL Server Analysis services 2008
Introduction to SQL Server Analysis services 2008
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
 
Taming the shrew Power BI
Taming the shrew Power BITaming the shrew Power BI
Taming the shrew Power BI
 
A Primer To Sybase Iq Development July 13
A Primer To Sybase Iq Development July 13A Primer To Sybase Iq Development July 13
A Primer To Sybase Iq Development July 13
 
Alfresco Business Reporting - Tech Talk Live 20130501
Alfresco Business Reporting - Tech Talk Live 20130501Alfresco Business Reporting - Tech Talk Live 20130501
Alfresco Business Reporting - Tech Talk Live 20130501
 
Where to save my data, for devs!
Where to save my data, for devs!Where to save my data, for devs!
Where to save my data, for devs!
 
Evolutionary Database Design
Evolutionary Database DesignEvolutionary Database Design
Evolutionary Database Design
 
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
Introduction to Azure Data Lake and U-SQL for SQL users (SQL Saturday 635)
 
PI-RDBMS.ppt
PI-RDBMS.pptPI-RDBMS.ppt
PI-RDBMS.ppt
 
Sqlite
SqliteSqlite
Sqlite
 
My sql crashcourse_intro_kdl
My sql crashcourse_intro_kdlMy sql crashcourse_intro_kdl
My sql crashcourse_intro_kdl
 
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
 
Wei's Self Intro
Wei's Self IntroWei's Self Intro
Wei's Self Intro
 

Último

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 

Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) - GDevCon#2

  • 1. Efficient Working with Databases Sam Sharp MediaMongrels Ltd sam@mediamongrels.com
  • 2. WebSockets API • New version (V2.X) coming soon! – New OO-based API – Available on NI Tools Network Client: Server: WSS Support?!
  • 3. Introduction • Considerable amount of LabVIEW & Database exposure: – PHP/MySQL Web Development (4-5 years) – UK Fuel Cell Company • Test Station Monitoring System (~100 Test Stations) • 60s Update Resolution (Test/Asset Status, PC Health) – Swiss Light Source Company • Design & Rollout of Production Test Database (10-15 tables) • TestStand Results Processing Plugin & LabVIEW API • Reporting & Analysis Tool in LabVIEW • Legacy Data Import • Writing VIs to talk to databases in LabVIEW is tedious.
  • 4. Databases Overview • Database Advantages: – Store large amounts of information – Sharing of information • Concurrent multi-user access – Quick access to information – Eliminate duplication of data – Information Security – Backup/Restore • Common DBMS: – Relational • Linked Tables (Rows & Columns) • Examples: MySQL, MS-SQL, Oracle, PostgreSQL, SQLite – NoSQL • Unstructured/Semi-Structured Data • Examples: MongoDB, Redis, Cassandra • LabVIEW <-> Database – Database Connectivity Toolkit – 3rd Party Toolkits (SQLite, GDatabase)
  • 5. Database Toolkit Basics ODBC Drivers MySQL: MySQL ODBC X.X ANSI Driver MS-SQL: SQL Native Client LV 32-bit
  • 6. Best Practice Hints & Tips • Security – Use parameter binding for user input (SQL injection) – Passwords in VIs? – Limit application access to databases by user roles • Performance – Do not repeatedly open/close the connection – Database design… …but what if the username & password is: “ OR “1”=“1 SELECT * FROM operator WHERE username = ““ OR “1”=“1” AND password = ““ OR “1”=“1” Any username/password will grant access! Looks harmless (and I have seen this done in many places!) https://xkcd.com/327/
  • 7. Database Design • Database design is important – Poorly designed database issues: • Poor quality data • Poor performance – Especially when volume of data increases • Redundant data • Poor data integrity • Difficult to extend/improve • Normalisation Principles – 1NF, 2NF, 3NF etc. – Guide good relational database design • Each relation adds complexity – sometimes it is sensible to break to rules. – e.g. execution_id in step_measurement – Storing JSON configuration (for audit purposes only)
  • 8. Question: How long would it take to write code to Create, Read, Update & Delete rows for these five tables?
  • 9.
  • 10. In ~90 seconds* we have: • Configured a database connection • Generated model classes for 5 tables – One model class per table – Columns as model properties – Basic validation (e.g. required fields) • Created a user interface to create, view, update and delete rows from our Operator table … without writing a single SQL query or line of PHP code …leaving more time to develop the ‘meat’** of the application …the joy of frameworks! A prize for anyone that can rewrite as a Haiku! *sequences have been shortened (no lawsuits please!) **or your favourite soy-based substitute
  • 11. Yii PHP Framework • Popular framework for developing web-based applications – PHP & MySQL – Based on Model-View-Controller (MVC) architecture • Model classes represent object/table data (e.g. customer, order) • Views display data to the user • Controllers implement the ‘business logic’ by interacting with the models and preparing the views – Contains tools for auto-generating code from a database schema
  • 12. What if we could do some of this in LabVIEW?
  • 13. ActiveRecord • ActiveRecord implements the Models in Yii’s MVC – ActiveRecord objects contain persistent data and behaviours operating on that data • Class = Table • Object = Row • Properties = Columns • Methods = Behaviours (e.g. create, read, update, delete, business logic) • Purpose: – Representing models and their data – Representing relations between models (e.g. foreign keys) – Validating models – Performing database operations +Insert() +Update() +Delete() +GetByID() +CheckPermission() -id -username -full_name -level Operator
  • 14.
  • 15. In ~150 seconds* we have: • Configured a MySQL connection (ish) • Generated model classes for 5 2 tables – One model class per table – Columns as model properties – Basic validation (e.g. required fields) • Created a user interface VI to create, view, update and delete rows from our Operator Test Execution table … without writing a single SQL query or much LabVIEW code …leaving more time to develop the ‘meat’** of the application …the joy of frameworks! *sequences have been shortened (no lawsuits please!) **or your favourite soy-based substitute
  • 16. Current Features • ActiveRecord base class – Create, Read, Update & Delete of Objects – Automatic creation of model classes using Scripting • Supporting Libraries / Tools – Database Connection Class • Database Connectivity Toolkit – Query Command Library • Builds SQL queries from VIs – Integrated into LV Tools folder
  • 17. Future Functionality • Query Options – FindAll, FindByAttributes etc. • Model Validation • Foreign Key Relations – Test_Execution.Test_Steps • User Interface Binding?

Notas do Editor

  1. Good afternoon, I hope everyone enjoyed their lunch and feel free to use the next half an hour for a nap if you’re feeling a little sleepy. My name is Sam Sharp, I run my own little NI Alliance Partnership, MediaMongrels Ltd, I recently became a LabVIEW Champion (Hooray!) and I am one of the founding members of GDevCon so feel free to come and talk to me if you have any feedback. Today I am going to be talking about communicating with databases in LabVIEW…but first…
  2. Another quick announcement – a new version of my LabVIEW WebSockets API is going to be released soon on the NI Tools Network. It’s the first major update to the library since its release that simplifies the API, fixes some bugs, adds some features and also allows for Secure WebSockets Support in the future. A version for LabVIEW NXG to use with the NXG Web Module will also be coming soon.
  3. OK, so onto my presentation. Most of my career dating back even to school has involved some form of work with databases, whether as a Web Developer writing applications in PHP/MySQL or writing LabVIEW applications that interface with databases. One thing I find when working with databases in LabVIEW is that it is TEDIOUS. Writing VIs to talk to a database with anything more than a few tables takes ages and much of it is repeated work (insert into X, insert into Y etc.). It is a BORING and THANKLESS TASK.
  4. Before I get to the real point of this presentation, I just wanted to give a bit of an introduction to databases over the next few slides. If you need any of the things on the left-hand side of the slide, you should probably put down Excel or your file-based record keeping system and consider using a database. Databases come in different shapes and sizes. Relational: Structured tables with rows and columns defined in a schema. Write queries (SQL) to read, update, delete and create data. Each row has a unique key. NoSQL: Allows unstructured and semi-structured data to be stored/manipulated. Data is stored as ‘documents’ (e.g. JSON in MongoDB), Key-Value pairs (Redis). When it comes to talking to databases in LabVIEW – there’s the built-in database connectivity toolkit and other 3rd party toolkits – such as James Powells excellent SQLite library which he will be talking about after me.
  5. Since the DCT is included in LabVIEW, here’s what a basic database operation in LabVIEW might look like…we open a connection (yes, you can wire different data types here), select some data, convert it to a LabVIEW data type and then close the connection. Depending on the database type you’re talking to, you might need to install some additional drivers and configure your database connection.
  6. Here are a few handy hints & tips to help you build applications that talk to databases in a robust and secure way.
  7. Having a poorly designed database can have a detrimental effect on your business. It can result in poor performance, data loss etc. Fortunately, the normalisation principles are there to help you. The normalisation principles (E.g. 1st normal form, 2nd normal form etc.) are there to help guide the design of your relational database. They are a tool to help you, but it is up to you whether to use them. As each added relation between tables adds complexity to your database design, sometimes it is sensible to break the rules. Here we have added the execution_id to step_measurement to give us a faster way to look up all measurements for a particular test execution.
  8. Ok, now you’re clued up on what a database is, how to design it and then talk to it from LabVIEW, let’s see if we can make our lives easier and remove some of the tedium involved and spend more time writing the interesting parts of our applications? Given our database design from the previous slide, how long it would take to write LabVIEW VIs for these five tables? Anyone want to shout out some guesses? A day? Half a day? A few hours?
  9. What if I said it could be done in 90 seconds? You’ll immediately notice that I’m cheating and this isn’t LabVIEW but here goes… First I configure a database connection to talk to my test database. I can then go to a special link, click the Model Generator and enter an asterix to generate all models, you’ll then see that it has populated a list of all of my database tables. I can preview the file to see the columns in the table and then generate my model files. I can then go back and go into the CRUD generator, configure my Operator controller, generate the files and then go to the URL for my Operator Controller. This has now added a user interface where I can add a new operator, view operators, update an operator and delete them.
  10. This was all done in the Yii Framework, a PHP framework for writing web-based applications. It is based on the Model-View-Controller architecture where Model… View… Controller… It also happens to contain tools for auto-generating the models, views and controllers automatically from a database.
  11. So – what if we could do some of this in LabVIEW?
  12. In the Yii Framework, database models are represented using ActiveRecord classes. AR objects contain persistent data (e.g. stored in a database) and have behaviours acting on that data. An AR class represents a table, an instance/object represents a single row in the table and properties and methods represent table columns and behaviours respectively. The purpose of ActiveRecord is to represent models and their data, relations between models and to perform validation and database operations. On the right you can see the progression from database table, to AR class design, to LabVIEW class to application code using the Operator ActiveRecord class.
  13. So here we are in LabVIEW… First I’m going to open up the ActiveRecord Model Generator…connect to my database and select the Operator table. I want the ‘Level’ field to be an enum so I’ll change that here and then generate the model class. I’m also going to do the same for my Test Execution table. The database data types don’t always match our LabVIEW types so I’m just going to fix a couple of them here before we generate the model. Now in our project folder we have a couple of folders containing our classes which we can then add to our project. The first thing to do is to populate the enum type definitions that have been automatically generated with the values that we want for our Operator Levels and Test Execution status fields. We can now start writing our application – for this demo I’m just going to create a new row in our Test Execution table. So I drop down a new test execution object, set the properties (which are our database columns), add a ‘Save’ VI and then read out the ID of the newly inserted database row just to verify that it worked.