Home > database >  All kinds of files stored in the Ms SQL Server in the database error...
All kinds of files stored in the Ms SQL Server in the database error...

Time:09-23

MS Sql server data can be Blob fields for the image type, the file after reading, write a database Blob field size is only 32767 bytes, but I everything is all right in the Sybase Sql database, in MS Sql server is to write incomplete, Sql 2000200 8 are tried, is for this reason that I read the file write data code is as follows, please tell master:
String ls_pathname, ls_filename
Integer li_value li_FileNum, loops, I
Long ll_fileLength bytes_read, new_pos
Blob, b tot_b
Blob gb_photo
String ls_id

Li_value=https://bbs.csdn.net/topics/GetFileOpenName (" choose photo ", ls_pathname, ls_filename)//
IF li_value=https://bbs.csdn.net/topics/1 THEN
SetPointer (HourGlass!
//Get the file length, and open the file
Ll_fileLength=FileLength (ls_filename)
Li_FileNum=FileOpen (ls_filename StreamMode! , Read! , LockRead!)
IF ll_filelength & gt; THEN 32765
IF the Mod (ll_filelength, 32765)=0 THEN
Loops=ll_filelength/32765
The ELSE
Loops=(ll_filelength/32765) + 1
END the IF
The ELSE
Loops=1
END the IF
//Read the file
New_pos=1
FOR I=1 to loops
Bytes_read=FileRead (li_FileNum, b)
Tot_b=tot_b + b
//
//IF I=1 then
//st_1. Text=string (tot_b)
//end if
//
NEXT
FileClose (li_FileNum)
Gb_photo=tot_b
St_1. Text=string (tot_b)
//ole_1 objectdata=https://bbs.csdn.net/topics/gb_photo
//st_1. Text=filepath
Ls_id=dw_1. Getitemstring (dw_1 getrow (), "id")
St_1. Text=string (dw_1 getrow ())
//file database
The SQLCA. The AutoCommit=True
UpdateBlob ole Set object=: gb_photo where id=: ls_id;
If the sqlca. Sqlcode=0 then
commit;
Messagebox (" congratulations "and" successfully saved ")
The else
The rollback.
Messagebox (" database error ", "save failed")
End the if
The SQLCA. The AutoCommit=false

The else
Messagebox (" prompt ", "didn't select files!" )
end if

CodePudding user response:

Know the reason, the original is a problem of database connection mode, the original is an ODBC connection way, change to be solved by special connection mode,

CodePudding user response:

If use PB10 above version, it is suggested that use FileReadEx, can directly read at a time, keep the circulation processing



The Description

Reads the data from the file associated with the specified file number, which was assigned to the file with the FileOpen function.

Syntax

FileReadEx (file#, blob length}, {)

FileReadEx (file#, string)

Argument Description
File# The integer assigned to The file when it was The opened.
A blob or string The name of The string or a blob variable into which you want to read The data.
Length In text or stream mode, the number of bytes a retrieve the requires. The default value is the length of the file.
The Return value

Long. Returns the number of bytes read. If an end - of - file mark (EOF) is encountered before any characters are read, FileReadEx Returns - 100. If the file is the opened in LineMode and a CR or LF is encountered before any characters are read, FileReadEx Returns 0. If an error occurs, FileReadEx Returns - 1. FileReadEx Returns 1 If you attempt to read from a string in stream mode or read from a blob in line mode. If any argument 's value is null, FileReadEx Returns null.

FileReadEx returns long Unlike the FileRead function that it replaces, the FileReadEx function returns a long value.

The Usage

FileReadEx can read files with ANSI, utf-8, utf-8 16 le, and 16 be utf-8 encoding.
If the file is the opened in line mode, FileReadEx reads a line of the file (that is, until it encounters a CR, LF, or EOF). It stores the contents of the line in the specified variable, skips the line - end characters, and positions the file pointer at the beginning of the next line.
The optional length parameter applies only to a blob data. If The length parameter is provided when The datatype of The second parameter is a string, The code will not compile.

If the file was the opened stream or in text mode, FileReadEx reads to the end of the file or the next length bytes, whichever is shorter. FileReadEx begins reading at the file pointer, which is positioned at the beginning of the file when the file is the opened for reading. If the file is longer than the length bytes, FileReadEx automatically positions the pointer after each read operation so that it is ready to read the next chunk of data.
An end - of - file mark is a null character (ASCII value 0). Therefore, if the file being read the contains null characters, FileReadEx stops reading at the first null character, and interpreting of it as the end of the file.

If the file is an ANSI or utf-8 file and is read into a string, FileReadEx converts the text to Unicode before saving it in the string variable. The BOM is not written to the string.
If the file is an ANSI or utf-8 file and is read into a blob, FileReadEx saves the contents of the file with the no conversion, the BOM is not written to the blob in text mode, but it is written to the blob in stream mode.
If the file is in Unicode, no conversion is required.

CodePudding user response:

I use a PB9.0

CodePudding user response:

pb9
  • Related