/***** * * TOra - An Oracle Toolkit for DBA's and developers * Copyright (C) 2003-2005 Quest Software, Inc * Portions Copyright (C) 2005 Other Contributors * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; only version 2 of * the License is valid for this program. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * As a special exception, you have permission to link this program * with the Oracle Client libraries and distribute executables, as long * as you follow the requirements of the GNU GPL in regard to all of the * software in the executable aside from Oracle client libraries. * * Specifically you are not permitted to link this program with the * Qt/UNIX, Qt/Windows or Qt Non Commercial products of TrollTech. * And you are not permitted to distribute binaries compiled against * these libraries without written consent from Quest Software, Inc. * Observe that this does not disallow linking to the Qt Free Edition. * * You may link this product with any GPL'd Qt library such as Qt/Free * * All trademarks belong to their respective owners. * *****/ #include "utils.h" #include "toconnection.h" #include "tohighlightedtext.h" #include "tosqlparse.h" #include #include #ifdef TOPARSE_DEBUG #include bool toMonolithic(void) { return false; } void printStatement(toSQLParse::statement &stat, int level) { for (int i = 0;i < level;i++) printf(" "); switch (stat.Type) { case toSQLParse::statement::Block: printf("Block:"); break; case toSQLParse::statement::Statement: printf("Statement:"); break; case toSQLParse::statement::List: printf("List:"); break; case toSQLParse::statement::Keyword: printf("Keyword:"); break; case toSQLParse::statement::Token: printf("Token:"); break; case toSQLParse::statement::Raw: printf("Raw:"); break; } printf("%s (%d)\n", (const char *)stat.String, stat.Line); if (!stat.Comment.isNull()) { for (int i = 0;i < level;i++) printf(" "); printf("Comment:%s\n", (const char *)stat.Comment); } for (std::list::iterator i = stat.subTokens().begin(); i != stat.subTokens().end(); i++) printStatement(*i, level + 1); } int main(int argc, char **argv) { QString res = "\n" "create table test ( col varchar(12) );\n" "insert into prova3 (prova)\n" "values ('This insert contains a ''\n" "and now it goes to new line');\n" "create or replace PROCEDURE prova1\n" "is\n" "v_tmp NUMBER(1);\n" "begin\n" "begin\n" "select 0 into v_tmp from dual;\n" "exception\n" "when 1 = 1 then\n" " v_tmp := 'Dadum';\n" "when others then\n" "if sqlcode=0 then\n" "null;\n" "else\n" "null;\n" "end if;\n" "end;\n" "\n" "if v_tmp=0 then\n" "null;\n" "end if;\n" "end;" "comment on column prova1.prova1 is 'This comment is\n" "on more than one line';\n" "PACKAGE oasSIMActivation AS\n" " FUNCTION ParseCommand(Command VARCHAR2,inICC VARCHAR2,Param VARCHAR2) RETURN VARCHAR2;\n" "\n" " PROCEDURE InsertActions(inCommandType VARCHAR2,\n" " Sim oasSIM%ROWTYPE,\n" " inParam VARCHAR2);\n" "\n" " PROCEDURE InsertActions(CommandType VARCHAR2,\n" " inICC VARCHAR2,\n" " inParam VARCHAR2);\n" "\n" " PROCEDURE InsertActions(inCommandType VARCHAR2,\n" " Service oasService%ROWTYPE);\n" "\n" " PROCEDURE InsertActions(CommandType VARCHAR2,\n" " inCustomerID NUMBER,\n" " inSubID NUMBER,\n" " inServiceType VARCHAR2,\n" " Param VARCHAR2);\n" "END;\n" "DECLARE\n" "grade CHAR(1);\n" "appraisal VARCHAR2(20);\n" "BEGIN\n" "CASE grade\n" "WHEN 'A' THEN 'Excellent'\n" "WHEN 'B' THEN 'Very Good'\n" "WHEN 'C' THEN 'Good'\n" "WHEN 'D' THEN 'Fair'\n" "WHEN 'F' THEN 'Poor'\n" "ELSE 'No such grade'\n" "END;\n" "IF appraisal IS NULL THEN\n" "NULL;\n" "END IF;\n" "END;\n" "\n" "BEGIN\n" "IF 1 == 1 THEN\n" "NULL;\n" "END IF;\n" "IF appraisal IS NULL THEN\n" "NULL;\n" "ELSE\n" "SELECT CASE WHEN dummy='X' THEN 'A' ELSE 'B' END, 2 FROM dual;\n" "END IF;\n" "END;\n" "\n" "select count(case when dummy = 'Y' then dummy\n" " else null end) as tot_str\n" "from dual;\n" "\n" "SET TRANSACTION READ ONLY\n" "\n" "PROMPT Hello\n" "\n" "/* Test comment\n" "*/\n" "INSERT INTO cdrProcess(ProcessID,\n" " StartDate,\n" " EnvDate,\n" " ProgramID,\n" " OSUser,\n" " SystemUser,\n" " ExecName,\n" " ExecVersion,\n" " ExecParameters,\n" " HostName)\n" "VALUES (:1,\n" " SYSDATE,\n" " SYSDATE,\n" " :2,\n" " :3,\n" " :4,\n" " :5,\n" " :6,\n" " :7,\n" " :8);\n" "\n" "CREATE or REPLACE Procedure TEST_SPR\n" "(\n" " IN_TICKET_NUM IN VARCHAR2\n" ")\n" "IS\n" "\n" "BEGIN\n" "\n" "BEGIN\n" "\n" "for cur_rec in (select emp_id from employees) loop\n" "\n" " update employees set emp_id = emp_id + 1\n" " where emp_id = cur_rec.emp_id;\n" " commit;\n" "end loop;\n" " \n" "END;\n" "END TEST_SPR;\n" "\n" "SELECT owner,\n" " OBJECT,\n" " TYPE FROM v$access\n" " WHERE sid=:f1\n" " ORDER BY owner,\n" " OBJECT,\n" " TYPE;\n" "\n" "CREATE TABLE ess.EssCalLog (\n" " CalID CHAR(5) NOT NULL, -- Calender type\n" " SeqID NUMBER(8) NOT NULL,\n" " ActStt CHAR(1) NOT NULL\n" " CONSTRAINT EssCalLog_CK_ActStt CHECK (ActStt IN ('A','D') ),\n" " LogRun CHAR(1) NOT NULL -- Should runs of this type be logged\n" " CONSTRAINT EssCalLog_CK_LogRun CHECK (LogRun IN ('Y','N') ),\n" " PrcID NUMBER(8) NOT NULL\n" " CONSTRAINT EssCalDay_FK_PrcID REFERENCES ess.EssPrc(PrcID),\n" " Dsc VARCHAR2(4000) NOT NULL, -- Description of this type\n" " CONSTRAINT EssCal_PK PRIMARY KEY (CalID,SeqID)\n" " USING INDEX TABLESPACE Index02 -- A Comment\n" ");\n" "-- Another comment\n" "\n" "CREATE OR REPLACE procedure spTuxGetAccData (oRet OUT NUMBER,\n" " oNumSwt OUT NUMBER)\n" "IS\n" " vYear CHAR(4);\n" "BEGIN\n" " <