os/persistentdata/persistentstorage/dbms/pcdbms/usql/UQ_STD.H
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/pcdbms/usql/UQ_STD.H	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,335 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <u32std.h>
    1.20 +#include "D32SQL.H"
    1.21 +#include "D32TABLE.H"
    1.22 +#include <e32math.h>
    1.23 +#include <s32mem.h>
    1.24 +#include "D32Assert.h"
    1.25 +
    1.26 +//Forward declarations
    1.27 +class TSqlParser2;
    1.28 +
    1.29 +// Classes defined
    1.30 +class TSqlToken;
    1.31 +class TSqlLexer;
    1.32 +class TSqlParser;
    1.33 +template <class T,class D> class TMatcher;
    1.34 +template <class T,class D> class TDesMatcher;
    1.35 +template <class T,class D> class TStreamMatcher;
    1.36 +template <class T,class D> class HMatcherPattern;
    1.37 +class CSqlCreateTableStatement;
    1.38 +class CSqlDropTableStatement;
    1.39 +class CSqlAlterTableStatement;
    1.40 +class CSqlCreateIndexStatement;
    1.41 +class CSqlDropIndexStatement;
    1.42 +
    1.43 +/**
    1.44 +parser classes
    1.45 +@internalComponent
    1.46 +*/
    1.47 +enum TSqlTokenType
    1.48 +	{
    1.49 +	ESqlNoToken=0,
    1.50 +//
    1.51 +	ESqlEos,
    1.52 +//
    1.53 +	ESqlIdentifier,
    1.54 +	ESqlLiteralInt,
    1.55 +	ESqlLiteralReal,
    1.56 +	ESqlLiteralTime,
    1.57 +	ESqlLiteralText,
    1.58 +	ESqlLiteralBlob,
    1.59 +//
    1.60 +	ESqlAsterisk,
    1.61 +	ESqlComma,
    1.62 +	ESqlLeftBracket,
    1.63 +	ESqlRightBracket,
    1.64 +	ESqlLess,
    1.65 +	ESqlLessEqual,
    1.66 +	ESqlEqual,
    1.67 +	ESqlGreaterEqual,
    1.68 +	ESqlGreater,
    1.69 +	ESqlNotEqual
    1.70 +	};
    1.71 +
    1.72 +/**
    1.73 +@internalComponent
    1.74 +*/
    1.75 +enum TSqlKeyword
    1.76 +	{
    1.77 +	ESqlNotKeyword=-1,
    1.78 +//
    1.79 +#define KEYWORD(s) ESqlKeyword_##s
    1.80 +#include "UQ_KEYWD.H"
    1.81 +#undef KEYWORD
    1.82 +	};
    1.83 +
    1.84 +class TSqlToken
    1.85 +/**
    1.86 +@internalComponent
    1.87 +*/
    1.88 +	{
    1.89 +	friend class TSqlLexer;
    1.90 +public:
    1.91 +	inline TBool operator==(TSqlTokenType aType) const;
    1.92 +	inline TBool operator!=(TSqlTokenType aType) const;
    1.93 +//
    1.94 +	inline void SetError(TInt aError);
    1.95 +	inline TInt Error() const;
    1.96 +//
    1.97 +	inline TSqlTokenType Type() const;
    1.98 +	inline const RSqlLiteral& Literal() const;
    1.99 +	inline RSqlLiteral& Literal();
   1.100 +private:
   1.101 +	inline TSqlTokenType operator=(TSqlTokenType aType);
   1.102 +private:
   1.103 +	TInt iType;
   1.104 +	RSqlLiteral iLiteral;
   1.105 +	};
   1.106 +
   1.107 +class TSqlLexer
   1.108 +/**
   1.109 +@internalComponent
   1.110 +*/
   1.111 +	{
   1.112 +public:
   1.113 +	TSqlLexer(const TDesC& aSql);
   1.114 +	inline TSqlTokenType NextToken(TSqlToken& aToken);
   1.115 +	static TSqlKeyword Keyword(const TSqlToken& aToken);
   1.116 +	static inline TBool IsKeyword(TSqlKeyword aKeyword,const TSqlToken& aToken);
   1.117 +	const TText* Next() const;
   1.118 +	void Set(const TText* aNext);	
   1.119 +private:
   1.120 +	TSqlTokenType GetIdentifier(TSqlToken& aToken);
   1.121 +	TSqlTokenType GetString(TSqlToken& aToken);
   1.122 +	TInt GetInteger(TInt64& aValue);
   1.123 +	TSqlTokenType GetNumber(TSqlToken& aToken);
   1.124 +	TSqlTokenType GetDate(TSqlToken& aToken);
   1.125 +	TSqlTokenType GetNextToken(TSqlToken& aToken);
   1.126 +	TSqlTokenType GetBlob(TSqlToken& aToken);
   1.127 +//
   1.128 +	static inline TSqlTokenType SqlError(TInt aError=KErrArgument);
   1.129 +	static TInt CompareKeyword(TInt aKeyword,const RSqlLiteral& aIdentifier);
   1.130 +private:
   1.131 +	const TText* iNext;
   1.132 +	const TText* iEnd;
   1.133 +	};
   1.134 +
   1.135 +class TSqlParser
   1.136 +/**
   1.137 +@internalComponent
   1.138 +*/
   1.139 +	{
   1.140 +	friend class TSqlParser2;
   1.141 +public:
   1.142 +	TSqlParser(const TDesC& aSql);
   1.143 +//
   1.144 +	CSqlQuery* QueryLC();
   1.145 +	CSqlSearchCondition* SearchConditionLC();
   1.146 +	CSqlDDLStatement* DDLStatementLC();
   1.147 +	CSqlDMLStatement* DMLStatementLC();
   1.148 +	Sql::TStatementType Type();
   1.149 +	TInt PatternFilter(const TDesC& aPattern,const TChar aEscape, TText *aNewPatternBuffer );
   1.150 +private:
   1.151 +	TSqlTokenType NextToken();
   1.152 +	CSqlSearchCondition* SqlError();
   1.153 +	inline TInt Error() const;
   1.154 +	static TSqlTokenType SqlErrorL();
   1.155 +//
   1.156 +	TSqlTokenType Parse(TSqlKeyword aKeyword);
   1.157 +	TSqlTokenType ParseL(TSqlTokenType aToken);
   1.158 +	TSqlTokenType ParseL(TSqlKeyword aKeyword);
   1.159 +	TSqlKeyword Keyword();
   1.160 +	TSqlTokenType RightBracketL();
   1.161 +	TSqlTokenType IdentifierL(TPtrC& aIdentifier);
   1.162 +	TPtrC IdentifierL();
   1.163 +	void EndL();
   1.164 +//
   1.165 +	TSqlTokenType ColumnNameL(RSqlColumnList& aList);
   1.166 +	TSqlTokenType ColumnListL(RSqlColumnList& aList);
   1.167 +	CSqlSearchCondition* SearchCondition(TInt aNot);
   1.168 +	CSqlSearchCondition* BooleanTerm(TInt aNot);
   1.169 +	CSqlSearchCondition* BooleanFactor(TInt aNot);
   1.170 +	CSqlSearchCondition* BooleanPrimary(TInt aNot);
   1.171 +	CSqlSearchCondition* Predicate(TInt aNot);
   1.172 +	void SortSpecificationL(CDbKey& aKey);
   1.173 +	CDbKey* SortSpecificationL();
   1.174 +	void DoQueryL(CSqlQuery& aQuery);
   1.175 +	CSqlSearchCondition* SearchConditionL();
   1.176 +//
   1.177 +	TSqlTokenType AddColumnSpecL(TDbCol& aDef);
   1.178 +	CSqlDDLStatement* CreateTableLC();
   1.179 +	CSqlDDLStatement* DropTableLC();
   1.180 +	CSqlDDLStatement* AlterTableLC();
   1.181 +	CSqlDDLStatement* CreateIndexLC(TBool aUnique);
   1.182 +	CSqlDDLStatement* DropIndexLC();
   1.183 +//
   1.184 +	TSqlTokenType ColumnValueL(CSqlValues& aValues);
   1.185 +	CSqlDMLStatement* InsertStatementLC();
   1.186 +	CSqlDMLStatement* UpdateStatementLC();
   1.187 +	CSqlDMLStatement* DeleteStatementLC();
   1.188 +private:
   1.189 +	TSqlLexer iSql;
   1.190 +	TSqlToken iToken;
   1.191 +	};
   1.192 +
   1.193 +
   1.194 +/**
   1.195 +LIKE evaluation support
   1.196 +@internalComponent
   1.197 +*/
   1.198 +enum TSegmentType {ENull,ESuccess,EStop,EBeginning,EEnd,EMiddle,ESkip,EEscape,EMask=0xf,EWild=0x80};
   1.199 +/**
   1.200 +@internalComponent
   1.201 +*/
   1.202 +const TInt KPatternGranularity=0x20;
   1.203 +
   1.204 +// If this value is changed class documentation must be updated.
   1.205 +// Namely, RDbDatabase and TDbQuery.
   1.206 +const TInt KMaxSegmentLength=0xff;
   1.207 +
   1.208 +template <class T,class D>
   1.209 +class HMatcherPattern
   1.210 +/**
   1.211 +@internalComponent
   1.212 +*/
   1.213 +	{
   1.214 +	friend class TMatcher<T,D>;
   1.215 +	typedef HMatcherPattern<T,D> TThis;
   1.216 +public:
   1.217 +	static HMatcherPattern<T,D>* NewL(const D& aPattern,TBool aEscape = EFalse);
   1.218 +	TInt MatchL(const D& aDes,const TTextOps& aTextOp) const;
   1.219 +	TInt MatchL(MStreamBuf& aBuf,TInt aLength,const TTextOps& aTextOp) const;
   1.220 +private:
   1.221 +	static TInt Construct(HMatcherPattern<T,D>*& aCell,const D& aPattern,TBool aEscape = EFalse);
   1.222 +	static inline HMatcherPattern<T,D>* Realloc(HMatcherPattern<T,D>* aThis,TInt aSize);
   1.223 +private:
   1.224 +	T iPattern[1];
   1.225 +	};
   1.226 +
   1.227 +template <class T,class D>
   1.228 +class TMatcher
   1.229 +/**
   1.230 +@internalComponent
   1.231 +*/
   1.232 +	{
   1.233 +public:
   1.234 +	TBool MatchL(const HMatcherPattern<T,D>& aPattern,const TTextOps& aTextOp);
   1.235 +private:
   1.236 +	virtual const T* UnderflowL(const T*& aEnd,TInt aRetain=0) =0;
   1.237 +	};
   1.238 +
   1.239 +template <class T,class D>
   1.240 +class TDesMatcher : public TMatcher<T,D>
   1.241 +/**
   1.242 +@internalComponent
   1.243 +*/
   1.244 +	{
   1.245 +public:
   1.246 +	inline TDesMatcher(const D& aDes);
   1.247 +private:
   1.248 +	const T* UnderflowL(const T*& aEnd,TInt aRetain=0);
   1.249 +private:
   1.250 +	const T* iPtr;
   1.251 +	const T* iEnd;
   1.252 +	};
   1.253 +
   1.254 +template <class T,class D>
   1.255 +class TStreamMatcher : public TMatcher<T,D>
   1.256 +/**
   1.257 +@internalComponent
   1.258 +*/
   1.259 +	{
   1.260 +public:
   1.261 +	inline TStreamMatcher(MStreamBuf& aStreamBuf,TInt aLength);
   1.262 +private:
   1.263 +	const T* UnderflowL(const T*& aEnd,TInt aRetain=0);
   1.264 +private:
   1.265 +	enum {EBufSize=0x200};
   1.266 +private:
   1.267 +	RReadStream iStream;
   1.268 +	TInt iRemain;
   1.269 +	T iBuffer[EBufSize];
   1.270 +	const T* iEnd;
   1.271 +	};
   1.272 +
   1.273 +NONSHARABLE_CLASS(CSqlCreateTableStatement) : public CSqlDDLStatement
   1.274 +/**
   1.275 +DDL statements
   1.276 +@internalComponent
   1.277 +*/
   1.278 +	{
   1.279 +public:
   1.280 +private:
   1.281 +	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
   1.282 +public:
   1.283 +	TPtrC iName;
   1.284 +	CDbColSet iColumns;
   1.285 +	};
   1.286 +
   1.287 +NONSHARABLE_CLASS(CSqlDropTableStatement) : public CSqlDDLStatement
   1.288 +/**
   1.289 +@internalComponent
   1.290 +*/
   1.291 +	{
   1.292 +private:
   1.293 +	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
   1.294 +public:
   1.295 +	TPtrC iName;
   1.296 +	};
   1.297 +
   1.298 +NONSHARABLE_CLASS(CSqlAlterTableStatement) : public CSqlDDLStatement
   1.299 +/**
   1.300 +@internalComponent
   1.301 +*/
   1.302 +	{
   1.303 +public:
   1.304 +	~CSqlAlterTableStatement();
   1.305 +private:
   1.306 +	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
   1.307 +public:
   1.308 +	TPtrC iName;
   1.309 +	CDbColSet iAdd;
   1.310 +	RSqlColumnList iDrop;
   1.311 +	};
   1.312 +
   1.313 +NONSHARABLE_CLASS(CSqlCreateIndexStatement) : public CSqlDDLStatement
   1.314 +/**
   1.315 +@internalComponent
   1.316 +*/
   1.317 +	{
   1.318 +private:
   1.319 +	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
   1.320 +public:
   1.321 +	TPtrC iName;
   1.322 +	TPtrC iTable;
   1.323 +	CDbKey iKey;
   1.324 +	};
   1.325 +
   1.326 +NONSHARABLE_CLASS(CSqlDropIndexStatement) : public CSqlDDLStatement
   1.327 +/**
   1.328 +@internalComponent
   1.329 +*/
   1.330 +	{
   1.331 +private:
   1.332 +	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
   1.333 +public:
   1.334 +	TPtrC iName;
   1.335 +	TPtrC iTable;
   1.336 +	};
   1.337 +
   1.338 +#include "UQ_STD.INL"