InterBase is a powerful database developed and supported by Idera / Embarcadero, it has a zero-administration, small-footprint database engine that can power your server and even run on your mobile devices as an embedded database. The InterBase 2020 release adds a number of new features, including tablespaces support for InterBase, allowing for better performance on servers with multiple data-storage options. InterBase 2020 is an ultrafast, scalable, embeddable SQL database with commercial grade data security, disaster recovery, and change synchronization abilities.
If you are asking how i can setup Interbase, we explained well before, please check How to Setup a Simple InterBase Database.
In this post, we will connect to this database and the tables created. So your database and table should be the same as explained before or you should arrange some variables in codes given below according to your database setup.
To use the InterBase database be sure that it is installed before or you can install it from Tools -> Manage Platforms -> Additional Options Tab. Both IBX Components and InterBase 2020 Developer Editions should be checked. The Latest InterBase installation is explained well here if you need more details.
Now let’s create a simple database connection application.
- Create a new C++ Builder VCL or FMX Application
- Save all units and project files to a new folder
- Drag a Button (TButton) and a DBGrid (TDBGrid) from Tools Palette to Form design (Form1)
- Drag IBDatabase (TIBDatabase) to Form design to connect Interbase database,
- Drag IBDataSet (TIBDataSet) to Form design to connect to a table of this database with SQL commands,
- and Drag DataSource (TDataSource) to Form design to use DataSet as a DataSource in other components, bindings, etc.
- Arrange your design as shown below,
8. Double click to IBDatabase1 component that you placed on the Form to establish connection properties as below,
Here,
– Enter database local location file or select Remote to connect remote IP address.
– Add User Name and Password, Character Set that you use
– and Pres OK with Login Prompt is checked.
You can check your connection by checking the Connected Property of IBDatabase Connection. If you have a problem check the settings above or check your database settings by using IBConsole. You may need to read details about How to Setup a Simple InterBase Database post or the official InterBase Get Started Guide here.
9. To connect a table in this database, select IBDataSet1 component and set Database property to IBDatabase1,
10. Double click to SelectSQL property of IBDataSet1, in this window Command Text Editor select table that you want to connect and write SQL your command, i.e. “select * from table1”,
11. Select DataSource1, and set its DataSet property to DataSet1,
12. Select DBGrid1 and set DataSource Property of Grid1 to DataSource1. So, briefly we build connections between IBDataBase1 -> IBDataSet1 -> IBDataSource1 -> DBGrid1
13. Be sure that you Connected property of IBDatabase is false, to connect manually double click to Button and add lines as below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void __fastcall TForm1::Button1Click(TObject *Sender) { IBDatabase1->Connected=true; if(IBDatabase1->Connected) { IBDataSet->Active=true; if(IBDataSet->Active) ShowMessage( L"Interbase Database and Table connection is Established" ); else ShowMessage( L"Error to connect Table" ); } else ShowMessage( L"Error to connect Interbase Database" ); } |
14. You can also add queries to IBDataSet as below
1 2 3 4 5 6 7 8 |
void __fastcall TForm1::Button2Click(TObject *Sender) { IBDataSet->SelectSQL->Clear(); IBDataSet->SelectSQL->Add("Select * from table1"); IBDataSet->Execute(); } |
This is a very basic connection example, you can find more details officially here, on the docwiki about IBDatabase here and about IBDataSet here