[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Parsing a string

Subject: Re: Parsing a string
From: Mayo <mayo@xxxxxxx>
Date: Thu, 3 Jun 2004 13:38:20 -0700
sql parse
Not exactly on topic, but it may help you.

I'm currently working on a project where we need to parse queries. The =20=

easiest way I found for us is to take out SQL parser from existing =20
database (PostgreSQL in our case, which RDBMS you take it out it =20
doesn't really matter), and adapt that to our use. (We used that one, =20=


as it generates SQL parse trees out of queries, which we were after, =20
it's based on yacc/lex so we can easily adopt different SQL dialects, =20=


and it looks to be quite easy to take out of the code base). There are =20=

few other SQL parsers that are around, written in different languages.

SQL is not the easiest thing to parse because of the number of dialects =20=

and features that exist in one but not in other implementation. Some =20
keywords can be at different places in the query (meaning different =20
things), and there are multiple ways of writing the same query, so it =20=


is hard to anchor on keywords (such as FROM, JOIN, etc).

Regards,
Mayo

On Jun 3, 2004, at 12:55, Jeff Kenton wrote:


As you have found, XSLT isn't necessarily the best tool for this job. XSLT 2.0 is somewhat better, because it has regular expression support.


But, the real question is, what is your application? Would Perl, or lex (with or without yacc), or just C be a better tool for you here?

xptm@xxxxxxx wrote:
Hi guys:
I have a string like
$select = SELECT * FROM aTable WHERE aColumn='something' ORDER BY anotherColumn
and want to parse this to variables such
fields = "*"
from = "aTable"
where = "aColumn='something' "
order = "anotherColumn"
so i made this:
<xsl:attribute name="fields">
<xsl:value-of
select="substring-before(substring-after($select,'SELECT'),'FROM')"/>
</xsl:attribute>
<xsl:attribute name="from">
<xsl:value-of
select="substring-before(substring-after($select,'FROM'),'WHERE')"/>
</xsl:attribute>
<xsl:attribute name="where">
<xsl:value-of
select="substring-before(substring-after($select,'WHERE'),'ORDER BY')"/>
</xsl:attribute>
<xsl:attribute name="order">
<xsl:value-of select="substring-after($select,'ORDER BY')"/>
</xsl:attribute>
This works, off-course, when $select is writen in that way, but if it is, for
instance
SELECT * FROM aTable ORDER BY anotherColumn
SELECT * FROM aTable ORDER BY anotherColumn WHERE aColumn='something'
and worst
SELECT * FROM aTable WHERE aColumn=(SELECT aColumn FROM anotherTable WHERE
anotherColumn='somethingelse')
then it won't work. Of course i can put a lot of xsl:if and xsl:when, but
hopefuly there's another way to do it.
Someone has any ideia?
O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--

--


----------------------------------------------------------------------- --
= Jeff Kenton Consulting and software development =
= http://home.comcast.net/~jeffrey.kenton =
----------------------------------------------------------------------- --





--+------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/ or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx> --+--



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.