Parsing SQL Statements

Has anyone run across any code or utilities for getting information from
complex SQL statements?  I want to be able to collect the table names and
column names from SQL statements with complex sub-queries.  Any help or
pointers would be appreciated.

joe white
joe@lemma.net


0
Joe
1/19/1999 2:39:57 PM
sybase.powerbuilder.general 62418 articles. 17 followers. Follow

5 Replies
376 Views

Similar Articles

[PageSpeed] 29

Joe --

Check out n_cst_sql in the PFC.  It has a function that will break up a sql
command into individual components (select,from,where,order,...) and another
that will recombine the components into a single command.  One caveat about
this.  When I used the 5.0.3 version, it had problems where nested selects
were concerned.  It assumes that the first 'from' statement it finds marks
the end of the 'select' clause.  If you're using a nested select in the
'select' clause, then it uses the 'from' in the nested select as the end of
the 'select' clause for the main SQL.

HTH

Ron Gallagher, CPDP
Atlanta, GA
rongallagher@mindspring.com



Joe White wrote in message <7uf##l7Q#GA.189@forums.powersoft.com>...
>Has anyone run across any code or utilities for getting information from
>complex SQL statements?  I want to be able to collect the table names and
>column names from SQL statements with complex sub-queries.  Any help or
>pointers would be appreciated.
>
>joe white
>joe@lemma.net
>
>


0
Ron
1/19/1999 2:46:14 PM
Thanks Ron for the (scarily) speedy response.  It never even occured to us
that the PFC would support such functionality.  We appreciate it.

jw


Ron Gallagher wrote in message ...
>Joe --
>
>Check out n_cst_sql in the PFC.


0
Joe
1/19/1999 3:44:52 PM
And furthermore, if a subquery is in the FROM clause and has a WHERE clause, the
parsing service thinks that the WHERE clause in the subquery is the WHERE clause
of the main SQL...

I have taken the PFC of_Parse function and overridden it, then added my own code
so that it works with subqueries.  My method counts parenthesis in the SQL.  So,
as long as all subqueries are in parens (which I think is the SQL standard) then
you can use it.  Let me know if you would like me to send you a copy of the
function.


Ron Gallagher wrote:

> Joe --
>
> Check out n_cst_sql in the PFC.  It has a function that will break up a sql
> command into individual components (select,from,where,order,...) and another
> that will recombine the components into a single command.  One caveat about
> this.  When I used the 5.0.3 version, it had problems where nested selects
> were concerned.  It assumes that the first 'from' statement it finds marks
> the end of the 'select' clause.  If you're using a nested select in the
> 'select' clause, then it uses the 'from' in the nested select as the end of
> the 'select' clause for the main SQL.
>
> HTH
>
> Ron Gallagher, CPDP
> Atlanta, GA
> rongallagher@mindspring.com
>
> Joe White wrote in message <7uf##l7Q#GA.189@forums.powersoft.com>...
> >Has anyone run across any code or utilities for getting information from
> >complex SQL statements?  I want to be able to collect the table names and
> >column names from SQL statements with complex sub-queries.  Any help or
> >pointers would be appreciated.
> >
> >joe white
> >joe@lemma.net
> >
> >

--
******************************************************
Kevin Healey
khealey@hq.caci.com
[To reply, remove ".NOSPAM" from the end of my e-mail]


0
Kevin
1/19/1999 4:05:29 PM
Joe,

If you are looking to do this from within your application, have a look at
the n_cst_sql object in the PFC.  It's not perfect (it has some problems
with sub-queries), but it should get you pointed in the right direction.

If you are looking to get a list of all of the tables your application uses,
have a look at PB Code Analyzer at:
http://www.ascensionlabs.com/pbcodeanalyzer.htm

HTH,
Greg

--
_____________________________
Gregory R. George
Greg_George@AscensionLabs.com
Ascension Labs, LLC
www.AscensionLabs.com

