C++DatabaseGeneric ProgrammingLearn C++

How To Query Databases Using SQL And C++ Builder

Learn to run powerful SQL queries using C++ Builder


C++ Builder is a great developer tool which is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs. There is a free C++ Builder Community Edition for students, beginners and startups.

You can easily access almost every type of database with C++ Builder

In our previous posts, we have described well how to connect to Interbase, PostgreSQL databases with FireDAC component that comes with RAD Studio officially, and how to connect to MySQL with FireDAC and MyDAC components. You can easily connect and query fields and values by using SQL queries. In C++ Builder, in professional applications we should make each query simple and detailed for the user benefits. So they can choice more details, they can filter their query or they can add their own SQL commands. Generally, in most applications users are far from knowing about SQL commands, thus developer should add more functionality to his application that filter in accordance with the database files and with the user needs from that application. You can check our DATABASE section for mode details about connections and databases.

An example SQL query C++ application

In this post we will develop a simple application that can do more detailed SQL queries. To do this first you should know well about each components, some components may have database components that can be used with bindings.

In our example we will not connect to a database but we will show the query text. So you can use our previous database examples to connect a database and you can add these example features to your applications to query by using components. As seen Form example below, we have a Data Table and Sub Data Table, we have a Text Search, Line Limits, Dates Begins and Ends also a checkbox for this date checking. And we have a Button to get SQL with these options from the componenets and a Memo to see this query.

How To Query Databases Using SQL And C++ Builder - SQL example on a form

This SQL Query can be obtained from these components as below in this Button1Click(),

This example is a very simple example with a second database join and some text to search, with some date formats. Note that limiting is very important, you should arrange this limit, or let the user limit. I recommend you 25, 50, 100 line limit for international connections, national and local queries can be 500 or 1000 queries as default, more than this should be an option but warn that query may take a time. Also don’t forget to add Zzz icon to mouse or to your application that shows SQL query is in execution. Set it normal when data received from the database.

Working directly with SQL

At the end of these lines instead of printing this SQL, you can directly add this SQL to your database query and use Execute() command as below,


Please check our DATABASE section for more information about database connections, and more.

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
Artificial Intelligence TechC++C++11C++14C++17Learn C++

Why You Should Know ELU Artificial Neural Net Functions

Artificial Intelligence TechC++C++11C++14C++17Learn C++

What You Need To Know About C++ Gaussian Error Linear Units

C++C++11C++14C++17Learn C++

What Is The SoftPlus Activation Function in C++ Neural Nets?

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Make AI Binary/Heaviside Step Functions In C++

en_USEnglish