473,698 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

parsing dynamic sql and removing constants

Hello

I need to process a SQL monitoring log stored in a table to group the
statements that change just the constants in it. Ex:

select a,b,c from table where (a = 'xyz' and b = 123 and c !=
'2004-10-10') or ( a like 'def%' )
select a,b,c from table where (a = 'zyx' and b = 321 and c !=
'2004-01-01') or ( a like '%fed' )

using an udf to remove constants:

select a,b,c from table where (a = '' and b = and c != '' ) or ( a
like '' )
or
select a,b,c from table where (a = %cconstant% and b = %nconstant% and
c != %dconstant% ) or ( a like %cconstant% )

I'm building a simple udf to do this, but i found this a little more
trickier.
It seems that i could use yacc / lex to do this, but i didnt touch
anything related yet
(i wasn't willing to spend so much time)

Anybody knowns any clever algorithm/udf that i could use to do this?
Thanks
Nov 12 '05 #1
3 2816
This is a much much more complex process than your two statements make
it appear to be. I believe that there are some purchasable performance
tools from third party vendors that do this bit I've never used any of
them and don't know how well they work.

I wrote a Java program to do this directly from a statement trace log
from UDB V7. I basically had to write an SQL statement parser then
rebuild the SQL statement. I'd be interested in "a clever algorithm" too.

Phil Sherman
Alexandre H. Guerra wrote:
Hello

I need to process a SQL monitoring log stored in a table to group the
statements that change just the constants in it. Ex:

select a,b,c from table where (a = 'xyz' and b = 123 and c !=
'2004-10-10') or ( a like 'def%' )
select a,b,c from table where (a = 'zyx' and b = 321 and c !=
'2004-01-01') or ( a like '%fed' )

using an udf to remove constants:

select a,b,c from table where (a = '' and b = and c != '' ) or ( a
like '' )
or
select a,b,c from table where (a = %cconstant% and b = %nconstant% and
c != %dconstant% ) or ( a like %cconstant% )

I'm building a simple udf to do this, but i found this a little more
trickier.
It seems that i could use yacc / lex to do this, but i didnt touch
anything related yet
(i wasn't willing to spend so much time)

Anybody knowns any clever algorithm/udf that i could use to do this?
Thanks


Nov 12 '05 #2
Ian
Alexandre H. Guerra wrote:
Hello

I need to process a SQL monitoring log stored in a table to group the
statements that change just the constants in it. Ex:

select a,b,c from table where (a = 'xyz' and b = 123 and c !=
'2004-10-10') or ( a like 'def%' )
select a,b,c from table where (a = 'zyx' and b = 321 and c !=
'2004-01-01') or ( a like '%fed' )

using an udf to remove constants:

select a,b,c from table where (a = '' and b = and c != '' ) or ( a
like '' )
or
select a,b,c from table where (a = %cconstant% and b = %nconstant% and
c != %dconstant% ) or ( a like %cconstant% )

I did this once using perl regular expressions, it was pretty effective.
(but I used 3 regexes to completely parameterize a statement).

There was an article on DB2DD to build a UDF that exposed the perl regex
library to DB2, so I suppose this would be possible to do within DB2.
(The script I wrote was reading SQL from a flat file).


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Nov 12 '05 #3
Hi,

i just wrote an UDF in C++ which uses the Perl Library to format the
constants in SQL-Statements. We are going to use this UDF in our
performance monitoring tool so i am not allowed to post it here. But
you can use the following links to implement your own UDF (1st
scenario).

1st scenario: CPerlString, Classdefinition s to integrate Perl Library
http://www.codeproject.com/string/cperlstring.asp
and integrate CPerlString in your UDF

2nd scenario: Knut Stolze (this guy knows what he does) uses PCRE
http://www-106.ibm.com/developerwork...301stolze.html

Using Lexx and yacc could be a problem (non deterministic, not context
sensitive grammar ....)

sample Perl REGEX to replace any number in a string with
'HERE_WAS_A_NUM BER':
$parse =~ s/(\W)(\d+)/$1HERE_WAS_A_NU MBER/gi;
be careful, this also make out of 123.456
HERE_WAS_A_NUMB ER.HERE_WAS_A_N UMBER
I wrote 4 regular expressions in my UDF to remove the constants and it
works for almost 90% of the sqls i tested with. Let me know if you
need some hints for the regular expressions, a sample c-code or
compiling DB2 UDFs for WIN32 (took me 2 days to set up the right
environment)

best wishes
Florian
Ian <ia*****@mobile audio.com> wrote in message news:<41******* *@127.0.0.1>...
Alexandre H. Guerra wrote:
Hello

I need to process a SQL monitoring log stored in a table to group the
statements that change just the constants in it. Ex:

select a,b,c from table where (a = 'xyz' and b = 123 and c !=
'2004-10-10') or ( a like 'def%' )
select a,b,c from table where (a = 'zyx' and b = 321 and c !=
'2004-01-01') or ( a like '%fed' )

using an udf to remove constants:

select a,b,c from table where (a = '' and b = and c != '' ) or ( a
like '' )
or
select a,b,c from table where (a = %cconstant% and b = %nconstant% and
c != %dconstant% ) or ( a like %cconstant% )

I did this once using perl regular expressions, it was pretty effective.
(but I used 3 regexes to completely parameterize a statement).

There was an article on DB2DD to build a UDF that exposed the perl regex
library to DB2, so I suppose this would be possible to do within DB2.
(The script I wrote was reading SQL from a flat file).


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Nov 12 '05 #4

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

Similar topics

2
4275
by: Emre Sevinc | last post by:
I'm using classical ASP on IIS 6.0 (Windows 2003 Server). What I want to do is to serve the same pages in two different languages without using two different folders and doubling my same ASP code and changing the string values. What I need is DYNAMIC INCLUDE functionality similar to PHP, however I know that I don't have it in ASP. Moreover Server.Execute is useless because it doesn't have a functionality like an include file, calling...
9
3203
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII "stereolithography" file (*.STL) into my program. This has the following syntax... Begin STL Snippet **********
8
1693
by: Drew | last post by:
I am trying to build a small app that shows a Course Title from the database, then displays a dropdown full of categories for the user to choose one... I thought a loop would be the best way to accomplish this, but since the dropdown is dynamic, I am having problems. Can someone help me out here? Here is my code, For i = 1 to Num
3
2248
by: Arsalan Ahmad | last post by:
Hi, I have recently uploaded a file in a webserver. When i try to access it via browser, I get following error: This is working fine in my local copy. Any idea what could be wrong. Server Error in '/' Application. ---------------------------------------------------------------------------- ---- Parser Error
23
1755
by: Peter Row | last post by:
Hi, I am currently working on a VB.NET project that has been going for quite a while. In the past it has been developed with a lot of compatibility VB6 functions and constants, e.g Left(), LCase() and vbCr Whilst not currently able to port to C# I am trying to remove usage of these functions and constants.
1
1727
by: chixor1 | last post by:
I have been charged with Parsing the data from many Abstract files, and then inputing this information into a SQL Database. The file format is rather unusual and certainly not delimited in any reasonable fashion. I was wondering if anyone would be able to assist or provide an idea of how I may go about parsing this data for insertion. The plan is to write a small application in VB that will allow me to run through each text file, and then...
2
2586
by: python | last post by:
I'm parsing a text file for a proprietary product that has the following 2 directives: #include <somefile> #define <name<value> Defined constants are referenced via <#name#syntax. I'm looking for a single text stream that results from processing a file containing these directives. Even better would be an iterator(?) type
6
7968
by: =?ISO-8859-1?Q?Tim_B=FCthe?= | last post by:
Hi, we are building a Java webapplication using JSF, running on websphere, querying a DB2 9 on Suse Enterprise 10. The app uses JDBC and PreparedStatements only (aka dynamic SQL). Every night, there is a ETL which deletes most of the data in the database and fills it all new. We observed very bad performance for some statements that ran for minutes (The queried table is about 100,000 records and the result is about 500 rows)....
1
2964
by: hd95 | last post by:
In a perfect world my xml feed source would produce perfect xml ..that is not the case I am parsing an XML feed that sometimes has ampersands and dashes in the content that messes up my parsing. I've tried doing pre processing with find/replace to get rid of these characters but then I get another type of error "An unexpected end of file parsing CDATA has occurred" So to get around that error I've added in unicoding and removing...
0
8604
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
9160
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
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8862
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...
1
6521
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.