dbTalk Databases Forums  

Parse an SQL file

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Parse an SQL file in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul Horan[TeamSybase]
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 08:15 AM






DBISQL will run the statements in the order they appear in the file. If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

<dpillay.lists (AT) gmail (DOT) com> wrote

Quote:
All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.




Reply With Quote
  #2  
Old   
dpillay.lists@gmail.com
 
Posts: n/a

Default Parse an SQL file - 10-29-2007 , 08:35 AM






All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.


Reply With Quote
  #3  
Old   
Volker Barth
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 09:38 AM



Dinesh,

or are you thinking of a way to check for syntax errors without executing
the queries?
Then dbisql -x should do.

HTH
Volker

"Paul Horan[TeamSybase]" <phoran AT sybase DOT com> wrote in
news:4725f91d (AT) forums-1-dub (DOT) ..
Quote:
DBISQL will run the statements in the order they appear in the file. If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

dpillay.lists (AT) gmail (DOT) com> wrote in message
news:1193668524.550137.170140 (AT) q3g2000prf (DOT) googlegroups.com...
All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.






Reply With Quote
  #4  
Old   
dpillay.lists@gmail.com
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 10:56 AM



On Oct 29, 7:15 pm, "Paul Horan[TeamSybase]" <phoran AT sybase DOT
com> wrote:
Quote:
DBISQL will run the statements in the order they appear in the file. If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

dpillay.li... (AT) gmail (DOT) com> wrote in message

news:1193668524.550137.170140 (AT) q3g2000prf (DOT) googlegroups.com...

All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.
What I actually needed was a way to parse the SQL so that I can
control the transaction. Its not 1 file I'm talking about, its
multiples of them.

Is there any way to do it or is dbisql the only option. I was thinking
one way could be to concatenate the files into one and then feed them
to dbisql.

- Dinesh.



Reply With Quote
  #5  
Old   
dpillay.lists@gmail.com
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 11:00 AM



On Oct 29, 8:38 pm, "Volker Barth" <No_VBarth (AT) Spam_GLOBAL-FINANZ (DOT) de>
wrote:
Quote:
Dinesh,

or are you thinking of a way to check for syntax errors without executing
the queries?
Then dbisql -x should do.

HTH
Volker

"Paul Horan[TeamSybase]" <phoran AT sybase DOT com> wrote innews:4725f91d (AT) forums-1-dub (DOT) ..

DBISQL will run the statements in the order they appear in the file. If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

dpillay.li... (AT) gmail (DOT) com> wrote in message
news:1193668524.550137.170140 (AT) q3g2000prf (DOT) googlegroups.com...
All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.
I'll paint a bigger picture. My application needs to upgrade the DB to
sync it with the app version. We have currently say 10 sql files that
push the DB schema from version 1 to version 2. What we currently are
doing is to run dbisql on each of those 10 files to upgrade. But in
case we face an issue during say the 5th file, we would have committed
till the 4th and hence negate a rollback.

I'm considering the following options:-

1. Concatenate the files into 1 and then execute dbisql on that one
file. The files are different for logical separations only. Also, does
DBISQL auto-commit on a DDL statement?

2. Parse those 10 files and then execute the parsed SQL over a jdbc
connection to the DB during which I can control commits.

Thoughts?

- Dinesh.



Reply With Quote
  #6  
Old   
Breck Carter [Team iAnywhere]
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 11:37 AM



DDL statements like CREATE and ALTER all do automatic commits. If one
of these statements *fails* during execution, the changes are undone
because each statement is atomic, but when one of these statements
succeeds its effect is permanent. So, you don't really have any
control over the transactions when doing DDL.

As Paul suggested, one approach is to wrap each DDL statement in an IF
so the script can be run against any database; e.g., not upgraded,
partially upgraded or fully upgraded already. Write each IF so that it
independently checks the current "state" of the database. Then just
put everything in one script and run it... if it fails, fix the script
and re-run it.

Here are some template examples:

IF NOT EXISTS ( SELECT * FROM SYSTABLE
WHERE SYSTABLE.table_name = 't' ) THEN
CREATE TABLE t ...
ALTER TABLE t ADD CONSTRAINT ...
END IF;

IF NOT EXISTS ( SELECT *
FROM SYSPUBLICATION
INNER JOIN SYSARTICLE
ON SYSARTICLE.publication_id
= SYSPUBLICATION.publication_id
INNER JOIN SYSTABLE
ON SYSTABLE.table_id = SYSARTICLE.table_id
WHERE SYSPUBLICATION.publication_name = 'p'
AND SYSTABLE.table_name = 't' ) THEN
ALTER PUBLICATION p ADD TABLE t ...
END IF;

IF NOT EXISTS ( SELECT * FROM SYSTABLE INNER JOIN SYSCOLUMN
ON SYSCOLUMN.table_id = SYSTABLE.table_id
WHERE SYSTABLE.table_name = 't'
AND SYSCOLUMN.column_name = 'c' ) THEN
ALTER TABLE t ADD c ...
ALTER PUBLICATION p MODIFY TABLE t ...
END IF;

Breck


On Mon, 29 Oct 2007 10:00:45 -0700, "dpillay.lists (AT) gmail (DOT) com"
<dpillay.lists (AT) gmail (DOT) com> wrote:

Quote:
On Oct 29, 8:38 pm, "Volker Barth" <No_VBarth (AT) Spam_GLOBAL-FINANZ (DOT) de
wrote:
Dinesh,

