473,651 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(CA ST(? 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 SQLBindParamete r, 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'2003102708 501443071700000 0'"

Is there a way to do it with SQLBindParamete r?

thanks
andreas

Nov 12 '05 #1
6 5105
"alederer" <al******@gmx.a t> 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(CA ST(? 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 SQLBindParamete r, 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'2003102708 501443071700000 0'"

Is there a way to do it with SQLBindParamete r?

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.a t> 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
representatio n: 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(CA ST(? 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 SQLBindParamete r, 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'2003102708 501443071700000 0'"

Is there a way to do it with SQLBindParamete r?

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.a t> 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.a t> 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.a t> 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(CA ST..." 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
1916
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 declaration of a function with special > characteristics. If this causes def lines to run longer than one line, > perhaps the same rule that allows an unmatched "(" to carry over multiple > lines without requiring "\" continuation markers could be...
1
14938
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 'p1': No size set for variable length data type: String. The column is nullable and of type varchar2(50). I'm aware that I can store DBNull.Value instead and Oracle won't complain, but, I was hoping to avoid
0
1291
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 season we have to reset the "Goals_season" column to the default value
10
5480
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 problem that I am facing is in dealing with (privacy) critical information like credit-card #s and SSNs or business critical information like sales opportunity size or revenue in the database. The requirement is that this data be stored encrypted...
2
1820
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 why, I just gotta know, can anybody give me a select statement that can join with SYSCOLUMNS or something to find out if the "bit data" is? Mike Griffin http://www.mygenerationsoftware.com
21
13818
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 by Sets. - ICollection cannot decide containment - IList promises indexability by the natural numbers, which is not achievable (since i hash elements, not sort them). - IDictionary is definatly not setlike. Although I can, of course, define...
0
1065
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 formatting option for a TextBox control? TIA, John
0
1571
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. With delimited data it looks like importing binary data is not an option as the binary data might have LFs, CRs etc and the import tool will get confused as to where the columns and rows begin or end. The DELPRIORITYCHAR modifier does not appear to...
7
3733
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 the rows for "Customers" 'Customers' is the only table from the database that im using for this query, so it cant be anything to do with a problem of having multiple tables. and the primary key is set. so i dont understand what the problem is.
0
8361
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8278
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8584
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1912
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.