winphonesqlite /root/SQLite/NextLine.Data.SQLite.Wrapper/tokenize_c.cs

Language C# Lines 674
MD5 Hash e9367b2c87fdde6360bf99ded71fcae6
Repository https://winphonesqlite.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
using System;
using System.Diagnostics;
using System.Text;

namespace NextLine.Data.SQLite.Wrapper
{
  internal partial class Sqlite3
  {
    /*
    ** 2001 September 15
    **
    ** The author disclaims copyright to this source code.  In place of
    ** a legal notice, here is a blessing:
    **
    **    May you do good and not evil.
    **    May you find forgiveness for yourself and forgive others.
    **    May you share freely, never taking more than you give.
    **
    *************************************************************************
    ** An tokenizer for SQL
    **
    ** This file contains C code that splits an SQL input string up into
    ** individual tokens and sends those tokens one-by-one over to the
    ** parser for analysis.
    *************************************************************************
    **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
    **  C#-SQLite is an independent reimplementation of the SQLite software library
    **
    **  SQLITE_SOURCE_ID: 2010-03-09 19:31:43 4ae453ea7be69018d8c16eb8dabe05617397dc4d
    **
    **  $Header$
    *************************************************************************
    */
    //#include "sqliteInt.h"
    //#include <stdlib.h>

    /*
    ** The charMap() macro maps alphabetic characters into their
    ** lower-case ASCII equivalent.  On ASCII machines, this is just
    ** an upper-to-lower case map.  On EBCDIC machines we also need
    ** to adjust the encoding.  Only alphabetic characters and underscores
    ** need to be translated.
    */
#if SQLITE_ASCII
    //# define charMap(X) sqlite3UpperToLower[(unsigned char)X]
#endif
#if SQLITE_EBCDIC
//# define charMap(X) ebcdicToAscii[(unsigned char)X]
//const unsigned char ebcdicToAscii[] = {
/* 0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 0x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 1x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 2x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 3x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 4x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 5x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 95,  0,  0,  /* 6x */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* 7x */
//   0, 97, 98, 99,100,101,102,103,104,105,  0,  0,  0,  0,  0,  0,  /* 8x */
//   0,106,107,108,109,110,111,112,113,114,  0,  0,  0,  0,  0,  0,  /* 9x */
//   0,  0,115,116,117,118,119,120,121,122,  0,  0,  0,  0,  0,  0,  /* Ax */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* Bx */
//   0, 97, 98, 99,100,101,102,103,104,105,  0,  0,  0,  0,  0,  0,  /* Cx */
//   0,106,107,108,109,110,111,112,113,114,  0,  0,  0,  0,  0,  0,  /* Dx */
//   0,  0,115,116,117,118,119,120,121,122,  0,  0,  0,  0,  0,  0,  /* Ex */
//   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  /* Fx */
//};
#endif

    /*
** The sqlite3KeywordCode function looks up an identifier to determine if
** it is a keyword.  If it is a keyword, the token code of that keyword is
** returned.  If the input is not a keyword, TK_ID is returned.
**
** The implementation of this routine was generated by a program,
** mkkeywordhash.h, located in the tool subdirectory of the distribution.
** The output of the mkkeywordhash.c program is written into a file
** named keywordhash.h and then included into this source file by
** the #include below.
*/
    //#include "keywordhash.h"


    /*
    ** If X is a character that can be used in an identifier then
    ** IdChar(X) will be true.  Otherwise it is false.
    **
    ** For ASCII, any character with the high-order bit set is
    ** allowed in an identifier.  For 7-bit characters,
    ** sqlite3IsIdChar[X] must be 1.
    **
    ** For EBCDIC, the rules are more complex but have the same
    ** end result.
    **
    ** Ticket #1066.  the SQL standard does not allow '$' in the
    ** middle of identfiers.  But many SQL implementations do.
    ** SQLite will allow '$' in identifiers for compatibility.
    ** But the feature is undocumented.
    */
#if SQLITE_ASCII
    //#define IdChar(C)  ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
#endif
#if SQLITE_EBCDIC
//const char sqlite3IsEbcdicIdChar[] = {
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
//    0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,  /* 4x */
//    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0,  /* 5x */
//    0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0,  /* 6x */
//    0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,  /* 7x */
//    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0,  /* 8x */
//    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0,  /* 9x */
//    1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0,  /* Ax */
//    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* Bx */
//    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,  /* Cx */
//    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,  /* Dx */
//    0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,  /* Ex */
//    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0,  /* Fx */
//};
//#define IdChar(C)  (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
#endif


