os/persistentdata/persistentstorage/dbms/usql/UQ_STD.H
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "U32STD.H"
sl@0
    17
#include "D32SQL.H"
sl@0
    18
#include "D32TABLE.H"
sl@0
    19
#include <e32math.h>
sl@0
    20
#include <s32mem.h>
sl@0
    21
sl@0
    22
//Forward declarations
sl@0
    23
class TSqlParser2;
sl@0
    24
sl@0
    25
// Classes defined
sl@0
    26
class TSqlToken;
sl@0
    27
class TSqlLexer;
sl@0
    28
class TSqlParser;
sl@0
    29
template <class T,class D> class TMatcher;
sl@0
    30
template <class T,class D> class TDesMatcher;
sl@0
    31
template <class T,class D> class TStreamMatcher;
sl@0
    32
template <class T,class D> class HMatcherPattern;
sl@0
    33
class CSqlCreateTableStatement;
sl@0
    34
class CSqlDropTableStatement;
sl@0
    35
class CSqlAlterTableStatement;
sl@0
    36
class CSqlCreateIndexStatement;
sl@0
    37
class CSqlDropIndexStatement;
sl@0
    38
sl@0
    39
/**
sl@0
    40
parser classes
sl@0
    41
@internalComponent
sl@0
    42
*/
sl@0
    43
enum TSqlTokenType
sl@0
    44
	{
sl@0
    45
	ESqlNoToken=0,
sl@0
    46
//
sl@0
    47
	ESqlEos,
sl@0
    48
//
sl@0
    49
	ESqlIdentifier,
sl@0
    50
	ESqlLiteralInt,
sl@0
    51
	ESqlLiteralReal,
sl@0
    52
	ESqlLiteralTime,
sl@0
    53
	ESqlLiteralText,
sl@0
    54
//
sl@0
    55
	ESqlAsterisk,
sl@0
    56
	ESqlComma,
sl@0
    57
	ESqlLeftBracket,
sl@0
    58
	ESqlRightBracket,
sl@0
    59
	ESqlLess,
sl@0
    60
	ESqlLessEqual,
sl@0
    61
	ESqlEqual,
sl@0
    62
	ESqlGreaterEqual,
sl@0
    63
	ESqlGreater,
sl@0
    64
	ESqlNotEqual
sl@0
    65
	};
sl@0
    66
sl@0
    67
/**
sl@0
    68
@internalComponent
sl@0
    69
*/
sl@0
    70
enum TSqlKeyword
sl@0
    71
	{
sl@0
    72
	ESqlNotKeyword=-1,
sl@0
    73
//
sl@0
    74
#define KEYWORD(s) ESqlKeyword_##s
sl@0
    75
#include "UQ_KEYWD.H"
sl@0
    76
#undef KEYWORD
sl@0
    77
	};
sl@0
    78
sl@0
    79
class TSqlToken
sl@0
    80
/**
sl@0
    81
@internalComponent
sl@0
    82
*/
sl@0
    83
	{
sl@0
    84
	friend class TSqlLexer;
sl@0
    85
public:
sl@0
    86
	inline TBool operator==(TSqlTokenType aType) const;
sl@0
    87
	inline TBool operator!=(TSqlTokenType aType) const;
sl@0
    88
//
sl@0
    89
	inline void SetError(TInt aError);
sl@0
    90
	inline TInt Error() const;
sl@0
    91
//
sl@0
    92
	inline TSqlTokenType Type() const;
sl@0
    93
	inline const RSqlLiteral& Literal() const;
sl@0
    94
	inline RSqlLiteral& Literal();
sl@0
    95
private:
sl@0
    96
	inline TSqlTokenType operator=(TSqlTokenType aType);
sl@0
    97
private:
sl@0
    98
	TInt iType;
sl@0
    99
	RSqlLiteral iLiteral;
sl@0
   100
	};
sl@0
   101
sl@0
   102
class TSqlLexer
sl@0
   103
