This article introduces the storage mechanism and access method of image data by mis SQL Server. For VB development tools, this paper introduces a method to access image data in mis SQL Server through the GetChunk method and AppendChunk method of ADO Field object.
In a complete Hospital Information MIS, image data access is essential, such as the preservation of X-ray images and CT images. On the one hand, these image data provides an important basis for accurate diagnosis of illness in remote diagnosis and treatment, on the other hand, it also provides basic conditions for quick access to patient data. Image Data Access is also widely used in other application systems, such as GIS.
1. Storage Mechanism of image data in SQL Server
In mis SQL Server, image data smaller than 8000 bytes can be expressed in binary (binary, varbinary. However, some medical image images to be saved are usually larger than 8000 bytes. SQL Server provides a mechanism to store binary objects (BLOB) up to 2 GB in each row. Such objects can include three data types: image, text, and ntext. The Image data type stores binary data. The maximum length is 231-1 (2,147,483,647) bytes.
BLOB data is stored in the mis SQL Server System in a different way than normal data types. For normal data systems, data values are stored directly on user-defined fields. For BLOB data, the system opens a new storage page to store the data. The BLOB data field in the table is only a 16-byte pointer, which points to the page where the BLOB data of the record is stored.
2. Access to image data in SQL Server
In mis SQL Server, when data is smaller than 8000 bytes, you can use common SQL statements (SELECT, INSERT, UPDATE, and DELETE) to manipulate fields, when the data exceeds 8000 bytes, SQL provides the WRITETEXT, READTEXT, and UPDATETEXT functions to read and modify data. The three functions are used as follows:
(1) WRITETEXT {table. column text_ptr} [with log] {data}
Table. column is the field in the table, text_ptr is a 16-byte pointer, and data is the data value to be written. The optional parameter with log indicates whether to write data to the LOG file.
Example:
DECLARE @ ptrval binary (16) -- pointer SELECT @ ptrval = TEXTPTR (img_ct) FROM zy_ct WHERE id_ct = 20010101001 WRITETEXT zy_ct.img_ct @ ptrval 0x024324142342134214213421421454353452341
|
(2) READTEXT {table. column text_ptr offset size} [HOLDLOCK]
Table. column is the field in the table, text_ptr is a 16-byte pointer, offset is the offset, that is, the number of bytes to read from the beginning, size is the number of bytes to read, HOLDLOCK indicates whether to allow other users to modify the read data.
Example:
DECLARE @ptrval varbinary(16)SELECT @ptrval = TEXTPTR(img_ct) FROM zy_ct WHERE id_ct = 20010101001READTEXT zy_ct.img_ct @ptrval 1 25
|
(3) UPDATETEXT
{table_name.dest_column_name dest_text_ptr}{NULL|insert_offset}{ NULL | delete_length}[WITH LOG][ inserted_data| {table_name.src_column_name src_text_ptr}]
|
Table_name.dest_column_name is the text, ntext, or image field to be modified; dest_text_ptr is the pointer to it; insert_offset is the offset. For text and image, it is written starting from the nth byte, ntext is written starting from the nth character (double byte); delete_length is the byte (character) of delete_length deleted from insert_offset. If it is 0, it is not deleted, if it is NULL, all data starting from insert_offset and ending is deleted. The data to be inserted is inserted_data, but the data indicated by the src_text_ptr pointer in the src_column_name field of table_name.
Example:
DECLARE @ptrval binary(16)SELECT @ptrval = TEXTPTR(img_ct) FROM zy_ct WHERE id_ct = 20010101001UPDATETEXT zy_ct.img_ct @ptrval 16 0x54345
|
It can be seen that the use of these three functions is complicated. Although the storage process can be generated to call and execute, one drawback is that when reading data, the data read by the READTEXT function cannot be directly transmitted back to the front-end application.
| [Content navigation] |
| Page 1: storage mechanism and Image Data Access |
Page 2nd: Access to image data in VB 6.0 |