    /*
** Return the length of the token that begins at z[iOffset + 0].
** Store the token type in *tokenType before returning.
*/
    static int sqlite3GetToken( string z, int iOffset, ref int tokenType )
    {
      int i;
      byte c = 0;
      switch ( z[iOffset + 0] )
      {
        case ' ':
        case '\t':
        case '\n':
        case '\f':
        case '\r':
          {
            testcase( z[iOffset + 0] == ' ' );
            testcase( z[iOffset + 0] == '\t' );
            testcase( z[iOffset + 0] == '\n' );
            testcase( z[iOffset + 0] == '\f' );
            testcase( z[iOffset + 0] == '\r' );
            for ( i = 1; z.Length > iOffset + i && sqlite3Isspace( z[iOffset + i] ); i++ ) { }
            tokenType = TK_SPACE;
            return i;
          }
        case '-':
          {
            if ( z.Length > iOffset + 1 && z[iOffset + 1] == '-' )
            {
              /* IMP: R-15891-05542 -- syntax diagram for comments */
              for ( i = 2; z.Length > iOffset + i && ( c = (byte)z[iOffset + i] ) != 0 && c != '\n'; i++ ) { }
              tokenType = TK_SPACE;   /* IMP: R-22934-25134 */
              return i;
            }
            tokenType = TK_MINUS;
            return 1;
          }
        case '(':
          {
            tokenType = TK_LP;
            return 1;
          }
        case ')':
          {
            tokenType = TK_RP;
            return 1;
          }
        case ';':
          {
            tokenType = TK_SEMI;
            return 1;
          }
        case '+':
          {
            tokenType = TK_PLUS;
            return 1;
          }
        case '*':
          {
            tokenType = TK_STAR;
            return 1;
          }
        case '/':
          {
            if ( iOffset + 2 >= z.Length || z[iOffset + 1] != '*' )
            {
              tokenType = TK_SLASH;
              return 1;
            }
            /* IMP: R-15891-05542 -- syntax diagram for comments */
            for ( i = 3, c = (byte)z[iOffset + 2]; iOffset + i < z.Length && ( c != '*' || ( z[iOffset + i] != '/' ) && ( c != 0 ) ); i++ ) { c = (byte)z[iOffset + i]; }
            if ( iOffset + i == z.Length ) c = 0;
            if ( c != 0 ) i++;
            tokenType = TK_SPACE; /* IMP: R-22934-25134 */
            return i;
          }
        case '%':
          {
            tokenType = TK_REM;
            return 1;
          }
        case '=':
          {
            tokenType = TK_EQ;
            return 1 + ( z[iOffset + 1] == '=' ? 1 : 0 );
          }
        case '<':
          {
            if ( ( c = (byte)z[iOffset + 1] ) == '=' )
            {
              tokenType = TK_LE;
              return 2;
            }
            else if ( c == '>' )
            {
              tokenType = TK_NE;
              return 2;
            }
            else if ( c == '<' )
            {
              tokenType = TK_LSHIFT;
              return 2;
            }
            else
            {
              tokenType = TK_LT;
              return 1;
            }
          }
        case '>':
          {
            if ( z.Length > iOffset + 1 && ( c = (byte)z[iOffset + 1] ) == '=' )
            {
              tokenType = TK_GE;
              return 2;
            }
            else if ( c == '>' )
            {
              tokenType = TK_RSHIFT;
              return 2;
            }
            else
            {
              tokenType = TK_GT;
              return 1;
            }
          }
        case '!':
          {
            if ( z[iOffset + 1] != '=' )
            {
              tokenType = TK_ILLEGAL;
              return 2;
            }
            else
            {
              tokenType = TK_NE;
              return 2;
            }
          }
        case '|':
          {
            if ( z[iOffset + 1] != '|' )
            {
              tokenType = TK_BITOR;
              return 1;
            }
            else
            {
              tokenType = TK_CONCAT;
              return 2;
            }
          }
        case ',':
          {
            tokenType = TK_COMMA;
            return 1;
          }
        case '&':
          {
            tokenType = TK_BITAND;
            return 1;
          }
        case '~':
          {
            tokenType = TK_BITNOT;
            return 1;
          }
        case '`':
        case '\'':
        case '"':
          {
            int delim = z[iOffset + 0];
            testcase( delim == '`' );
            testcase( delim == '\'' );
            testcase( delim == '"' );
            for ( i = 1; ( iOffset + i ) < z.Length && ( c = (byte)z[iOffset + i] ) != 0; i++ )
            {
              if ( c == delim )
              {
                if ( z.Length > iOffset + i + 1 && z[iOffset + i + 1] == delim )
                {
                  i++;
                }
                else
                {
                  break;
                }
              }
            }
            if ( ( iOffset + i == z.Length && c != delim ) || z[iOffset + i] != delim )
            {
              tokenType = TK_ILLEGAL;
              return i + 1;
            }
            if ( c == '\'' )
            {
              tokenType = TK_STRING;
              return i + 1;
            }
            else if ( c != 0 )
            {
              tokenType = TK_ID;
              return i + 1;
            }
            else
            {
              tokenType = TK_ILLEGAL;
              return i;
            }
          }
        case '.':
          {
#if !SQLITE_OMIT_FLOATING_POINT
            if ( !sqlite3Isdigit( z[iOffset + 1] ) )
#endif
            {
              tokenType = TK_DOT;
              return 1;
            }
            /* If the next character is a digit, this is a floating point
            ** number that begins with ".".  Fall thru into the next case */
            goto case '0';
          }
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          {
            testcase( z[iOffset] == '0' ); testcase( z[iOffset] == '1' ); testcase( z[iOffset] == '2' );
            testcase( z[iOffset] == '3' ); testcase( z[iOffset] == '4' ); testcase( z[iOffset] == '5' );
            testcase( z[iOffset] == '6' ); testcase( z[iOffset] == '7' ); testcase( z[iOffset] == '8' );
            testcase( z[iOffset] == '9' );
            tokenType = TK_INTEGER;
            for ( i = 0; z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ); i++ ) { }
#if !SQLITE_OMIT_FLOATING_POINT
            if ( z.Length > iOffset + i && z[iOffset + i] == '.' )
            {
              i++;
              while ( z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ) ) { i++; }
              tokenType = TK_FLOAT;
            }
            if ( z.Length > iOffset + i + 1 && ( z[iOffset + i] == 'e' || z[iOffset + i] == 'E' ) &&
            ( sqlite3Isdigit( z[iOffset + i + 1] )
            || z.Length > iOffset + i + 2 && ( ( z[iOffset + i + 1] == '+' || z[iOffset + i + 1] == '-' ) && sqlite3Isdigit( z[iOffset + i + 2] ) )
            )
            )
            {
              i += 2;
              while ( z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ) ) { i++; }
              tokenType = TK_FLOAT;
            }
#endif
            while ( iOffset + i < z.Length && IdChar( (byte)z[iOffset + i] ) )
            {
              tokenType = TK_ILLEGAL;
              i++;
            }
            return i;
          }

