How can I store images in a database? _ MySQL

Source: Internet
Author: User
If you are using an sqlserver database! You don't want to use background operations. you can see the following operations on text. write operation (WRITETEXT) here, the commonly used function is TextPtr to obtain the pointer of the text field, and TextVaild to verify the validity of the pointer, @ RowCount to determine the number of records returned. The basic method is: use the Textptr function if you are using the SQL server database! You don't want to use background operations. you can check this
The following are the operations on text.
1. write operation (WRITETEXT)
Generally, TextPtr is used to obtain the pointer of a text field, and TextVaild is used to verify the validity of the pointer. @ RowCount is used to determine the number of records returned.
The basic method is to use the Textptr function to obtain the pointer, determine its validity, and write data with Writetext.
Function description: Textptr (field name ). Writetext tablename. Fieldname @ textptr (pointer) [With Log] data (data)
For example:
Begin Tran
Declare @ Mytextptr VarBinary (16)
Select @ mytextptr = textptr (pr_info)
From Pub_Info (updlock)
Where pud_id = '20140901'
IF @ Mytextptr Is Not Null
Writetext pub_info.pr_info @ mytextptr with log 'data'
Commit Tran
2. read operations
Common functions
PatIndex ('% exp %', var | fieldname ..)
Datalength ()
@ TextSize text size
SettextSize N set the text size
ReadText {TableName. FieldName }{@ textptr} Offet Size [HoldLock]
For example:
Begin tran
Declare @ mytextptr Varbinary (16), @ Totalsize int, @ Readsize int, @ lastread int
Set textsize 100
Select @ mytextptr = textptr (pr_info), @ totalsize = datalength (pr_info)
@ Lastread = 0,
@ Readsize = case when (textsize Eles datalength (pr_info)
End
From Pub_info
Where Pub_id = '20140901'
IF @ mytextptr Is not Null and @ readsize> 0
While (@ lastread <@ totalsize)
ReadText pub_info.pr_info @ mytextptr @ lastread @ readsize holdlock
If (@ error <> 0)
Break
Select @ lastread = @ lastread @ readsize
If (@ readsize @ lastread)> @ totalsize)
Select @ readsize = @ totalsize-@ lastread
End
Commit Tran
3. UpdateText
The update data replaces the write operation. the basic syntax is:
UpdateText Table_Name.Col_Name Text_Ptr Offest (offset) Deleted_Length
[With Log] [Inserted_Data | Table_Name.Scr_Column_name Str_Text_Ptr]
Note:
Offest: 0 indicates starting from the beginning. Null indicates that you append data to the current content.
Deleted_Length: 0 indicates that no content is deleted, and Null indicates that all content is deleted.
For example, 1 (completely replaced ):
Declare @ mytextptr varbinary (16)
Begin tran
Select @ mytextptr = textptr (pr_infro) from pub_info (uplock) where pub_id = '201312'
If @ mytextptr is not null
Updatetext pub_info.pr_infro @ mytextptr 0 null with log "you are right"
Commit
Example 2:
Declare @ mytextptr varbinary (16), @ offest int
Begin tran
Select @ mytextptr = textptr (pr_infro), @ offest = patindex ('% D.C %', pr_infro)-1 4
/* Minus one because there is a correction offset, and adding 4 is because D. C. is 4 */
From pub_info (unlock) where pub_id = '201312'
If @ mytextptr is not null and @ offest> = 0
Updatetext pub_info.pr_infro @ mytextptr @ offest null with log
Commit tran
Example 3:
Text appending
Append the content of publisher pub_id = 9952 to the text of publisher Pub_id = 0877d.
Delcare @ source_textptr varbinary (16), @ target_textptr varbinary (16)
Begin tran
Select @ source_textptr = textptr (pr_infro) from pub_info (uplock) where pub_id = '201312'
Select @ target_textptr = textptr (pr_infro) from pub_info (uplock) where pub_id = '201312'
If @ source_textptr Is not null and @ target I s not null
Updatetext pub_info.pr_infro @ target_textptr null
With log pub_info.pr_infro @ source_textptr

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.