var
MyForm : TclForm;
Qry : TClSQLiteQuery;
productPriceArr : TClArrayString;
void SqLiteInsertData;
{
try
Clomosy.DBSQLiteQuery.Sql.Text = '
INSERT INTO Products (productId, productName, productPrice) VALUES (1, ''Iphone 11'', ''18000.00'');
INSERT INTO Products (productId, productName, productPrice) VALUES (2, ''Xiaomi Redmi Note 11 Pro'', ''15000.50'');
INSERT INTO Products (productId, productName, productPrice) VALUES (3, ''Omix X600'', ''20000.75'');
INSERT INTO Products (productId, productName, productPrice) VALUES (4, ''Huawei Nova Y70'', ''25000.00'');
INSERT INTO Products (productId, productName, productPrice) VALUES (5, ''Samsung Galaxy S20'', ''30000.25'');
INSERT INTO Products (productId, productName, productPrice) VALUES (6, ''Iphone 14 Pro Max'', ''50000.25'');';
Clomosy.DBSQLiteQuery.OpenOrExecute;
ShowMessage('Adding data to the table was successful!');
except
ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
}
void SqLiteConnectionCreateTable;
var
TableExists: Boolean;
{
try
Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
// Check if the table exists
Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Products";';
Clomosy.DBSQLiteQuery.OpenOrExecute;
// Check the results
TableExists = not Clomosy.DBSQLiteQuery.Eof;
// Create the table if it does not exist
if not (TableExists)
{
Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE Products(productId INTEGER NOT NULL,
productName TEXT NOT NULL,
productPrice TEXT NOT NULL)';
Clomosy.DBSQLiteQuery.OpenOrExecute;
ShowMessage('Table successfully added to the database!');
SqLiteInsertData;
} else
{
ShowMessage('The Products table already exists.');
}
except
ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
}
void getArr;
var
iIndex : Integer;
{
for (iIndex = 0 to productPriceArr.Count-1)
{
ShowMessage('productPrice: '+IntToStr(productPriceArr.GetItem(iIndex)));
}
}
void GetData;
{
try
Qry = Clomosy.DBSQLiteQueryWith('SELECT productId, productName, productPrice FROM Products');
Qry.OpenOrExecute;
Qry.First;
while (not Qry.EOF)
{
productPriceArr.Add(Qry.FieldByName('productPrice').AsString);
Qry.Next;
}
getArr;
except
ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
}
}
{
MyForm = TclForm.Create(Self);
productPriceArr = TClArrayString.Create;
SqLiteConnectionCreateTable;
GetData;
MyForm.Run;
}