        case '[':
          {
            for ( i = 1, c = (byte)z[iOffset + 0]; c != ']' && ( iOffset + i ) < z.Length && ( c = (byte)z[iOffset + i] ) != 0; i++ ) { }
            tokenType = c == ']' ? TK_ID : TK_ILLEGAL;
            return i;
          }
        case '?':
          {
            tokenType = TK_VARIABLE;
            for ( i = 1; z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ); i++ ) { }
            return i;
          }
        case '#':
          {
            for ( i = 1; z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ); i++ ) { }
            if ( i > 1 )
            {
              /* Parameters of the form #NNN (where NNN is a number) are used
              ** internally by sqlite3NestedParse.  */
              tokenType = TK_REGISTER;
              return i;
            }
            /* Fall through into the next case if the '#' is not followed by
            ** a digit. Try to match #AAAA where AAAA is a parameter name. */
            goto case ':';
          }
#if !SQLITE_OMIT_TCL_VARIABLE
        case '$':
#endif
        case '@':  /* For compatibility with MS SQL Server */
        case ':':
          {
            int n = 0;
            testcase( z[iOffset + 0] == '$' ); testcase( z[iOffset + 0] == '@' ); testcase( z[iOffset + 0] == ':' );
            tokenType = TK_VARIABLE;
            for ( i = 1; z.Length > iOffset + i && ( c = (byte)z[iOffset + i] ) != 0; i++ )
            {
              if ( IdChar( c ) )
              {
                n++;
#if !SQLITE_OMIT_TCL_VARIABLE
              }
              else if ( c == '(' && n > 0 )
              {
                do
                {
                  i++;
                } while ( ( iOffset + i ) < z.Length && ( c = (byte)z[iOffset + i] ) != 0 && !sqlite3Isspace( c ) && c != ')' );
                if ( c == ')' )
                {
                  i++;
                }
                else
                {
                  tokenType = TK_ILLEGAL;
                }
                break;
              }
              else if ( c == ':' && z[iOffset + i + 1] == ':' )
              {
                i++;
#endif
              }
              else
              {
                break;
              }
            }
            if ( n == 0 ) tokenType = TK_ILLEGAL;
            return i;
          }