Joe White wrote in message <7uf##l7Q#GA.189@forums.powersoft.com>...
>Has anyone run across any code or utilities for getting information from
>complex SQL statements?  I want to be able to collect the table names and
>column names from SQL statements with complex sub-queries.  Any help or
>pointers would be appreciated.
>
>joe white
>joe@lemma.net
>
>


0
Gregory
1/19/1999 4:29:02 PM
Kevin -

I just ran into this problem.  Would you mind posting your copy of the
function?

Maintain,
Babul

Kevin Healey wrote in message <36A4AD49.B37FB272@hq.caci.com.NOSPAM>...
>And furthermore, if a subquery is in the FROM clause and has a WHERE
clause, the
>parsing service thinks that the WHERE clause in the subquery is the WHERE
clause
>of the main SQL...
>
>I have taken the PFC of_Parse function and overridden it, then added my own
code
>so that it works with subqueries.  My method counts parenthesis in the SQL.
So,
>as long as all subqueries are in parens (which I think is the SQL standard)
then
>you can use it.  Let me know if you would like me to send you a copy of the
>function.
>
>
>Ron Gallagher wrote:
>
>> Joe --
>>
>> Check out n_cst_sql in the PFC.  It has a function that will break up a
sql
>> command into individual components (select,from,where,order,...) and
another
>> that will recombine the components into a single command.  One caveat
about
>> this.  When I used the 5.0.3 version, it had problems where nested
selects
>> were concerned.  It assumes that the first 'from' statement it finds
marks
>> the end of the 'select' clause.  If you're using a nested select in the
>> 'select' clause, then it uses the 'from' in the nested select as the end
of
>> the 'select' clause for the main SQL.
>>
>> HTH
>>
>> Ron Gallagher, CPDP
>> Atlanta, GA
>> rongallagher@mindspring.com
>>
>> Joe White wrote in message <7uf##l7Q#GA.189@forums.powersoft.com>...
>> >Has anyone run across any code or utilities for getting information from
>> >complex SQL statements?  I want to be able to collect the table names
and
>> >column names from SQL statements with complex sub-queries.  Any help or
>> >pointers would be appreciated.
>> >
>> >joe white
>> >joe@lemma.net
>> >
>> >
>
>--
>******************************************************
>Kevin Healey
>khealey@hq.caci.com
>[To reply, remove ".NOSPAM" from the end of my e-mail]
>
>


0
Babul
1/20/1999 4:43:02 AM
Reply:

Similar Artilces:

RE: SQL::Statement cannot parse valid Postgresql statement
> From: Terrence Brannon [mailto:metaperl@mac.com] > > On Monday, December 10, 2001, at 09:16 AM, Jeff Zucker wrote: > > > Terrence Brannon wrote: > >> > >> The following SQL is not parseable by SQL::Statement: > >> > >> INSERT > >> INTO thot_log (thot_fk,thot_type_fk,thot_temporality_fk,date) > >> VALUES (?,?,?,CURRENT_TIMESTAMP) > > What I have is a program which reads a SQL statement from a file. > It parses it with SQL::Statement, then it prepares this > statement, then does an ...

parsing SQL statement
Anyone having suggestion parsing SQL statement? It should able to parse: BLA BALA BALA... VALUES( 'abcd efg',,999, 'some \"STRING\" and \'STR2\' STR3',,,, 'abcd, def, fghi' ) I'm using tr and then split by "," but it will fall when seeing comma inside the single quote. Thanks. --budhi On Fri, 2008-05-30 at 19:24 +0700, beast wrote: > Anyone having suggestion parsing SQL statement? > > It should able to parse: > > BLA BALA BALA... > > VALUES( > 'abcd efg',,999, 'so...

sql statement parsing
hi guys, how can i parse the where clause in an SQL::Statement object instance? $statement = SQL::Statement->new("select 1,2,3 from table where x=y"); now when i do this: $where = $stmt->where(); it gives me error: Can't locate object method "where" via package "SQL::Statement" (perhaps you for got to load "SQL::Statement"?) at blah line 34. any idea? thanks -- Hytham Shehab At 07:34 PM 8/10/02 +0300, Hytham Shehab wrote: > how can i parse the where clause in an SQL::Statement object instance? >$statement = S...