/**
sl@0
   104
@internalComponent
sl@0
   105
*/
sl@0
   106
	{
sl@0
   107
public:
sl@0
   108
	TSqlLexer(const TDesC& aSql);
sl@0
   109
	inline TSqlTokenType NextToken(TSqlToken& aToken);
sl@0
   110
	static TSqlKeyword Keyword(const TSqlToken& aToken);
sl@0
   111
	static inline TBool IsKeyword(TSqlKeyword aKeyword,const TSqlToken& aToken);
sl@0
   112
	const TText* Next() const;
sl@0
   113
	void Set(const TText* aNext);	
sl@0
   114
private:
sl@0
   115
	TSqlTokenType GetIdentifier(TSqlToken& aToken);
sl@0
   116
	TSqlTokenType GetString(TSqlToken& aToken);
sl@0
   117
	TInt GetInteger(TInt64& aValue);
sl@0
   118
	TSqlTokenType GetNumber(TSqlToken& aToken);
sl@0
   119
	TSqlTokenType GetDate(TSqlToken& aToken);
sl@0
   120
	TSqlTokenType GetNextToken(TSqlToken& aToken);
sl@0
   121
//
sl@0
   122
	static inline TSqlTokenType SqlError(TInt aError=KErrArgument);
sl@0
   123
	static TInt CompareKeyword(TInt aKeyword,const RSqlLiteral& aIdentifier);
sl@0
   124
private:
sl@0
   125
	const TText* iNext;
sl@0
   126
	const TText* iEnd;
sl@0
   127
	};
sl@0
   128
sl@0
   129
class TSqlParser
sl@0
   130
/**
sl@0
   131
@internalComponent
sl@0
   132
*/
sl@0
   133
	{
sl@0
   134
	friend class TSqlParser2;
sl@0
   135
public:
sl@0
   136
	TSqlParser(const TDesC& aSql);
sl@0
   137
//
sl@0
   138
	CSqlQuery* QueryLC();
sl@0
   139
	CSqlSearchCondition* SearchConditionLC();
sl@0
   140
	CSqlDDLStatement* DDLStatementLC();
sl@0
   141
	CSqlDMLStatement* DMLStatementLC();
sl@0
   142
	Sql::TStatementType Type();
sl@0
   143
	TInt PatternFilter(const TDesC& aPattern,const TChar aEscape, TText *aNewPatternBuffer );
sl@0
   144
private:
sl@0
   145
	TSqlTokenType NextToken();
sl@0
   146
	CSqlSearchCondition* SqlError();
sl@0
   147
	inline TInt Error() const;
sl@0
   148
	static TSqlTokenType SqlErrorL();
sl@0
   149
//
sl@0
   150
	TSqlTokenType Parse(TSqlKeyword aKeyword);
sl@0
   151
	TSqlTokenType ParseL(TSqlTokenType aToken);
sl@0
   152
	TSqlTokenType ParseL(TSqlKeyword aKeyword);
sl@0
   153
	TSqlKeyword Keyword();
sl@0
   154
	TSqlTokenType RightBracketL();
sl@0
   155
	TSqlTokenType IdentifierL(TPtrC& aIdentifier);
sl@0
   156
	TPtrC IdentifierL();
sl@0
   157
	void EndL();
sl@0
   158
//
sl@0
   159
	TSqlTokenType ColumnNameL(RSqlColumnList& aList);
sl@0
   160
	TSqlTokenType ColumnListL(RSqlColumnList& aList);
sl@0
   161
	CSqlSearchCondition* SearchCondition(TInt aNot);
sl@0
   162
	CSqlSearchCondition* BooleanTerm(TInt aNot);
sl@0
   163
	CSqlSearchCondition* BooleanFactor(TInt aNot);
sl@0
   164
	CSqlSearchCondition* BooleanPrimary(TInt aNot);
sl@0
   165
	CSqlSearchCondition* Predicate(TInt aNot);
sl@0
   166
	void SortSpecificationL(CDbKey& aKey);
sl@0
   167
	CDbKey* SortSpecificationL();
sl@0
   168
	void DoQueryL(CSqlQuery& aQuery);
sl@0
   169
	CSqlSearchCondition* SearchConditionL();
sl@0
   170
//
sl@0
   171
	TSqlTokenType AddColumnSpecL(TDbCol& aDef);
sl@0
   172
	CSqlDDLStatement* CreateTableLC();
sl@0
   173
	CSqlDDLStatement* DropTableLC();
sl@0
   174
	CSqlDDLStatement* AlterTableLC();
sl@0
   175
	CSqlDDLStatement* CreateIndexLC(TBool aUnique);
sl@0
   176
	CSqlDDLStatement* DropIndexLC();
sl@0
   177
//
sl@0
   178
	TSqlTokenType ColumnValueL(CSqlValues& aValues);
sl@0
   179
	CSqlDMLStatement* InsertStatementLC();
sl@0
   180
	CSqlDMLStatement* UpdateStatementLC();
sl@0
   181
	CSqlDMLStatement* DeleteStatementLC();
sl@0
   182
private:
sl@0
   183
	TSqlLexer iSql;
sl@0
   184
	TSqlToken iToken;
sl@0
   185
	};
