1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CONNECTIVITY_SQLSCAN_HXX
28 #define _CONNECTIVITY_SQLSCAN_HXX
29 
30 #include <stdarg.h>
31 #include "connectivity/IParseContext.hxx"
32 #include "connectivity/dbtoolsdllapi.hxx"
33 
34 namespace connectivity
35 {
36 	//==========================================================================
37 	//= OSQLScanner
38 	//==========================================================================
39 	/** Scanner for SQL92
40 	*/
41 	class OOO_DLLPUBLIC_DBTOOLS OSQLScanner
42 	{
43 		const IParseContext*	m_pContext;					// context for parse, knows all international stuff
44 		::rtl::OString			m_sStatement;			    // statement to parse
45 		::rtl::OUString			m_sErrorMessage;
46 
47 		sal_Int32				m_nCurrentPos;             // next position to read from the statement
48 		sal_Bool				m_bInternational;		   // do we have a statement which may uses
49 		sal_Int32				m_nRule;				   // rule to be set
50 
51 	public:
52 		OSQLScanner();
53 		virtual ~OSQLScanner();
54 
55 		inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () )
56 			{ return ::rtl_allocateMemory( nSize ); }
57 		inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW( () )
58 			{ return _pHint; }
59 		inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () )
60 			{ ::rtl_freeMemory( pMem ); }
61 		inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW( () )
62 			{  }
63 
64 		virtual sal_Int32 SQLyygetc(void);
65 		virtual void SQLyyerror(char *fmt);
66 		virtual void output(sal_Int32) { OSL_ASSERT("Internal error in sdblex.l: output not possible"); }
67 		virtual void ECHO(void) { OSL_ASSERT("Internal error in sdblex.l: ECHO not possible"); }
68 		virtual IParseContext::InternationalKeyCode getInternationalTokenID(const char* sToken) const;
69 
70 		// setting the new information before scanning
71 		void prepareScan(const ::rtl::OUString & rNewStatement, const IParseContext* pContext, sal_Bool bInternational);
72 		const ::rtl::OUString& getErrorMessage() const {return m_sErrorMessage;}
73 		::rtl::OString getStatement() const { return m_sStatement; }
74 
75 		sal_Int32 SQLlex();
76 		// set this as scanner for flex
77 		void setScanner(sal_Bool _bNull=sal_False);
78 		// rules settings
79 		void SetRule(sal_Int32 nRule) {m_nRule = nRule;}
80 		sal_Int32	GetCurrentRule() const;
81 		sal_Int32	GetGERRule() const;
82 		sal_Int32	GetENGRule() const;
83 		sal_Int32	GetSQLRule() const;
84 		sal_Int32	GetDATERule() const;
85 		sal_Int32	GetSTRINGRule() const;
86         inline sal_Int32 GetCurrentPos() const { return m_nCurrentPos; }
87 	};
88 }
89 
90 #endif
91