From Clomosy Docs
Clomosy supports cloud technologies to meet the needs of modern application development. Users can leverage various cloud database technologies to deliver dynamic and real-time data within their applications. With Clomosy, it is possible to connect to commonly used cloud databases via API services. Example databases include:
Firebase is a cloud-based NoSQL database offered by Google that provides real-time data synchronization.
MongoDB is an open-source NoSQL database that works with flexible, JSON-like documents.
MySQL is a widely used open-source database management system based on relational data structure.
PostgreSQL is an advanced open-source relational database system that offers strong support for complex queries.
Azure SQL
Azure SQL is a scalable, managed relational database service provided by Microsoft in the cloud environment.
This enables data to be retrieved from external sources, updated, and allows applications to work in integration with external systems. Clomosy’s flexible infrastructure makes it possible to develop custom solutions tailored to different project needs.
Example - Microsoft Azure SQL Database / SELECT
By connecting to a SQL Server database hosted on Azure, the category names from the specified table are listed. The application displays the data to the user through a ListView component placed on the form.
To create your own database and table, you first need to create a Microsoft Azure SQL Database account. After creating the account, you can easily connect to SQL Server and create your database and necessary tables. By following the steps below, you can create your Azure account and start working with SQL Database.
For more information about Azure SQL Database and to create your account, you can visit the Microsoft Azure SQL Database website.
Var
MyForm:TclForm;
testListview : TClListView;
selectQuery : TClSqlQuery;
void AddDataToListview
{
try
selectQuery.SQL.Text = 'SELECT Name as MAIN_TEXT from SalesLT.ProductCategory';
selectQuery.Open;
if (selectQuery.Found)
{
testListview.clLoadListViewDataFromDataset(selectQuery);
}
else
{
ShowMessage('No record found!');
}
finally
selectQuery.Free;
selectQuery.Close;
}
}
{
MyForm = TclForm.Create(Self);
testListview = MyForm.AddNewListView(MyForm,'testListview');
testListview.Align = alClient;
selectQuery = TClSqlQuery.Create(nil);
Clomosy.DBSQLServerConnect('SQL Server', 'clomosy.database.windows.net', 'Clomosy', '1234abc.', 'ClomosyDatabase', 1433);
selectQuery.Connection = Clomosy.DBSQLServerConnection;
AddDataToListview;
MyForm.Run;
}
Example - Microsoft Azure SQL Database / INSERT
In this example, a connection is established to a SQL Server database hosted on Azure, and category information entered by the user is inserted into the database. The application consists of a simple form interface with two text boxes and a button. After the user enters the category ID and name, they click the "Insert" button. This triggers an operation that attempts to insert the entered data into the database using the INSERT INTO command. If an error occurs during the connection or query execution, the user is shown the exception class and message. If the insertion is successful, a message is displayed to inform the user that the operation was completed successfully.
To create your own database and table, you first need to create a Microsoft Azure SQL Database account. After creating the account, you can easily connect to SQL Server and create your database and necessary tables. By following the steps below, you can create your Azure account and start working with SQL Database.
For more information about Azure SQL Database and to create your account, you can visit the Microsoft Azure SQL Database website.
var
MyForm : TclForm;
edtCategoryID, edtName : TclEdit;
btnInsert : TclButton;
insertQuery : TclSqlQuery;
void InsertToDatabase;
{
try
Clomosy.DBSQLServerQuery.Sql.Text = 'INSERT INTO Category (CategoryID, Name) VALUES ('+edtCategoryID.Text+', '+QuotedStr(edtName.Text)+');';
Clomosy.DBSQLServerQuery.ExecSql;
ShowMessage('Adding data successful');
except
ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
}
}
{
MyForm = TclForm.Create(Self);
edtCategoryID = MyForm.AddNewEdit(MyForm, 'edtCategoryID', 'CategoryID');
edtCategoryID.Margins.Right = 150;
edtName = MyForm.AddNewEdit(MyForm, 'edtName', 'Name');
edtName.Margins.Left = 150;
btnInsert = MyForm.AddNewButton(MyForm,'btnInsert', 'Insert');
btnInsert.Align = alBottom;
MyForm.AddNewEvent(btnInsert, tbeOnClick, 'InsertToDatabase');
insertQuery = TclSqlQuery.Create(nil);
Clomosy.DBSQLServerConnect('SQL Server', 'clomosy.database.windows.net', 'Clomosy', '1234abc.', 'ClomosyDatabase', 1433);
insertQuery.Connection = Clomosy.DBSQLServerConnection;
MyForm.Run;
}
Example - Microsoft Azure SQL Database / UPDATE
The product's list price (ListPrice) is updated based on the product ID (ProductID) entered by the user, by connecting to a SQL Server database hosted on Azure.
To create your own database and table, you first need to create a Microsoft Azure SQL Database account. After creating the account, you can easily connect to SQL Server and create your database and necessary tables. By following the steps below, you can create your Azure account and start working with SQL Database.
For more information about Azure SQL Database and to create your account, you can visit the Microsoft Azure SQL Database website.
var
MyForm : TclForm;
edtProductID, edtListPrice : TclEdit;
btnUpdate : TclButton;
updateQuery : TclSqlQuery;
void UpdateFromDatabase;
{
try
updateQuery.Sql.Text = 'UPDATE SalesLT.Product SET ListPrice = ' +edtListPrice.Text+ 'WHERE ProductID = ' +edtProductID.Text;
updateQuery.ExecSql;
ShowMessage('Data update successful.');
except
ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
}
}
{
MyForm = TclForm.Create(Self);
edtProductID = MyForm.AddNewEdit(MyForm, 'edtProductID', 'ProductID');
edtProductID.Margins.Right = 150;
edtListPrice = MyForm.AddNewEdit(MyForm, 'edtListPrice', 'New ListPrice');
edtListPrice.Margins.Left = 150;
btnUpdate = MyForm.AddNewButton(MyForm,'btnUpdate', 'Update');
btnUpdate.Align = alBottom;
MyForm.AddNewEvent(btnUpdate, tbeOnClick, 'UpdateFromDatabase');
updateQuery = TclSqlQuery.Create(nil);
Clomosy.DBSQLServerConnect('SQL Server', 'clomosy.database.windows.net', 'Clomosy', '1234abc.', 'ClomosyDatabase', 1433);
updateQuery.Connection = Clomosy.DBSQLServerConnection;
MyForm.Run;
}
Example - Microsoft Azure SQL Database / DELETE
By connecting to a SQL Server database hosted on Azure, the data in the Category table is listed, and the record selected by the user can be deleted.
To create your own database and table, you first need to create a Microsoft Azure SQL Database account. After creating the account, you can easily connect to SQL Server and create your database and necessary tables. By following the steps below, you can create your Azure account and start working with SQL Database.
For more information about Azure SQL Database and to create your account, you can visit the Microsoft Azure SQL Database website.
Var
MyForm:TclForm;
testListview : TClListView;
deleteBtn : TCLButton;
query : TClSqlQuery;
void GetData;
{
try
query.SQL.Text = 'SELECT CategoryID as RECORD_GUID, Name as MAIN_TEXT from Category';
query.Open;
testListview.clLoadListViewDataFromDataset(query);
finally
query.Close;
}
}
void DeleteFromListView;
{
try
query.Sql.Text = 'DELETE Category WHERE CategoryID =' +testListview.clSelectedItemData('RECORD_GUID');
query.ExecSql;
ShowMessage('Data deletion successful.');
GetData;
finally
query.Close;
}
}
{
MyForm = TclForm.Create(Self);
testListview = MyForm.AddNewListView(MyForm,'testListview');
testListview.Align = alClient;
deleteBtn = MyForm.AddNewButton(MyForm,'deleteBtn', 'Delete');
deleteBtn.Align = alBottom;
MyForm.AddNewEvent(deleteBtn,tbeOnClick,'DeleteFromListView');
query = TClSqlQuery.Create(nil);
Clomosy.DBSQLServerConnect('SQL Server', 'clomosy.database.windows.net', 'Clomosy', '1234abc.', 'ClomosyDatabase', 1433);
query.Connection = Clomosy.DBSQLServerConnection;
GetData;
MyForm.Run;
}
Example - Firebase Database / GET-POST
Before performing data insertion (POST) or retrieval (GET) operations on Firebase, users must first visit the Firebase Console and create a project. Once the project is created, the database service should be enabled using Realtime Database. In addition, properly configuring the database rules is crucial for ensuring data security and access permissions. Otherwise, unauthorized access or operation errors may occur. If these steps are not completed, attempting to perform data operations directly may result in your application not functioning as expected.
GET - Reading Data
In the example, when sending an HTTP request for the GET operation, you should replace the PROJECT_ID with your Firebase project’s unique ID. This ID is a unique identifier for the project you created in the Firebase Console.
Additionally, the "europe-west1" part of the URL refers to the data center Firebase is using. Firebase has data centers located in various regions worldwide, and the "europe-west1" region refers to one of the data centers in Europe. This part indicates the geographical region where your data is stored and where the servers are located.
https://[PROJECT_ID].firebaseio.com/Fruits.json
You can replace the PROJECT_ID in the URL above with your own Firebase project ID to retrieve your data. For instance, if your database is located in the "europe-west1" region, your connection URL may look like:
https://fruits-1111z-default-rtdb.europe-west1.firebasedatabase.app/Fruits.json
When you store data like Fruits in your database, you can correctly customize the URL to perform data retrieval.
POST - Pushing Data
POST is used to send data to the server, typically to create or update resources.
For example, in Firebase, you can use the POST method to add new data to your Realtime Database. Below is how you would use POST to add a new fruit with the name "Apple" and the color "Red" to the Fruits node in your Firebase database:
BaseURL:
https://fruits-1111z-default-rtdb.europe-west1.firebasedatabase.app/Fruits.json
Body:
{"name": "Apple","color": "Red"}
This POST request sends the data to the Firebase Realtime Database under the Fruits node, creating a new entry with the specified name and color.
You can visit the Firebase Realtime Database REST API documentation page to learn in detail about reading and writing data in your Firebase database and adapt it to your application. This page contains comprehensive explanations along with examples of how to perform GET (data reading) and POST operations.
Example Code:
var
mainForm:TCLForm;
BtnSend : TclButton;
RestClient: TclRest;
MemoDB : TclMemo;
Combo1 : TClComboBox;
PnlFruits : TclPanel;
LblFruitCaption : TclLabel;
EdtFruitName,EdtFruitColor : TclEdit;
IsGetRequest : Boolean;
void CompletedProc;
{
MemoDB.Lines.Clear;
MemoDB.Lines.Add(RestClient.Response);
RestClient.Free;
RestClient = Nil;
}
void SendRequest(AMethod,AURL,ABody);
{
RestClient = TclRest.Create;
try
try
RestClient.Accept = 'application/json';
RestClient.ContentType = 'application/json';
RestClient.ConnectTimeOut = 60000;
RestClient.BaseURL = AURL;
if (ABody <> '')
RestClient.Body = ABody;
RestClient.Method = AMethod;
RestClient.OnCompleted = 'CompletedProc';
RestClient.ExecuteAsync;
except
ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
finally
}
}
void GetRequest;
{
if (IsGetRequest)
SendRequest(rmGet,'https://fruits-1111z-default-rtdb.europe-west1.firebasedatabase.app/Fruits.json','');
else
{
if ((EdtFruitName.Text == '') && (EdtFruitColor.Text == ''))
{
ShowMessage('Post işlemi gerçekleşmedi. Lütfen meyvenin adını ve rengini giriniz.');
}
else
{
SendRequest(rmPost,'https://fruits-1111z-default-rtdb.europe-west1.firebasedatabase.app/Fruits.json','{"name": "'+EdtFruitName.Text+'", "color": "'+EdtFruitColor.Text+'"}');
}
}
}
void ComboSelected;
var
strValue,strKey,strKey2 : String;
{
if (Combo1.GetValueIndex(Combo1.ItemIndex) == '1')
{
IsGetRequest = True;
BtnSend.Text = 'GET';
PnlFruits.Visible = False;
}
else if (Combo1.GetValueIndex(Combo1.ItemIndex) == '2')
{
IsGetRequest = False;
BtnSend.Text = 'POST';
PnlFruits.Visible = True;
}
}
{
mainForm = TCLForm.Create(Self);
IsGetRequest = True;
Combo1 = mainForm.AddNewComboBox(mainForm,'Combo1');
Combo1.Align = alMostTop;
Combo1.Height = 50;
Combo1.Margins.Top=10;
Combo1.Margins.Left =mainForm.clWidth/6;
Combo1.Margins.Right =mainForm.clWidth/6;
Combo1.AddItem('GET','1');
Combo1.AddItem('POST','2');
mainForm.AddNewEvent(Combo1,tbeOnChange,'ComboSelected');
PnlFruits = mainForm.AddNewPanel(mainForm,'PnlFruits');
PnlFruits.ALign = alMostTop;
PnlFruits.Height = mainForm.clHeight/4;
PnlFruits.Margins.Top=10;
PnlFruits.Margins.Left =10;
PnlFruits.Margins.Right =10;
PnlFruits.Margins.Bottom =10;
PnlFruits.Visible = False;
LblFruitCaption= mainForm.AddNewLabel(PnlFruits,'LblFruitCaption','Add New Fruits');
LblFruitCaption.Align = alMostTop;
LblFruitCaption.Height = PnlFruits.Height / 4 ;
LblFruitCaption.StyledSettings = ssFamily;
LblFruitCaption.TextSettings.Font.Size=14;
EdtFruitName= mainForm.AddNewEdit(PnlFruits,'EdtFruitName','Fruit Name...');
EdtFruitName.Align = alMostTop;
EdtFruitName.Margins.Top= 10;
EdtFruitName.Height = PnlFruits.Height / 4 ;
EdtFruitColor= mainForm.AddNewEdit(PnlFruits,'EdtFruitColor','Fruit Color...');
EdtFruitColor.Align = alMostTop;
EdtFruitColor.Margins.Top= 10;
EdtFruitColor.Height = PnlFruits.Height / 4 ;
BtnSend = mainForm.AddNewButton(mainForm,'BtnSend','GET');
BtnSend.ALign = alTop;
BtnSend.Height = 50;
BtnSend.Margins.Top= 10;
BtnSend.Margins.Left = mainForm.clWidth / 4;
BtnSend.Margins.Right = mainForm.clWidth / 4;
mainForm.AddNewEvent(BtnSend,tbeOnClick,'GetRequest');
MemoDB = mainForm.AddNewMemo(mainForm,'MemoDB','---');
MemoDB.ALign = alBottom;
MemoDB.Margins.Top = 10;
MemoDB.Height = (mainForm.clHeight / 3);
MemoDB.WordWrap = True;
mainForm.Run;
}
See Also