General SQL statement?
Once I have a table in SQLAnywhere 5.5.04, is there any way to generate a SQL statement that would have created it? Someone else needs to recreate the structure of my table and I'd like to send them a SQL statement that they could use to do so. One way to do it is to (for example, you need foo_table TABLE): 1) unload database (can be done from Sybase Central) into foo.sql 2) copy "CREATE TABLE foo_table" command where you need it... Petar Rick Charnes wrote: > > Once I have a table in SQLAnywhere 5.5.04, is there any way to generate > a SQL stateme...

SQL statement and If statement
I've problem, it's in sqlcommand it's in "where" condition, which if it's exist in sql the "ELSE" not work, and if the condition not in sqlcommand the "ELSE" appear, could someone help  it's in selectcommand.CommandText = "SELECT Weekno FROM Weeks where Weekno='" + Weekno.Text + "'" if i delete the condition the " ELSE " appear. otherwise it's not appear whole code Dim myconnection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\football.mdf;Integrated S...

wrong parsing SQL statements
This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C2A5ED.5D254130 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: quoted-printable I have a complex SQL Statements like this: SELECT pms_list_temp.lot_no, pms_list_temp.wo_no, =20 pms_list_temp.seq, =20 pms_list_temp.ord_seq2, pms_list_temp.m_itemno, pms_list_temp.delivery_name,=20 pms_list_temp.dep_no, pms_list_temp.wo_qty, pms_list_temp.dship, pms_list_temp.work_center, =20 pms_list_temp.work_group, pms_list_temp.catch_date, pms_l...

