473,399 Members | 2,858 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,399 software developers and data experts.

How to use parameter markers for "for bit data" columns?

Hallo!

I have a table tstest(ts char(13) for bit data constraint a unique).

This column is filled in a trigger with generate_unique().

In a application (CLI), I have the values of this column as timestamp
representation: e.g.: select timestamp(ts) from tstest

1
--------------------------
2003-10-27-08.50.14.430717

My problem is, that i want do delete from this table with:
"delete from tstest where ts=?"
This means I want to use a parameter marker for the value.
How should I format the value, so that db2 understands it as char(13)
for bit data?

I have tried to use "delete from tstest where ts=TIMESTAMP(CAST(? AS
CHAR(26))", which works, but has a poor performance. So I think it would
have a better performance when I use the value without the cast.

Is there a way in SQLBindParameter, to tell db2 that it should interpret
the given value string as the hex representation of binary data?

e.g. with plain sql i would write:
"delete from tstest where ts=x'20031027085014430717000000'"

Is there a way to do it with SQLBindParameter?

thanks
andreas

Nov 12 '05 #1
6 5079
"alederer" <al******@gmx.at> wrote in message
news:3f********@e-post.inode.at...
Hallo!

I have a table tstest(ts char(13) for bit data constraint a unique).

This column is filled in a trigger with generate_unique().

In a application (CLI), I have the values of this column as timestamp
representation: e.g.: select timestamp(ts) from tstest

1
--------------------------
2003-10-27-08.50.14.430717

My problem is, that i want do delete from this table with:
"delete from tstest where ts=?"
This means I want to use a parameter marker for the value.
How should I format the value, so that db2 understands it as char(13)
for bit data?

I have tried to use "delete from tstest where ts=TIMESTAMP(CAST(? AS
CHAR(26))", which works, but has a poor performance. So I think it would
have a better performance when I use the value without the cast.

Is there a way in SQLBindParameter, to tell db2 that it should interpret
the given value string as the hex representation of binary data?

e.g. with plain sql i would write:
"delete from tstest where ts=x'20031027085014430717000000'"

Is there a way to do it with SQLBindParameter?

thanks
andreas

I am not sure why your Timestamp column is defined for bit data. Even though
you see the data as 26 bytes, DB2 stores the data for a timestamp column as
13 bytes without you defining it as bit data.

My understanding is that bit data is primarily used when no code page
conversion is desired.
Nov 12 '05 #2
> I am not sure why your Timestamp column is defined for bit data. Even
though
you see the data as 26 bytes, DB2 stores the data for a timestamp column as 13 bytes without you defining it as bit data.

My understanding is that bit data is primarily used when no code page
conversion is desired.

Correction. DB2 stores a timestamp internally in 10 bytes, not 13.
Nov 12 '05 #3
The reason for char(13) is, that the db2 function generate_unique()
returns "char(13) for bit data". And this function is used inside a
trigger to fill the specified column.

Andreas
Mark A wrote:
"alederer" <al******@gmx.at> wrote in message
news:3f********@e-post.inode.at...
Hallo!

I have a table tstest(ts char(13) for bit data constraint a unique).

This column is filled in a trigger with generate_unique().

In a application (CLI), I have the values of this column as timestamp
representation: e.g.: select timestamp(ts) from tstest

1
--------------------------
2003-10-27-08.50.14.430717

My problem is, that i want do delete from this table with:
"delete from tstest where ts=?"
This means I want to use a parameter marker for the value.
How should I format the value, so that db2 understands it as char(13)
for bit data?

I have tried to use "delete from tstest where ts=TIMESTAMP(CAST(? AS
CHAR(26))", which works, but has a poor performance. So I think it would
have a better performance when I use the value without the cast.

Is there a way in SQLBindParameter, to tell db2 that it should interpret
the given value string as the hex representation of binary data?

e.g. with plain sql i would write:
"delete from tstest where ts=x'20031027085014430717000000'"

Is there a way to do it with SQLBindParameter?

thanks
andreas


I am not sure why your Timestamp column is defined for bit data. Even though
you see the data as 26 bytes, DB2 stores the data for a timestamp column as
13 bytes without you defining it as bit data.

My understanding is that bit data is primarily used when no code page
conversion is desired.


