473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bulk Insert of Blob data type in Oracle

Hi,
I am trying to do bulk insert of binary data (array of bytes) in an
Oracle table. The data type of the table is BLOB. I am using Oracle
Objects for OLE (OO4O) in C++.

The binary data that I have to insert is in the form of byte array.
My problem is that the bulk inserts happen only as long as the length
of array is less than 4K. Any data more than 4K gets truncated.

Is it possible to do bulk inserts in a BLOB field with data more that
4K per record ? Here is the code that works fine only as long as byte
array is less that 4000 bytes:
OStartup();

ODatabase conn;
conn.Open("tnsname", "user", "password");
if (conn.IsOpen())
{

long recordCount = 10;

OParameterCollection params = conn.GetParameters();
OParamArray blobParam =
params.AddTable("PARAMBLOB", OPARAMETER_INVAR,
OTYPE_RAW_BIN, recordCount, 4000);

//lets put 10 dumy records
int bufSize = 4000;
for (int i=0;i<recordCount;i++)
{
//simulate a byte array of size bufSize.
//This is normally more than 4000 bytes in real life
BYTE * byteArray = new BYTE[bufSize];
for (int j=0;j<bufSize;j++)
{
byteArray[j] = 60;//an arbit value

}

//copy it over to a char buffer
char *buff = (char *)malloc(bufSize);

memcpy(buff, byteArray, bufSize);

blobParam.SetValue(buff, bufSize, i);

free(buff);

free(byteArray);

}

oresult result =
conn.ExecuteSQL("insert into BLOB_TABLE (BLOB_FIELD) values
(:PARAMBLOB)");

blobParam.Close();
params.Close();

conn.Close();
}

OShutdown();

Any help will be greatly appreciated.
Thanks
Jul 22 '05 #1
2 6839
* nk****@oriongis.com (Niraj) schriebt:

Off-topic in [comp.lang.c++].

Please don't cross-post to groups unrelated to the question.

Jul 22 '05 #2

"Niraj" <nk****@oriongis.com> wrote in message
news:77**************************@posting.google.c om...
Hi,
I am trying to do bulk insert of binary data (array of bytes) in an
Oracle table. The data type of the table is BLOB. I am using Oracle
Objects for OLE (OO4O) in C++.

The binary data that I have to insert is in the form of byte array.
My problem is that the bulk inserts happen only as long as the length
of array is less than 4K. Any data more than 4K gets truncated.

Is it possible to do bulk inserts in a BLOB field with data more that
4K per record ? Here is the code that works fine only as long as byte
array is less that 4000 bytes:
OStartup();

ODatabase conn;
conn.Open("tnsname", "user", "password");
if (conn.IsOpen())
{

long recordCount = 10;

OParameterCollection params = conn.GetParameters();
OParamArray blobParam =
params.AddTable("PARAMBLOB", OPARAMETER_INVAR,
OTYPE_RAW_BIN, recordCount, 4000);

//lets put 10 dumy records
int bufSize = 4000;
for (int i=0;i<recordCount;i++)
{
//simulate a byte array of size bufSize.
//This is normally more than 4000 bytes in real life
BYTE * byteArray = new BYTE[bufSize];
for (int j=0;j<bufSize;j++)
{
byteArray[j] = 60;//an arbit value

}

//copy it over to a char buffer
char *buff = (char *)malloc(bufSize);

memcpy(buff, byteArray, bufSize);

blobParam.SetValue(buff, bufSize, i);

free(buff);

free(byteArray);

}

oresult result =
conn.ExecuteSQL("insert into BLOB_TABLE (BLOB_FIELD) values
(:PARAMBLOB)");

blobParam.Close();
params.Close();

conn.Close();
}

OShutdown();

Any help will be greatly appreciated.
Thanks
You have defined the record to be only 4,000 bytes long in the parameter. A
BLOB can hold up to 4 gigs so you shouldn't have trouble fitting something
larger in it.
Change: params.AddTable("PARAMBLOB", OPARAMETER_INVAR,
OTYPE_RAW_BIN, recordCount, 4000); to params.AddTable("PARAMBLOB", OPARAMETER_INVAR,
OTYPE_RAW_BIN, recordCount,

SOMETHING_LARGE_ENOUGH_TO_HOLD_LARGEST_VALUE);

To test you could change the 4000 to 3000 and I bet it will be truncated to
3,000 bytes not 4,000 bytes.
Jim
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
11
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
2
by: mrkrishnan.ms | last post by:
Hi i would like to know whether we can save data of 2GB capacity into a table in one statement using C++. I would say the data type would be BLOB or any LOB of a max of 2 gb DATA . PLEASE HELP...
11
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
2
by: mivey4 | last post by:
Hi, I have been searching but haven't had any luck finding a method of performing bulk inserts of data into Oracle comparable to using the BCP utility with MSSQL. In our MSSQL environment I...
3
by: oravm | last post by:
Hi, I re-write a query and used bulk collect to improve the performance of the batch process. The query below has NO compile error but when execute query there is error 'ORA-01403: no data...
4
by: shreyask | last post by:
I have been working on doing bulk updates and inserts through sqlapi++ using a bulk udpate extention library, developed, a long time ago, internally. The database is oracle. The bulk inserts/updates...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.