#if !SQLITE_OMIT_BLOB_LITERAL
        case 'x':
        case 'X':
          {
            testcase( z[iOffset + 0] == 'x' ); testcase( z[iOffset + 0] == 'X' );
            if ( z.Length > iOffset + 1 && z[iOffset + 1] == '\'' )
            {
              tokenType = TK_BLOB;
              for ( i = 2; z.Length > iOffset + i && ( c = (byte)z[iOffset + i] ) != 0 && c != '\''; i++ )
              {
                if ( !sqlite3Isxdigit( c ) )
                {
                  tokenType = TK_ILLEGAL;
                }
              }
              if ( i % 2 != 0 || z.Length == iOffset + i && c != '\'' ) tokenType = TK_ILLEGAL;
              if ( c != 0 ) i++;
              return i;
            }
            goto default;
            /* Otherwise fall through to the next case */
          }
#endif
        default:
          {
            if ( !IdChar( (byte)z[iOffset] ) )
            {
              break;
            }
            for ( i = 1; i < z.Length - iOffset && IdChar( (byte)z[iOffset + i] ); i++ ) { }
            tokenType = keywordCode( z, iOffset, i );
            return i;
          }
      }
      tokenType = TK_ILLEGAL;
      return 1;
    }

    /*
    ** Run the parser on the given SQL string.  The parser structure is
    ** passed in.  An SQLITE_ status code is returned.  If an error occurs
    ** then an and attempt is made to write an error message into
    ** memory obtained from sqlite3_malloc() and to make pzErrMsg point to that
    ** error message.
    */
    static int sqlite3RunParser( Parse pParse, string zSql, ref string pzErrMsg )
    {
      int nErr = 0;                   /* Number of errors encountered */
      int i;                          /* Loop counter */
      yyParser pEngine;               /* The LEMON-generated LALR(1) parser */
      int tokenType = 0;              /* type of the next token */
      int lastTokenParsed = -1;       /* type of the previous token */
      byte enableLookaside;           /* Saved value of db->lookaside.bEnabled */
      sqlite3 db = pParse.db;         /* The database connection */
      int mxSqlLen;                   /* Max length of an SQL string */


      mxSqlLen = db.aLimit[SQLITE_LIMIT_SQL_LENGTH];
      if ( db.activeVdbeCnt == 0 )
      {
        db.u1.isInterrupted = false;
      }
      pParse.rc = SQLITE_OK;
      pParse.zTail = new StringBuilder( zSql );
      i = 0;
      Debug.Assert( pzErrMsg != null );
      pEngine = sqlite3ParserAlloc();//sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc);
      if ( pEngine == null )
      {
        ////        db.mallocFailed = 1;
        return SQLITE_NOMEM;
      }
      Debug.Assert( pParse.pNewTable == null );
      Debug.Assert( pParse.pNewTrigger == null );
      Debug.Assert( pParse.nVar == 0 );
      Debug.Assert( pParse.nVarExpr == 0 );
      Debug.Assert( pParse.nVarExprAlloc == 0 );
      Debug.Assert( pParse.apVarExpr == null );
      enableLookaside = db.lookaside.bEnabled;
      if ( db.lookaside.pStart != 0 ) db.lookaside.bEnabled = 1;
      while ( /*  0 == db.mallocFailed && */  i < zSql.Length )
      {
        Debug.Assert( i >= 0 );
        //pParse->sLastToken.z = &zSql[i];
        pParse.sLastToken.n = sqlite3GetToken( zSql, i, ref tokenType );
        pParse.sLastToken.z = zSql.Substring( i );
        i += pParse.sLastToken.n;
        if ( i > mxSqlLen )
        {
          pParse.rc = SQLITE_TOOBIG;
          break;
        }
        switch ( tokenType )
        {
          case TK_SPACE:
            {
              if ( db.u1.isInterrupted )
              {
                sqlite3ErrorMsg( pParse, "interrupt" );
                pParse.rc = SQLITE_INTERRUPT;
                goto abort_parse;
              }
              break;
            }
          case TK_ILLEGAL:
            {
              sqlite3DbFree( db, ref pzErrMsg );
              pzErrMsg = sqlite3MPrintf( db, "unrecognized token: \"%T\"",
                (object)pParse.sLastToken );
              nErr++;
              goto abort_parse;
            }
          case TK_SEMI:
            {
              //pParse.zTail = new StringBuilder(zSql.Substring( i,zSql.Length-i ));
              /* Fall thru into the default case */
              goto default;
            }
          default:
            {
              sqlite3Parser( pEngine, tokenType, pParse.sLastToken, pParse );
              lastTokenParsed = tokenType;
              if ( pParse.rc != SQLITE_OK )
              {
                goto abort_parse;
              }
              break;
            }
        }
      }
    abort_parse:
      pParse.zTail = new StringBuilder( zSql.Length <= i ? "" : zSql.Substring( i, zSql.Length - i ) );
      if ( zSql.Length >= i && nErr == 0 && pParse.rc == SQLITE_OK )
      {
        if ( lastTokenParsed != TK_SEMI )
        {
          sqlite3Parser( pEngine, TK_SEMI, pParse.sLastToken, pParse );
        }
        sqlite3Parser( pEngine, 0, pParse.sLastToken, pParse );
      }
#if YYTRACKMAXSTACKDEPTH
sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
sqlite3ParserStackPeak(pEngine)
);
#endif //* YYDEBUG */
      sqlite3ParserFree( pEngine, null );//sqlite3_free );
      db.lookaside.bEnabled = enableLookaside;
      //if ( db.mallocFailed != 0 )
      //{
      //  pParse.rc = SQLITE_NOMEM;
      //}
      if ( pParse.rc != SQLITE_OK && pParse.rc != SQLITE_DONE && pParse.zErrMsg == "" )
      {
        sqlite3SetString( ref pParse.zErrMsg, db, sqlite3ErrStr( pParse.rc ) );
      }
      //assert( pzErrMsg!=0 );
      if ( pParse.zErrMsg != null )
      {
        pzErrMsg = pParse.zErrMsg;
        sqlite3_log(pParse.rc, "%s", pzErrMsg);
        pParse.zErrMsg = "";
        nErr++;
      }
      if ( pParse.pVdbe != null && pParse.nErr > 0 && pParse.nested == 0 )
      {
        sqlite3VdbeDelete( ref pParse.pVdbe );
        pParse.pVdbe = null;
      }