Nov 12 '05 #4
"alederer" <al******@gmx.at> wrote in message
news:3f********@e-post.inode.at...
The reason for char(13) is, that the db2 function generate_unique()
returns "char(13) for bit data". And this function is used inside a
trigger to fill the specified column.

Andreas

You don't think that current timestamp would be unique for each transaction?
Just wondering if you have tested that.
Nov 12 '05 #5
Mark A <ma@switchboard.net> wrote:
"alederer" <al******@gmx.at> wrote in message
news:3f********@e-post.inode.at...
The reason for char(13) is, that the db2 function generate_unique()
returns "char(13) for bit data". And this function is used inside a
trigger to fill the specified column.


You don't think that current timestamp would be unique for each
transaction? Just wondering if you have tested that.


GENERATE_UNIQUE gives you a unique value - across transactions, statements,
and even within a single statement. The description of that function says
that the unique value is based on the system time and some further
information is added to make it truly unique. You can also use the
timestamp function on the unique value returned by GENERATE_UNIQUE to
extract the timestamp portion. The result of that might not be unique.

So it does make sense to me what Andreas tries to do.

In any case, I would write the delete statement like this:

DELETE
FROM tstest
WHERE TIMESTAMP(ts) = ?

And then pass a regular timestamp value as SQL_NTS (null-terminated string)
through CLI. I don't think that a direct comparison of the unique value
with a timestamp is such a good idea because generate_unique does not
consist of a timestamp only and the additional information might cause
problems for you.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #6
Knut Stolze wrote:
Mark A <ma@switchboard.net> wrote:

"alederer" <al******@gmx.at> wrote in message
news:3f********@e-post.inode.at...
The reason for char(13) is, that the db2 function generate_unique()
returns "char(13) for bit data". And this function is used inside a
trigger to fill the specified column.


You don't think that current timestamp would be unique for each
transaction? Just wondering if you have tested that.

GENERATE_UNIQUE gives you a unique value - across transactions, statements,
and even within a single statement. The description of that function says
that the unique value is based on the system time and some further
information is added to make it truly unique. You can also use the
timestamp function on the unique value returned by GENERATE_UNIQUE to
extract the timestamp portion. The result of that might not be unique.

So it does make sense to me what Andreas tries to do.

In any case, I would write the delete statement like this:

DELETE
FROM tstest
WHERE TIMESTAMP(ts) = ?

And then pass a regular timestamp value as SQL_NTS (null-terminated string)
through CLI. I don't think that a direct comparison of the unique value
with a timestamp is such a good idea because generate_unique does not
consist of a timestamp only and the additional information might cause
problems for you.


The deliberations of Knut are correct.
So I have changed my solution to use not the timestamp representation of
the unique value.
Now I convert the 26 char hex string representation to the 13 byte
binary representation and use this for the parameter value.
The speedup against the "where ts=TIMESTAMP(CAST..." solution is
fascinating.

thanks
Andreas

Nov 12 '05 #7

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

Similar topics

17
by: Istvan Albert | last post by:
Paul McGuire wrote: > Please reconsider the "def f() :" construct. Instead of > invoking a special punctuation character, it uses context and placement, > with familiar old 's, to infuse the...
1
by: arvee | last post by:
Hi - I'm updating an Oracle table with an empty string and getting the error: An unhandled exception of type 'System.Exception' occurred in system.data.dll Additional information: Parameter...
0
by: JL | last post by:
Hi there I have a database with entries like the following: Id, Name, Goals_season, Goals_total ---------------------------------------- 5, John, 5, 23 6, Mike, 2, 14 7, Joe, 10, 34 Every...
10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
2
by: Mike | last post by:
I need to determine where the "bit data" flag (as applied on a CHAR and other columns) is stored in the system tables. I'm trying to add data mappings to our product (MyGeneration) so if you ask me...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
0
by: John Spiegel | last post by:
Hi all, I'm converting a data grid from using bound columns to templated columns. With a BoundColumn, I can format something like a date with the DataFormatStyle attribute. Is there a similar...
0
by: earsypaul | last post by:
Hello, With MS SQL server we can bcp hexadecimal data into varbinary columns quite nicely. We're migrating some data to DB2 and trying to import to a "varchar for bit data" data type column....
7
by: bazzer | last post by:
i am having trouble updating a datset because i get the follwing error in the Data Adapter configuration Wizard: Generated UPDATE statement. could not determine which columns uniquely identify...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.