How can I store images in a database ?. If you are using an sqlserver database! If you do not want to use background operations, you can see the following operations on text. you can see 1. write operation (WRITETEXT). the general functions are used here. 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.
Login server database! If you don't want to use background operations, you can see the following operations on text. you can see 1. write operation (WRITETEXT) the commonly used function here...