#if !SQLITE_OMIT_SHARED_CACHE
if ( pParse.nested == 0 )
{
sqlite3DbFree( db, ref pParse.aTableLock );
pParse.aTableLock = null;
pParse.nTableLock = 0;
}
#endif
#if !SQLITE_OMIT_VIRTUALTABLE
sqlite3DbFree(db,pParse.apVtabLock);
#endif
      if ( !IN_DECLARE_VTAB )
      {
        /* If the pParse.declareVtab flag is set, do not delete any table
        ** structure built up in pParse.pNewTable. The calling code (see vtab.c)
        ** will take responsibility for freeing the Table structure.
        */
        sqlite3DeleteTable( ref pParse.pNewTable );
      }

#if !SQLITE_OMIT_TRIGGER
      sqlite3DeleteTrigger( db, ref pParse.pNewTrigger );
#endif
      sqlite3DbFree( db, ref pParse.apVarExpr );
      sqlite3DbFree( db, ref pParse.aAlias );
      while ( pParse.pAinc != null )
      {
        AutoincInfo p = pParse.pAinc;
        pParse.pAinc = p.pNext;
        sqlite3DbFree( db, ref p );
      }
      while ( pParse.pZombieTab != null )
      {
        Table p = pParse.pZombieTab;
        pParse.pZombieTab = p.pNextZombie;
        sqlite3DeleteTable( ref p );
      }
      if ( nErr > 0 && pParse.rc == SQLITE_OK )
      {
        pParse.rc = SQLITE_ERROR;
      }
      return nErr;
    }
  }
}
Back to Top