Showing parsed SQL statement?
In classic ASP, I used to be able to do a response.write(SQL) to view a parsed SQL statement. Can I do this in .NET? I'm using a SQLDataSource container and want to see what I'm passing through in my INSERT statement. All I can seem to get are @parameters.Thanks!Stace Add OnInserting="SqlDataSource1_Inserting"  to your SqlDataSource and check the InsertCommand and parameter values as shown below. Another way is to use SQL Profiler from SSMS (SQL Server Management Studio) to trace what has been passed to SQL Server.  protected void SqlDataSource1_Inserting(objec...

Parsing columns from a sql statement
Hi, How I could get the name of the columns from a string variable that has a sql statement? "select this, that, (to_date('02-02-04','mm-dd-yy')) from table" I want to obtain the column names "this", "that" and (to_date('02-02-04','mm-dd-yy')) Thank you I would suggest to use the POS and MID functions. Joseph wrote: > Hi, How I could get the name of the columns from a string > variable that has a sql statement? > > "select this, that, (to_date('02-02-04','mm-dd-yy')) from >...

Parsing complex datawindow SQL statements
Hello, I need to modify the where clause of a datawindow SQL expression at runtime. This cannot be done by using the using retrieval arguments, so I need to modify the TABLE.SELECT of the datawindow. In PFC there is a user object that does this, but it doens't handle the nested queries in the SELECT or WHERE clause. I have been looking around on the internet for hints that point me in the right direction, but I haven't found anything yet. Dipesh Panchal has posted a reply back in december 98 stating that he has done this, but there is no sample code nor details about the way...

PARSE SQL STATEMENT (Changing Where part)
Dear All, I wonder if there is a way to change the Where statement of a Sql statement withouth writing a custom code? For instance I need to change the "select * from employees where serial>100 order by serial" to "select * from employees where EmploymentDate is not null order by serial" Thanks a lot Aref K. Hi, Have that portion of "where ...." in a variable and then you can concatenate it to the query string. Like as follows:- Dim strWhrCon as string // then you can assign the where condition to this variable. strsql =...

Parsing a textbox for use in a SQL statement
How can I take the value of a textbox and parse out the indivdual words to use in a WHERE statement without having to result to having the user placing a special charater in between word?  I'm pulling the text out and doing the data pull in my code behind VB.net page. Thanks, Ty  you can use the string.split method and specify your own delimiter. http://msdn.microsoft.com/en-us/library/system.string.split.aspx or you can use the string.replace method and replace spaces with whatever character you want to delimit the words in the textbox Do you mean something like, the us...

Adding an IF Statement to the SQL Statement
I have the following tables and SQL statment which works out a league table for me from the given results. I am now trying to add a bit more to this: If the Walkover column = 1 then that row will be a home walkover meaning that the score will be 0(Home Score) - 0(Away Score) but the home team will recieve 3 points, and away team recieves 0 points, win column will be 1 and the played colum will be 1 as well.If the Walkover column = 2 then that row will be a home walkover meaning that the score will be 0(Home Score) - 0(Away Score) but the away team will recieve 3 po...

Problem parsing SQL Statement with backslash and parameter
Hi We are migration from Ado to Firedac (for MSSQL) and noticed that not all existing SQL starements work as before. As an example such a statement won't work anymore (resulting in "Incorret syntax near ':'"): insert into table (field1, field2, field3) values ('test', '\\Server\Share\', :paField3Parameter). Is there a fix or another way how to change the behaviour of the component without the need to change the SQL statements? Thanks FireDAC by default considers '\' as an escape character. Because you are migrating from ADO and do n...

SQL Logging SQL Statement
Hi at All!! I use ASA 7 so I'd like to know if there is a way to logging the sql instruction that database server dbsrv7, receive from clients ? I need this because a client that use odbc connection after performing an insert into a table, the client receive the Message: "SQL truncate". I need to know the field on the table that generate this warning!! Thanks in advance Massimo The tool that does this is called "request-level logging" and in V7 you have to enable it from the command line when you start the server, using the -zr (and optionally -zo) c...

Web resources about - Parsing SQL Statements - sybase.powerbuilder.general

User:Jimbo Wales/Statement of principles - Wikipedia, the free encyclopedia
As we move forward with software and social changes, I think it is imperative that I state clearly and forcefully my views on openness and the ...

Category:Articles containing potentially dated statements from June 2006 - Wikipedia, the free encyclopedia ...
This is an administration category . It is used for administration of the Wikipedia project and is not part of the encyclopedia. It contains ...

Peyton Manning Issues Statement Denying Doping Allegations - Bleacher Report
Denver Broncos quarterback Peyton Manning has issued a statement strongly denying that he received human growth hormone from an anti-aging clinic ...

Madonna says Sean Penn never assaulted her in court statement, denying previous reports
... of the allegations that have surfaced over the years accusing Sean of incidents of physical assault and abuse against me," she said in a statement ...

Statement from Premier League’s Crystal Palace Football Club
Crystal Palace Football Club is delighted to announce that it has today signed a deal with investors Josh Harris and David Blitzer. The deal ...

FOMC Statement: Fed Funds Rate target range increased to 1/4 to 1/2 percent
FOMC Statement: Information received since the Federal Open Market Committee met in October suggests that economic activity has been expanding ...

Chicago police statement on double fatal police shooting - Chicago Tribune
Chicago police emailed the following statement to the media at about 9:45 the morning of Dec. 26, 2015, after an early morning police-involved ...

What changed in new Fed statement
This is a comparison of today's FOMC statement with the one issued after the Fed's previous policy-making meeting on Oct. 28.

Does Draymond feel Warriors have chance to make statement vs Cavs?
... Giants A's Sharks Warriors Kings 49ers Raiders Quakes Insiders More Tickets Shop Watch Does Draymond feel Warriors have chance to make statement ...

Rajon Rondo's Statement Looks A Lot Like Kobe Bryant's Statement
... pay after he called referee Bill Kennedy a “faggot” in a Dec. 3 game . (Kennedy publicly came out after the incident.) Rondo tweeted a statement, ...

Resources last updated: 12/28/2015 5:30:31 PM