sl@0
   186
sl@0
   187
sl@0
   188
/**
sl@0
   189
LIKE evaluation support
sl@0
   190
@internalComponent
sl@0
   191
*/
sl@0
   192
enum TSegmentType {ENull,ESuccess,EStop,EBeginning,EEnd,EMiddle,ESkip,EEscape,EMask=0xf,EWild=0x80};
sl@0
   193
/**
sl@0
   194
@internalComponent
sl@0
   195
*/
sl@0
   196
const TInt KPatternGranularity=0x20;
sl@0
   197
sl@0
   198
// If this value is changed class documentation must be updated.
sl@0
   199
// Namely, RDbDatabase and TDbQuery.
sl@0
   200
const TInt KMaxSegmentLength=0xff;
sl@0
   201
sl@0
   202
template <class T,class D>
sl@0
   203
class HMatcherPattern
sl@0
   204
/**
sl@0
   205
@internalComponent
sl@0
   206
*/
sl@0
   207
	{
sl@0
   208
	friend class TMatcher<T,D>;
sl@0
   209
	typedef HMatcherPattern<T,D> TThis;
sl@0
   210
public:
sl@0
   211
	static HMatcherPattern<T,D>* NewL(const D& aPattern,TBool aEscape = EFalse);
sl@0
   212
	TInt MatchL(const D& aDes,const TTextOps& aTextOp) const;
sl@0
   213
	TInt MatchL(MStreamBuf& aBuf,TInt aLength,const TTextOps& aTextOp) const;
sl@0
   214
private:
sl@0
   215
	static TInt Construct(HMatcherPattern<T,D>*& aCell,const D& aPattern,TBool aEscape = EFalse);
sl@0
   216
	static inline HMatcherPattern<T,D>* Realloc(HMatcherPattern<T,D>* aThis,TInt aSize);
sl@0
   217
private:
sl@0
   218
	T iPattern[1];
sl@0
   219
	};
sl@0
   220
sl@0
   221
template <class T,class D>
sl@0
   222
class TMatcher
sl@0
   223
/**
sl@0
   224
@internalComponent
sl@0
   225
*/
sl@0
   226
	{
sl@0
   227
public:
sl@0
   228
	TBool MatchL(const HMatcherPattern<T,D>& aPattern,const TTextOps& aTextOp);
sl@0
   229
private:
sl@0
   230
	virtual const T* UnderflowL(const T*& aEnd,TInt aRetain=0) =0;
sl@0
   231
	};
sl@0
   232
sl@0
   233
template <class T,class D>
sl@0
   234
class TDesMatcher : public TMatcher<T,D>
sl@0
   235
