LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-07-2011, 05:01 PM   #1
The Oate
Member
 
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.

Code:
SQLBindParameter(handleStmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, 
        SQL_VARCHAR, (SQLUINTEGER)(30000), 0, data2, 30000,
        &sqlNts);
 
Old 03-08-2011, 12:11 PM   #2
The Oate
Member
 
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?

Code:
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:

Code:
char *insertStmt =
        "INSERT INTO TESTTABLE (CATEGORY, TOPIC, DATA) VALUES(?, ?, CAST(? AS BLOB(30000)))";
 
  


Reply

Tags
db2, sql, [c]



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:39 PM.

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