Delphi processing SQL Server Multimedia data

Source: Internet
Author: User

The author has been involved in the development of a set of highway toll system, the main function is to record all the vehicles through the toll station information, including time, model, amount, vehicle picture information, which involves the processing of multimedia data. The following author will mainly rely on the flow of Delphi data types to do for everyone to explain.

First, select the database

1. Problem

Common desktop databases, such as Access, Visual FoxPro, and so on, are simple to use, and can manage multimedia information. However, because the database engine is not strong enough, in the management of a small number of multimedia data fashion can be normal operation, when the amount of data to a certain extent, the response of the database will become unusually slow, and its performance has been greatly reduced. At a certain critical point, there will even be a database processing capacity and the amount of data to be processed seriously imbalance, and lead to the appearance of suspended animation. The author has had such experience, with Visual Fox Pro to manage the 10,000 students photo files and school information, at this time to make inquiries must be a long wait, and finally have to give up.

2. To govern the "standard"

Use some techniques to speed up the operation of the system, such as the "piecemeal" approach. Large data scattered to a large number of data tables, although it can effectively improve the speed of the database, but too many levels make inquiries, statistics and so become very inconvenient, and programming complexity and workload will also increase dramatically.

Another common method is to save the multimedia data as a separate file, storing only the path and filename of the files in the database, thus avoiding storing the massive data directly into the database. This method of reducing the weight of the database can be used in any database, the versatility is good, and the performance of the promotion is also considerable, is a widely used in the treatment of "standard" method. However, this method also has obvious disadvantages: complex structure, inconvenient maintenance, poor security, not to show the advantages of the database. In the case of student status management, using this method to manage the photo data of 10,000 or more students, the procedure is very complex, maintenance is very difficult, still not to govern "this" policy.

3. Governing "This"

In fact, to deal with a large number of multimedia data, and then advanced Desktop database will be stretched, the author finally adopted an enterprise-class database. Enterprise-class databases, represented by SQL Server, Sybase, Oracle, and so on, have more powerful performance, better data management, more reliable security features, and better network capabilities that are capable of very complex and massive data management tasks, and they also provide rich data types, and an engine optimized for multimedia management. Considering the overall performance, price and other factors, we finally chose the SQL Server 2000 Standard Edition as the system's background database.

Second, how to deal with multimedia data

1. Storage of multimedia data

Multimedia information includes images, sounds and video, which exist in the form of binary data sets, and the objects processed in this system are images. SQL Server provides an image data type to store variable-length binary data (size range is 0~2GB). However, the image field does not load the multimedia data directly, and you must pass some intermediate steps to save the data. Below the image data storage as an example, to introduce how to implement these intermediate steps in Delphi.

The Tstream data type in Delphi stores character or non character data in the form of a stream, like a temporary buffer with a variable size in memory. It can not only easily read and write to the external file, but also the flow of all the data directly into the database, so use it as a bridge to complete the data into the work is very appropriate.

The function of the following savetoimage function is to deposit tstream data into the image field of the datasheet.

function SavetoImage(const Stream:TStream;const AField:TField):boolean;
var
FieldStr:string;
PFieldStr:PChar;
begin
Result:=false;
if (Assigned(AField)) and (Assigned(Stream)) then
begin
try
Stream.Seek(0,0);
SetLength(FieldStr,Stream.Size);
PFieldStr:=PChar(FieldStr);
Stream.Read(PFieldStr^,Stream.Size);
AField.Value:=FieldStr;
Result:=true;
except
end;
end;
end;

The following is a program fragment that calls the Savetoimage function to complete the image data store.

Var
FS:TFileStream;
begin
FS:=TFileStream.Create('C:\Car001.jpg',fmOpenRead);
SavetoImage(FS,Adodataset1.FieldBy
Name('st_img'));
FS.Free;
end;

Where Adodataset1 is the ADO dataset control that connects to the database, st_img is the image field.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.