/**
sl@0
   236
@internalComponent
sl@0
   237
*/
sl@0
   238
	{
sl@0
   239
public:
sl@0
   240
	inline TDesMatcher(const D& aDes);
sl@0
   241
private:
sl@0
   242
	const T* UnderflowL(const T*& aEnd,TInt aRetain=0);
sl@0
   243
private:
sl@0
   244
	const T* iPtr;
sl@0
   245
	const T* iEnd;
sl@0
   246
	};
sl@0
   247
sl@0
   248
template <class T,class D>
sl@0
   249
class TStreamMatcher : public TMatcher<T,D>
sl@0
   250
/**
sl@0
   251
@internalComponent
sl@0
   252
*/
sl@0
   253
	{
sl@0
   254
public:
sl@0
   255
	inline TStreamMatcher(MStreamBuf& aStreamBuf,TInt aLength);
sl@0
   256
private:
sl@0
   257
	const T* UnderflowL(const T*& aEnd,TInt aRetain=0);
sl@0
   258
private:
sl@0
   259
	enum {EBufSize=0x200};
sl@0
   260
private:
sl@0
   261
	RReadStream iStream;
sl@0
   262
	TInt iRemain;
sl@0
   263
	T iBuffer[EBufSize];
sl@0
   264
	const T* iEnd;
sl@0
   265
	};
sl@0
   266
sl@0
   267
NONSHARABLE_CLASS(CSqlCreateTableStatement) : public CSqlDDLStatement
sl@0
   268
/**
sl@0
   269
DDL statements
sl@0
   270
@internalComponent
sl@0
   271
*/
sl@0
   272
	{
sl@0
   273
private:
sl@0
   274
	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
sl@0
   275
public:
sl@0
   276
	TPtrC iName;
sl@0
   277
	CDbColSet iColumns;
sl@0
   278
	};
sl@0
   279
sl@0
   280
NONSHARABLE_CLASS(CSqlDropTableStatement) : public CSqlDDLStatement
sl@0
   281
/**
sl@0
   282
@internalComponent
sl@0
   283
*/
sl@0
   284
	{
sl@0
   285
private:
sl@0
   286
	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
sl@0
   287
public:
sl@0
   288
	TPtrC iName;
sl@0
   289
	};
sl@0
   290
sl@0
   291
NONSHARABLE_CLASS(CSqlAlterTableStatement) : public CSqlDDLStatement
sl@0
   292
/**
sl@0
   293
@internalComponent
sl@0
   294
*/
sl@0
   295
	{
sl@0
   296
public:
sl@0
   297
	~CSqlAlterTableStatement();
sl@0
   298
private:
sl@0
   299
	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
sl@0
   300
public:
sl@0
   301
	TPtrC iName;
sl@0
   302
	CDbColSet iAdd;
sl@0
   303
	RSqlColumnList iDrop;
sl@0
   304
	};
sl@0
   305
sl@0
   306
NONSHARABLE_CLASS(CSqlCreateIndexStatement) : public CSqlDDLStatement
sl@0
   307
/**
sl@0
   308
@internalComponent
sl@0
   309
*/
sl@0
   310
	{
sl@0
   311
private:
sl@0
   312
	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
sl@0
   313
public:
sl@0
   314
	TPtrC iName;
sl@0
   315
	TPtrC iTable;
sl@0
   316
	CDbKey iKey;
sl@0
   317
	};
sl@0
   318
sl@0
   319
NONSHARABLE_CLASS(CSqlDropIndexStatement) : public CSqlDDLStatement
sl@0
   320
/**
sl@0
   321
@internalComponent
sl@0
   322
*/
sl@0
   323
	{
sl@0
   324
private:
sl@0
   325
	CDbIncremental* ExecuteL(CDbDatabase& aDatabase,TDbTextComparison aComparison,TInt& aSteps);
sl@0
   326
public:
sl@0
   327
	TPtrC iName;
sl@0
   328
	TPtrC iTable;
sl@0
   329
	};
sl@0
   330
sl@0
   331
#include "UQ_STD.INL"