473,902 Members | 6,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reference SQL Parser

I need to parse SQL statements directly and extract each segment
individually. Is there a way reference the Microsoft SQL Parser
directly from VB.Net?

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
6 10727

"mCompany" <ma**@mvestcapi tal.com> wrote in message
news:40******** *************@n ews.frii.net...
I need to parse SQL statements directly and extract each segment
individually. Is there a way reference the Microsoft SQL Parser
directly from VB.Net?

Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


If you're referring to the MSSQLParser COM object, I belive it's MS
internal, and isn't documented or supported. But if you can explain why you
need to do this, someone may have a better answer.

Simon
Jul 20 '05 #2
mCompany (ma**@mvestcapi tal.com) writes:
I need to parse SQL statements directly and extract each segment
individually. Is there a way reference the Microsoft SQL Parser
directly from VB.Net?


As Simon said, if you are more specific what you are up to, you can
get more precise advice.

The simple way is to send the statements to SQL Server, and first send
SET PARSEONLY ON.

If you want find where there statement boundaries, there is a really
obscure variant which requires you to use DB-Library. Which probably
precludes Visual Basic, because I doubt there is a DB-lib interface
for VB these days. You first send SET OFFSETS ON to SQL Server and then
you retrieve the information with dboffsets. I should hasten to add that
I played with this at some occasion. I got different results back from
SQL 6.5 and SQL 7, but none of them appeared correct to me.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
All we really need to do is split out the various SQL segments (SELECT,
FROM, WHERE, ORDER BY). It's not that difficult to write, but if
there's a quick way to do, we'll use it. Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

"mCompany" <ma**@mvestcapi tal.com> wrote in message
news:40******** *************@n ews.frii.net...
All we really need to do is split out the various SQL segments (SELECT,
FROM, WHERE, ORDER BY). It's not that difficult to write, but if
there's a quick way to do, we'll use it. Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


I don't know of any supported tool, but roughly parsing a very simple SELECT
into its parts should be straightforward with most string/regex tools.
However, you need to think about the limitations of that solution - SQL
queries can be written in numerous ways, and with subqueries, derived
tables, unions etc, you may have problems.

You still haven't really explained your goal, so may want to clarify that to
help someone give you a better answer. For example, are you implementing
custom syntax highlighting? Or are you accepting arbitrary SQL strings from
a client, and you want to ensure they are syntactically correct before
execution? Or do you want to validate SQL strings as being SQL92/99
compliant?

Simon
Jul 20 '05 #5
The SET OFFSETS should work. If it does not, we'll write our own basic
parser.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #6
mCompany (ma**@mvestcapi tal.com) writes:
All we really need to do is split out the various SQL segments (SELECT,
FROM, WHERE, ORDER BY). It's not that difficult to write, but if
there's a quick way to do, we'll use it. Any ideas?


Not that difficult? Boy, you are in for a real treat.

Believe me, I have written Perl code that parses bits of T-SQL, and this
is no simple exercise if you want it to work perfectly. If you can cut
down on the ambitions and miss out on some constructs, the work you need
to put in it, is of moderate size.

The reason why this is difficult is that T-SQL has a wretched ad-hoc
syntax onto which things have been added through the years, and lot of
old syntax retained for compatibility. For instance, do you think these
two statements parse the same?

SELECT 5ee
SELECT 5dd

They don't.

What I needed to was to find all references to table in the code. To this
end I sifted through the code and woke up on keywords that can be followed
by a table name: INSERT, UPDATE, DELETE, FROM and JOIN. FROM is most
tricky, because there may come a list of tables. And in the middle of
there may be a rowset fucntion like OPENQUERY or OPENXML. This is perfectly
legal T-SQL:

SELECT *
FROM a, b, OPENQUERY(REMOT ESRV, 'SELECT * FROM a') AS c, d
JOIN e ON a.col = e.col, f
WHERE a.col2 = b.col2
AND a.col3 = c.col3
AND a.col4 = d.col4
AND e.col5 = f.col5

But the code I wrote will not find d and f. It would be crazy to write
code like that.

A tip is that start by doing a pass that eliminates all constants, and
replaces all string literals with simple tokens. String literals here
includes all that is enclosed in '', "" and [].
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #7

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

Similar topics

1
2855
by: lawrence | last post by:
The following class method is being rejected by the PHP parser. If I change the method paramaters and allow the objects to be passed as copies, then the parser has no problem. Or, if I pass by reference but set no default value, then the parser has no problems. I've resovled this for now by taking out the "false" default values. But how shall I handle those situations (there are many) where I wish to pass an object by reference but I'm not...
2
3533
by: David Dorward | last post by:
I'm attempting to read an XHTML 1.1 file, perform some DOM manipulation, then write the results to a different file. I've found myself rather stuck at the first hurdle. I have the following: from xml.dom.ext.reader import Sax2 reader = Sax2.Reader() f = open('dorward.me.uk/sitemap.html', 'r')
15
2147
by: Ron Adam | last post by:
Does anyone have suggestions on how to improve this further? Cheers, Ron_Adam def getobjs(object, dlist=, lvl=0, maxlevel=1): """ Retrieve a list of sub objects from an object. """
1
1629
by: laughlin | last post by:
I'm using MS's XML DOM component to parse what I thought was XHTML. For some reason, the parser doesn't like the following reference that includes a couple of parameters following the "?" and seperated by the "&". Specifically, the parser is expecting a ";" following "stills" in the snippet below. <a href="../../../../Media/Drills/feint1.avi?selection=8.65,10.33&stills=10.07"> Any ideas?
2
2629
by: msnews.microsoft.com | last post by:
I am currently trying to follow the Que Publishing exam guide to the Microsoft Exam 70-320. I followed the guide to a tee, but when I try to add a web reference to my server side soap extension it gives me the following error:- An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message:...
2
9187
by: JT | last post by:
Okay, I've seen about 4 years' worth of posts about this with no viable solutions. I've spent 9 hours today trying to fix this. It works BEAUTIFULLY on my local IIS installation, but when I publish to my web host and try to add a web reference I get the following: Server Error in '/' Application. -------------------------------------------------------------------------------- Parser Error Description: An error occurred during the...
3
23788
by: sisqorap | last post by:
Hi all, I have this kind of warning and would like to have it solved: Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_parse_into_struct(). If you would like to enable call-time pass-by- reference, you can set allow_call_time_pass_reference to true in your INI file. in /bla.php on line 94 The code which is behind is like this:
2
2899
by: r_ahimsa_m | last post by:
Hello, I am learning PHP5. I need to parse XML file and I found a solution in some book on PHP5 ("PHP5 Programming" by Rasmus Lerdors and others). Unfortunately I have two problems that I don't understand: Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of xml_set_object(). If you would like to enable call-time pass-by-reference, you can set...
0
1263
by: r.battistoni | last post by:
Hy to everyone I have created a simple SAX parser for a very simple XML file. When I run the code that follows I get this error: "Invalid hexadecimal character reference" The strange thing is If I change the "chunk size" for the data I send to the parser, the error row changes. This behaviour is very strange!
0
9997
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
10870
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
10499
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
9673
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8047
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
5893
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
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4306
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
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.