or are you thinking of a way to check for syntax errors without executing
the queries?
Then dbisql -x should do.

HTH
Volker

"Paul Horan[TeamSybase]" <phoran AT sybase DOT com> wrote innews:4725f91d (AT) forums-1-dub (DOT) ..

DBISQL will run the statements in the order they appear in the file. If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

dpillay.li... (AT) gmail (DOT) com> wrote in message
news:1193668524.550137.170140 (AT) q3g2000prf (DOT) googlegroups.com...
All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.

I'll paint a bigger picture. My application needs to upgrade the DB to
sync it with the app version. We have currently say 10 sql files that
push the DB schema from version 1 to version 2. What we currently are
doing is to run dbisql on each of those 10 files to upgrade. But in
case we face an issue during say the 5th file, we would have committed
till the 4th and hence negate a rollback.

I'm considering the following options:-

1. Concatenate the files into 1 and then execute dbisql on that one
file. The files are different for logical separations only. Also, does
DBISQL auto-commit on a DDL statement?

2. Parse those 10 files and then execute the parsed SQL over a jdbc
connection to the DB during which I can control commits.

Thoughts?

- Dinesh.
--
Breck Carter [Team iAnywhere]
RisingRoad SQL Anywhere and MobiLink Professional Services
www.risingroad.com
The book: http://www.risingroad.com/SQL_Anywhe...ers_Guide.html
breck.carter (AT) risingroad (DOT) com


Reply With Quote
  #7  
Old   
Paul Horan[TeamSybase]
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 12:56 PM



We did this for hundreds of customers at my previous employer... The
approach we came up with was to have individual .SQL files for each
"object" - table, proc, function, view, etc... Each would have a statement
like:
IF not exists (select * from sys.syscolumns where table_name = 'myTable' and
column_name = 'myNewColumn' ) then
ALTER TABLE myTable...
END IF;

We also had one "controller" .SQL file, that did nothing but READ statements
against those individual .SQL files. So, during the course of the
month/quarter/release cycle, each developer would be responsible for
creating the .SQL file that did the work, and modifying the controller .SQL
file that invoked it.

Paul Horan[TeamSybase]

<dpillay.lists (AT) gmail (DOT) com> wrote

Quote:
On Oct 29, 7:15 pm, "Paul Horan[TeamSybase]" <phoran AT sybase DOT
com> wrote:
DBISQL will run the statements in the order they appear in the file. If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

dpillay.li... (AT) gmail (DOT) com> wrote in message

news:1193668524.550137.170140 (AT) q3g2000prf (DOT) googlegroups.com...

All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.

What I actually needed was a way to parse the SQL so that I can
control the transaction. Its not 1 file I'm talking about, its
multiples of them.

Is there any way to do it or is dbisql the only option. I was thinking
one way could be to concatenate the files into one and then feed them
to dbisql.

- Dinesh.




Reply With Quote
  #8  
Old   
Andrew Giulinn
 
Posts: n/a

Default Re: Parse an SQL file - 10-29-2007 , 04:07 PM



DDL would not (technically) be described as "queries". Most (all?) DDL
autocommits, so one can't talk about the statements being in a
"transaction".

AFAIK therefore, your only choice is to follow these steps:

(1) create a backup of your database
(2) run the script, logging any errors
(3) if any errors in (2), replace the (incompletely) altered database with
the backup (this is your rollback) and report the errors, fix the script and
then start from (1) again.

Cheers

--
Andrew Giulinn
Senior Analyst/Programmer
Integrated Aviation Software Pty Ltd

<dpillay.lists (AT) gmail (DOT) com> wrote

Quote:
On Oct 29, 8:38 pm, "Volker Barth" <No_VBarth (AT) Spam_GLOBAL-FINANZ (DOT) de
wrote:
Dinesh,

or are you thinking of a way to check for syntax errors without executing
the queries?
Then dbisql -x should do.

HTH
Volker

"Paul Horan[TeamSybase]" <phoran AT sybase DOT com> wrote
innews:4725f91d (AT) forums-1-dub (DOT) ..

DBISQL will run the statements in the order they appear in the file.
If
you want to alter the flow of the batch, you can use conditional logic
(IF/THEN/ELSE statements). Am I not understanding your requirements??

Paul Horan[TeamSybase]

dpillay.li... (AT) gmail (DOT) com> wrote in message
news:1193668524.550137.170140 (AT) q3g2000prf (DOT) googlegroups.com...
All,

Given the situation that I have an SQL file with multiple queries,
does Sybase provide a way to parse that file and execute each of the
queries in turn?

The individual queries themselves are mutually exclusive from the
rest
but being able to parse properly (say how to parse a "create
procedure" statement) is the actual problem.

- Dinesh.

I'll paint a bigger picture. My application needs to upgrade the DB to
sync it with the app version. We have currently say 10 sql files that
push the DB schema from version 1 to version 2. What we currently are
doing is to run dbisql on each of those 10 files to upgrade. But in
case we face an issue during say the 5th file, we would have committed
till the 4th and hence negate a rollback.

I'm considering the following options:-

1. Concatenate the files into 1 and then execute dbisql on that one
file. The files are different for logical separations only. Also, does
DBISQL auto-commit on a DDL statement?

2. Parse those 10 files and then execute the parsed SQL over a jdbc
connection to the DB during which I can control commits.

Thoughts?

- Dinesh.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.