From Clomosy Docs
(Created page with "TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset. TclBlobField encapsulates the basic behavior common to binary large object (BLOB - Binary Large Object) fields. BLOB fields are database fields that contain raw binary data of arbitrary length. BLOB fields can represent different, optionally large data types. These data types are distinguished in the header of the binary data. BLOB fields allow f...") |
ClomosyAdmin (talk | contribs) No edit summary |
||
| (5 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset. | TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset.<br> | ||
TclBlobField encapsulates the basic behavior common to binary large object (BLOB - Binary Large Object) fields. BLOB fields are database fields that contain raw binary data of arbitrary length. BLOB fields can represent different, optionally large data types. These data types are distinguished in the header of the binary data. | TclBlobField encapsulates the basic behavior common to binary large object (BLOB - Binary Large Object) fields. BLOB fields are database fields that contain raw binary data of arbitrary length. BLOB fields can represent different, optionally large data types. These data types are distinguished in the header of the binary data.<br> | ||
BLOB fields allow for the storage of large binary data such as text, images, audio, or video. | BLOB fields allow for the storage of large binary data such as text, images, audio, or video.<br> | ||
<div class="table-responsive"> | |||
{| class="wikitable" style="border: 2px solid #c3d7e0" | {| class="wikitable" style="border: 2px solid #c3d7e0" | ||
! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"|Definition | ! style="background-color: #c3d7e0"| Feature !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition | ||
|- | |- | ||
|TclBlobField|| BlobField : TclBlobField; || A variable belonging to the TclBlobField class is created. | |TclBlobField|| BlobField : TclBlobField; || A variable belonging to the TclBlobField class is created. | ||
|- | |- | ||
|Assigning to object || BlobField = qry.FieldByName('DOCUMENT_FILE') as TclBlobField; || Assigning to a | |Assigning to object || BlobField = qry.FieldByName('DOCUMENT_FILE') as TclBlobField; || Assigning to a TclBlobField object | ||
|- | |- | ||
|SaveToStream ||BlobField.SaveToStream(BlobStream); || Saves BLOB data to a TclMemoryStream or TclFileStream object. | |SaveToStream ||BlobField.SaveToStream(BlobStream); || Saves BLOB data to a TclMemoryStream or TclFileStream object. | ||
|} | |} | ||
</div> | |||
<b>Example</b><br> | |||
This code connects to a SQL Server database, executes a query on a table, and loads image data from a BLOB (Binary Large Object) field. It saves the loaded image data into a stream (TclMemoryStream), then loads this data into a visual component (TclImage) and displays it. Additionally, it copies the image data in Base64 format to the clipboard (setClipBoard).<br> | |||
<pre> | |||
var | |||
Server, User, Password,DB: String; | |||
Port: Integer; | |||
Form1:TCLForm; | |||
qry : TClSqlQuery; | |||
BlobStream: TclMemoryStream; | |||
BlobField: TclBlobField; | |||
Img1 : TclImage; | |||
Base64String: string; | |||
void MainForm; | |||
{ | |||
Form1 = TCLForm.Create(Self); | |||
Img1 = Form1.AddNewImage(Form1,'Img1'); | |||
Img1.Align = alClient; | |||
qry = TClSqlQuery.Create(Nil); | |||
try | |||
try | |||
qry.Connection = Clomosy.DBSQLServerConnection; | |||
qry.Sql.Text = 'SELECT TOP(1) DOC_FILE FROM ATBLDOCS'; | |||
qry.Open; | |||
if (qry.Found) | |||
{ | |||
BlobField = qry.FieldByName('DOC_FILE') as TclBlobField; | |||
BlobStream = TclMemoryStream.Create; | |||
BlobField.SaveToStream(BlobStream); // Load BLOB data into the stream | |||
BlobStream.Position = 0; | |||
Base64String = Clomosy.StreamToBase64(BlobStream); | |||
Clomosy.setClipBoard(Base64String);//FOR TEST PURPOSE COPIES BASE64 | |||
Img1.Bitmap.LoadFromStream(BlobStream); // Load the image from the stream | |||
BlobStream.Free; | |||
} | |||
except | |||
ShowMessage('[019] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage); | |||
} | |||
finally | |||
qry.Free; | |||
} | |||
Form1.Run; | |||
} | |||
{ | |||
try | |||
Server = '192.168.5.13'; | |||
User = 'sa'; | |||
Password = 'aaaa'; | |||
DB = 'ATK23'; | |||
Port = 1433; | |||
Clomosy.EventLog = True; | |||
if not (Clomosy.DBSQLServerConnect('SQL Server', Server, User, Password, DB, Port)) | |||
{ | |||
ShowMessage('DATABASE CONNECT ERROR'); | |||
Exit; | |||
} | |||
MainForm; | |||
except | |||
ShowMessage('Connection Error '+'Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage); | |||
} | |||
} | |||
</pre> | |||
<h2> See Also </h2> | |||
* [[Components]] | |||
* [[TclFileStream]] | * [[TclFileStream]] | ||
* [[TclMemoryStream]] | * [[TclMemoryStream]] | ||
| Line 157: | Line 95: | ||
* [[Base64ToFile]] | * [[Base64ToFile]] | ||
* [[Base64ToStream]] | * [[Base64ToStream]] | ||
{{#seo:|title=TclBlobField Using in Clomosy - Clomosy Docs}} | |||
{{#seo:|description=Learn how to use TclBlobField in Clomosy to handle and manage BLOB data like images, audio, and video from a database, with practical examples.}} | |||
Latest revision as of 15:05, 24 December 2024
TclBlobField represents a field that holds a reference to a binary large object (BLOB - Binary Large Object) in the dataset.
TclBlobField encapsulates the basic behavior common to binary large object (BLOB - Binary Large Object) fields. BLOB fields are database fields that contain raw binary data of arbitrary length. BLOB fields can represent different, optionally large data types. These data types are distinguished in the header of the binary data.
BLOB fields allow for the storage of large binary data such as text, images, audio, or video.
| Feature | Use of | Definition |
|---|---|---|
| TclBlobField | BlobField : TclBlobField; | A variable belonging to the TclBlobField class is created. |
| Assigning to object | BlobField = qry.FieldByName('DOCUMENT_FILE') as TclBlobField; | Assigning to a TclBlobField object |
| SaveToStream | BlobField.SaveToStream(BlobStream); | Saves BLOB data to a TclMemoryStream or TclFileStream object. |
Example
This code connects to a SQL Server database, executes a query on a table, and loads image data from a BLOB (Binary Large Object) field. It saves the loaded image data into a stream (TclMemoryStream), then loads this data into a visual component (TclImage) and displays it. Additionally, it copies the image data in Base64 format to the clipboard (setClipBoard).
var
Server, User, Password,DB: String;
Port: Integer;
Form1:TCLForm;
qry : TClSqlQuery;
BlobStream: TclMemoryStream;
BlobField: TclBlobField;
Img1 : TclImage;
Base64String: string;
void MainForm;
{
Form1 = TCLForm.Create(Self);
Img1 = Form1.AddNewImage(Form1,'Img1');
Img1.Align = alClient;
qry = TClSqlQuery.Create(Nil);
try
try
qry.Connection = Clomosy.DBSQLServerConnection;
qry.Sql.Text = 'SELECT TOP(1) DOC_FILE FROM ATBLDOCS';
qry.Open;
if (qry.Found)
{
BlobField = qry.FieldByName('DOC_FILE') as TclBlobField;
BlobStream = TclMemoryStream.Create;
BlobField.SaveToStream(BlobStream); // Load BLOB data into the stream
BlobStream.Position = 0;
Base64String = Clomosy.StreamToBase64(BlobStream);
Clomosy.setClipBoard(Base64String);//FOR TEST PURPOSE COPIES BASE64
Img1.Bitmap.LoadFromStream(BlobStream); // Load the image from the stream
BlobStream.Free;
}
except
ShowMessage('[019] Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
finally
qry.Free;
}
Form1.Run;
}
{
try
Server = '192.168.5.13';
User = 'sa';
Password = 'aaaa';
DB = 'ATK23';
Port = 1433;
Clomosy.EventLog = True;
if not (Clomosy.DBSQLServerConnect('SQL Server', Server, User, Password, DB, Port))
{
ShowMessage('DATABASE CONNECT ERROR');
Exit;
}
MainForm;
except
ShowMessage('Connection Error '+'Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
}
}