powered by simpleCommunicator - 2.0.60     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Delphi [игнор отключен] [закрыт для гостей] / Загрузка BLOB-ов
5 сообщений из 5, страница 1 из 1
Загрузка BLOB-ов
    #32325400
Фотография Oleg Afanasiev
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Есть идея грузить BLOB-поля из делфи(ДОА) в Оракл так
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
var
    BlobField:Variant;
begin
BlobField.LoadFromFile('path');
......
SaveQuery.SetVariable('BlobField',BLOBFIELD);
......


Раньше с блобами не работал, поэтому может есть какие грабли?
...
Рейтинг: 0 / 0
Загрузка BLOB-ов
    #32325675
Сашка
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
в документации по ДОА написано, что для работы с BLOB полями нужно использовать локаторы (лишнее выкинишь сам):

var
...
LOB: TLOBLocator;
...

begin
...
with DMForm.TempInOraQuery do begin
Clear;
SQL.Add('INSERT INTO '+AttachTableNameEdit.Text+' (Receive_Time, Dir_Name, Name_File, Body_File)');
SQL.Add('VALUES (:RecTime, :DirName, :Name_File, empty_blob())');
SQL.Add('RETURNING Body_File INTO :Body_File');
DeclareVariable('RecTime', otDate);
DeclareVariable('Name_File', otString);
DeclareVariable('Body_File', otBLOB);
DeclareVariable('DirName', otString);
SetVariable('DirName', TempDirInside);
SetVariable('RecTime', RecTime);
SetVariable('Name_File', searchRecFile.Name);
LOB := TLOBLocator.Create(DMForm.OraSession, otBLOB);
SetComplexVariable('Body_File', LOB);
Execute;
LOB.LoadFromFile(TempDir+'\'+SearchRecFile.Name);
LOB.Free;
end;
...
end;
...
Рейтинг: 0 / 0
Загрузка BLOB-ов
    #32331628
trollish
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
"SQL.Add('INSERT INTO '+AttachTableNameEdit.Text+' (Receive_Time, Dir_Name, Name_File, Body_File)');
SQL.Add('VALUES (:RecTime, :DirName, :Name_File, empty_blob())');
SQL.Add('RETURNING Body_File INTO :Body_File'); "

Вот здесь что происходит? Можно чуть объяснить. Я так понимаю, что создаётся строка сначала с пустым блобом. А потом туда каким-то макаром
(скорее всего в этих строках:
SetComplexVariable('Body_File', LOB);
LOB.LoadFromFile(TempDir+'\'+SearchRecFile.Name); )
записывается сам файл.

Вопрос 1-ый: что даёт RETURNING Body_File INTO :Body_File') в insert'e ?
Вопрос 2-ой: как вообще это работает (где тут update??)
Вопрос 3-ий: как без инсёрта сие реализовать? Т.е. у меня например в таблица tab (id integer, b blob).. как мне сделать что-то типа update tab set b=bbbb (данные) where id=121 ?
...
Рейтинг: 0 / 0
Загрузка BLOB-ов
    #32331702
Сашка
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
вот что написано в документации:

You need to insert new LOB data into a table in two situations:

1. You are inserting a new record.
2. You are updating a record where the old value of the LOB column is null. In this case, the record does not contain a LOB Locator that you can use to write data to.

If you are not using a temporary LOB, you must first insert/update an empty LOB Locator into the record. To do so, you can use the SQL function empty_blob() or empty_clob() in an insert or update statement. On the server, the LOB Locator will be initialized. The initialized LOB Locator can then be returned to the client in a variable by using the new Oracle8 returning clause. After this, you can start writing data to the LOB column. Note that you must use SetComplexVariable to set a LOB variable.

The following is an example of an insert:

var LOB: TLOBLocator;

Buffer: array[0..99] of Byte;

begin

// insert into lobtable (id, lobcolumn) values (:id, empty_blob())

// returning lobcolumn into :lobcolumn

with LOBQuery do

begin

SetVariable('id', 1);

// Create a new BLOB (initially Null)

LOB := TLOBLocator.Create(Session, otBLOB);

// Assign it to the returning variable

SetComplexVariable('lobcolumn', LOB);

Execute;

// After the insert, use the LOB Locator to write the data

LOB.Write(Buffer, 100);

LOB.Free;

end;

end;

If you are using temporary LOB's, you can write the LOB data before executing the query, and directly use this LOB data for an insert or update without a returning clause:

var LOB: TLOBLocator;

Buffer: array[0..99] of Byte;

begin

// insert into lobtable (id, lobcolumn) values (:id, :lobcolumn)

with LOBQuery do

begin

SetVariable('id', 1);

// Create a new temporary BLOB and write the data

LOB := TLOBLocator.CreateTemporary(Session, otBLOB, True);

LOB.Write(Buffer, 100);

// Assign it to the returning variable

SetComplexVariable('lobcolumn', LOB);

// Insert it

Execute;

LOB.Free;

end;

end;
...
Рейтинг: 0 / 0
Загрузка BLOB-ов
    #32333510
ujin
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Подскажите пожалуйста: делаю по всем хелпам и советам, как бы не пытался занести значение в CLOB поле (пишу на С++ Builder)
LOB->AsString = S;
LOB->Write(S.c_str(), S.Length());
.....................................
Результат один - "TLOBLocator : Invalid handle"

ЧТО ДЕЛАТЬ???
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / Delphi [игнор отключен] [закрыт для гостей] / Загрузка BLOB-ов
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]