March 7th, 2013, 12:42 AM
-
Segmentation Fault(core dump) - BLOB Locator use in Oracle DB using Pro*C/C++
Hi,
I am trying to implement BLOB Locators concept in oracle db using pro*c/c++.
My DB table columns are of BLOB datatype and i want to insert/update data using BLOB Locators and that data is passed as parameter in the function.
As i have understood till this point the Locators concept, please comment if i am wrong:-
- Declare the Locator variable - OCIBlobLocator *<locator_variable>;
- Allocate the memory for Locator variable - EXEC SQL ALLOCATE :<locator_variable>;
- Map the Locator variable with the DB Column - EXEC SQL SELECT <column_name> INTO :<locator_variable> FROM <table_name>;
- Perform the operation(in this case UPDATE operation) - EXEC SQL UPDATE <table_name> SET <cloumn_name>=:<locator_variable>;
- Free the memory of Locator variable - EXEC SQL FREE :<locator_variable>;
In my case i am having data passed as parameter in the function, so how to map the locator variable to particular column.
While updating the BLOB column i am getting the Segmentation Fault(core dump). So during UPDATE operation what <locator_variable> contains memory address or the data value.
I my opinion i am having address mapping problem, while updating the BLOB column.
Can you guys suggest any thing. Thanks for your help.
March 8th, 2013, 11:52 AM
-
Originally Posted by saumitra8361
Hi,
I am trying to implement BLOB Locators concept in oracle db using pro*c/c++.
My DB table columns are of BLOB datatype and i want to insert/update data using BLOB
. . . E t c . . .
Can you guys suggest any thing. Thanks for your help.
Did you insert the row(s) using EMPTY_BLOB()?
March 11th, 2013, 03:39 AM
-
Originally Posted by LKBrwn_DBA
Did you insert the row(s) using EMPTY_BLOB()?
Hi LKBrwn_DBA,
Yes I tried to insert row using EMPTY_BLOB(), but that also didn't worked.
According to my knowledge EMPTY_BLOB() only initializes LOB Locator particular to that column.
April 4th, 2013, 03:38 PM
-
Originally Posted by saumitra8361
Yes I tried to insert row using EMPTY_BLOB(), but that also didn't worked.
According to my knowledge EMPTY_BLOB() only initializes LOB Locator particular to that column.
That is exactly how it works:
1) Insert EMPTY_BLOB()
2) Update the blob.
April 8th, 2013, 11:46 PM
-
Hi LKBrwn_DBA,
Now i get the solution
. It involves following Steps:-
1) First Allocate Memory and Initialize LOB Locator
EXEC SQL ALLOCATE :<LOB_Locator>;
2) Then use INSERT/UPDATE to initialize LOB Column,
here we are using example of UPDATE query....
EXEC SQL UPDATE <Table_Name>
SET <LOB_Column> = EMPTY_BLOB(),(column = : <Value>,......)
(WHERE <condition_check>)
RETURNING <LOB_Column> INTO :<LOB_Locator> ;
Here, 'RETURNING' Clause will map LOB_Locator with LOB Column in the DB Table.
3) OPEN LOB Locator according to use.
EXEC SQL LOB OPEN :<LOB_Locator> READ WRITE;
4) Now WRITE data into LOB Locator.
EXEC SQL
LOB WRITE ONE :<amt> FROM :<Data_Buffer> INTO : <LOB_Locator>;
here, 'amt' is the no. of bytes need to be written.
5) CLOSE the LOB Locator after read/write Operation.
EXEC SQL LOB CLOSE :<LOB_Locator>;
6) FREE Allocated Memory of LOB Locator.
EXEC SQL FREE :<LOB_Locator>;