Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-07-2011, 05:01 PM   #1
The Oate
Registered: May 2004
Location: Massachusetts
Posts: 134

Rep: Reputation: 16
DB2 VARCHAR type usage with NULL character

I have a vector of bytes that I need to store in a DB2 database and was wanting to do it with a column declared as VARCHAR () FOR BIT DATA. I can do this with no problem except when a byte representing the NULL character occurs in the vector. Anytime this occurs, the rest of the bytes are truncated. I know this is the proper behavior for if this were a string, but I was under the impression that if the column is declared as I previously mentioned, that this would support any variable length binary data including the NULL character.

I've found repeated references to people dealing with DB2 tables where the data in VARCHAR columns contained leading and embedded NULLS, so I know this is possible. Can anyone provide me with the proper INSERT statement in order to get this to work? This is the current BindParameters call I'm making for the VARCHAR () FOR BIT DATA column that's truncating after the NULL character occurs.

SQLBindParameter(handleStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, 
        SQL_VARCHAR, (SQLUINTEGER)(30000), 0, data2, 30000,
Old 03-08-2011, 12:11 PM   #2
The Oate
Registered: May 2004
Location: Massachusetts
Posts: 134

Original Poster
Rep: Reputation: 16
I've changed the field in the table to now be declared as a BLOB(30000) and I'm using the below bind parameter statement with this, however I'm still seeing the same problem. When the first byte is reached that contains 0 (NULL character), the rest of what's in ptr is ignored. ptr is declared as unsigned char ptr[30000]. For testing purposes, I've just been using a for loop and storing the value of the counter % 255 + 1 so that all the characters except for NULL are represented. Then I've gone in and just inserted a 0 value in a few places. Anyone know how I can get the full contents of ptr to be stored?

SQLBindParameter(handleStmt, 3, SQL_PARAM_INPUT, SQL_C_BINARY,
                     SQL_BLOB, (SQLUINTEGER)30000, 0, ptr, (SQLINTEGER)30000, &sqlNts);
Also, here is the format of the INSERT statement that I'm trying to use:

char *insertStmt =


db2, sql, [c]

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Printf and a sort of "null character"? Possible? BlueSpirit Programming 26 05-02-2007 05:17 PM
Can't tyPe a certain character in GNOME kesara3k Fedora 0 08-31-2004 05:55 PM
What type of slashdot character are you? ProgramGeek General 7 07-26-2004 04:19 PM
I always have spaces between each character I type markraem Linux - General 2 01-26-2004 06:15 AM
Bug A Javascript that will not allowed alphabet character type into a text box Linh Programming 2 09-22-2003 11:15 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:33 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration