PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://winphonesqlite.codeplex.com
C# | 673 lines | 528 code | 12 blank | 133 comment | 209 complexity | e9367b2c87fdde6360bf99ded71fcae6 MD5 | raw file
  1. using System;
  2. using System.Diagnostics;
  3. using System.Text;
  4. namespace NextLine.Data.SQLite.Wrapper
  5. {
  6. internal partial class Sqlite3
  7. {
  8. /*
  9. ** 2001 September 15
  10. **
  11. ** The author disclaims copyright to this source code. In place of
  12. ** a legal notice, here is a blessing:
  13. **
  14. ** May you do good and not evil.
  15. ** May you find forgiveness for yourself and forgive others.
  16. ** May you share freely, never taking more than you give.
  17. **
  18. *************************************************************************
  19. ** An tokenizer for SQL
  20. **
  21. ** This file contains C code that splits an SQL input string up into
  22. ** individual tokens and sends those tokens one-by-one over to the
  23. ** parser for analysis.
  24. *************************************************************************
  25. ** Included in SQLite3 port to C#-SQLite; 2008 Noah B Hart
  26. ** C#-SQLite is an independent reimplementation of the SQLite software library
  27. **
  28. ** SQLITE_SOURCE_ID: 2010-03-09 19:31:43 4ae453ea7be69018d8c16eb8dabe05617397dc4d
  29. **
  30. ** $Header$
  31. *************************************************************************
  32. */
  33. //#include "sqliteInt.h"
  34. //#include <stdlib.h>
  35. /*
  36. ** The charMap() macro maps alphabetic characters into their
  37. ** lower-case ASCII equivalent. On ASCII machines, this is just
  38. ** an upper-to-lower case map. On EBCDIC machines we also need
  39. ** to adjust the encoding. Only alphabetic characters and underscores
  40. ** need to be translated.
  41. */
  42. #if SQLITE_ASCII
  43. //# define charMap(X) sqlite3UpperToLower[(unsigned char)X]
  44. #endif
  45. #if SQLITE_EBCDIC
  46. //# define charMap(X) ebcdicToAscii[(unsigned char)X]
  47. //const unsigned char ebcdicToAscii[] = {
  48. /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
  49. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
  50. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
  51. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
  52. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3x */
  53. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 4x */
  54. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 5x */
  55. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, /* 6x */
  56. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 7x */
  57. // 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* 8x */
  58. // 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* 9x */
  59. // 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ax */
  60. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
  61. // 0, 97, 98, 99,100,101,102,103,104,105, 0, 0, 0, 0, 0, 0, /* Cx */
  62. // 0,106,107,108,109,110,111,112,113,114, 0, 0, 0, 0, 0, 0, /* Dx */
  63. // 0, 0,115,116,117,118,119,120,121,122, 0, 0, 0, 0, 0, 0, /* Ex */
  64. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Fx */
  65. //};
  66. #endif
  67. /*
  68. ** The sqlite3KeywordCode function looks up an identifier to determine if
  69. ** it is a keyword. If it is a keyword, the token code of that keyword is
  70. ** returned. If the input is not a keyword, TK_ID is returned.
  71. **
  72. ** The implementation of this routine was generated by a program,
  73. ** mkkeywordhash.h, located in the tool subdirectory of the distribution.
  74. ** The output of the mkkeywordhash.c program is written into a file
  75. ** named keywordhash.h and then included into this source file by
  76. ** the #include below.
  77. */
  78. //#include "keywordhash.h"
  79. /*
  80. ** If X is a character that can be used in an identifier then
  81. ** IdChar(X) will be true. Otherwise it is false.
  82. **
  83. ** For ASCII, any character with the high-order bit set is
  84. ** allowed in an identifier. For 7-bit characters,
  85. ** sqlite3IsIdChar[X] must be 1.
  86. **
  87. ** For EBCDIC, the rules are more complex but have the same
  88. ** end result.
  89. **
  90. ** Ticket #1066. the SQL standard does not allow '$' in the
  91. ** middle of identfiers. But many SQL implementations do.
  92. ** SQLite will allow '$' in identifiers for compatibility.
  93. ** But the feature is undocumented.
  94. */
  95. #if SQLITE_ASCII
  96. //#define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
  97. #endif
  98. #if SQLITE_EBCDIC
  99. //const char sqlite3IsEbcdicIdChar[] = {
  100. /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
  101. // 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 4x */
  102. // 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, /* 5x */
  103. // 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 6x */
  104. // 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, /* 7x */
  105. // 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, /* 8x */
  106. // 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, /* 9x */
  107. // 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, /* Ax */
  108. // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Bx */
  109. // 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Cx */
  110. // 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Dx */
  111. // 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* Ex */
  112. // 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, /* Fx */
  113. //};
  114. //#define IdChar(C) (((c=C)>=0x42 && sqlite3IsEbcdicIdChar[c-0x40]))
  115. #endif
  116. /*
  117. ** Return the length of the token that begins at z[iOffset + 0].
  118. ** Store the token type in *tokenType before returning.
  119. */
  120. static int sqlite3GetToken( string z, int iOffset, ref int tokenType )
  121. {
  122. int i;
  123. byte c = 0;
  124. switch ( z[iOffset + 0] )
  125. {
  126. case ' ':
  127. case '\t':
  128. case '\n':
  129. case '\f':
  130. case '\r':
  131. {
  132. testcase( z[iOffset + 0] == ' ' );
  133. testcase( z[iOffset + 0] == '\t' );
  134. testcase( z[iOffset + 0] == '\n' );
  135. testcase( z[iOffset + 0] == '\f' );
  136. testcase( z[iOffset + 0] == '\r' );
  137. for ( i = 1; z.Length > iOffset + i && sqlite3Isspace( z[iOffset + i] ); i++ ) { }
  138. tokenType = TK_SPACE;
  139. return i;
  140. }
  141. case '-':
  142. {
  143. if ( z.Length > iOffset + 1 && z[iOffset + 1] == '-' )
  144. {
  145. /* IMP: R-15891-05542 -- syntax diagram for comments */
  146. for ( i = 2; z.Length > iOffset + i && ( c = (byte)z[iOffset + i] ) != 0 && c != '\n'; i++ ) { }
  147. tokenType = TK_SPACE; /* IMP: R-22934-25134 */
  148. return i;
  149. }
  150. tokenType = TK_MINUS;
  151. return 1;
  152. }
  153. case '(':
  154. {
  155. tokenType = TK_LP;
  156. return 1;
  157. }
  158. case ')':
  159. {
  160. tokenType = TK_RP;
  161. return 1;
  162. }
  163. case ';':
  164. {
  165. tokenType = TK_SEMI;
  166. return 1;
  167. }
  168. case '+':
  169. {
  170. tokenType = TK_PLUS;
  171. return 1;
  172. }
  173. case '*':
  174. {
  175. tokenType = TK_STAR;
  176. return 1;
  177. }
  178. case '/':
  179. {
  180. if ( iOffset + 2 >= z.Length || z[iOffset + 1] != '*' )
  181. {
  182. tokenType = TK_SLASH;
  183. return 1;
  184. }
  185. /* IMP: R-15891-05542 -- syntax diagram for comments */
  186. for ( i = 3, c = (byte)z[iOffset + 2]; iOffset + i < z.Length && ( c != '*' || ( z[iOffset + i] != '/' ) && ( c != 0 ) ); i++ ) { c = (byte)z[iOffset + i]; }
  187. if ( iOffset + i == z.Length ) c = 0;
  188. if ( c != 0 ) i++;
  189. tokenType = TK_SPACE; /* IMP: R-22934-25134 */
  190. return i;
  191. }
  192. case '%':
  193. {
  194. tokenType = TK_REM;
  195. return 1;
  196. }
  197. case '=':
  198. {
  199. tokenType = TK_EQ;
  200. return 1 + ( z[iOffset + 1] == '=' ? 1 : 0 );
  201. }
  202. case '<':
  203. {
  204. if ( ( c = (byte)z[iOffset + 1] ) == '=' )
  205. {
  206. tokenType = TK_LE;
  207. return 2;
  208. }
  209. else if ( c == '>' )
  210. {
  211. tokenType = TK_NE;
  212. return 2;
  213. }
  214. else if ( c == '<' )
  215. {
  216. tokenType = TK_LSHIFT;
  217. return 2;
  218. }
  219. else
  220. {
  221. tokenType = TK_LT;
  222. return 1;
  223. }
  224. }
  225. case '>':
  226. {
  227. if ( z.Length > iOffset + 1 && ( c = (byte)z[iOffset + 1] ) == '=' )
  228. {
  229. tokenType = TK_GE;
  230. return 2;
  231. }
  232. else if ( c == '>' )
  233. {
  234. tokenType = TK_RSHIFT;
  235. return 2;
  236. }
  237. else
  238. {
  239. tokenType = TK_GT;
  240. return 1;
  241. }
  242. }
  243. case '!':
  244. {
  245. if ( z[iOffset + 1] != '=' )
  246. {
  247. tokenType = TK_ILLEGAL;
  248. return 2;
  249. }
  250. else
  251. {
  252. tokenType = TK_NE;
  253. return 2;
  254. }
  255. }
  256. case '|':
  257. {
  258. if ( z[iOffset + 1] != '|' )
  259. {
  260. tokenType = TK_BITOR;
  261. return 1;
  262. }
  263. else
  264. {
  265. tokenType = TK_CONCAT;
  266. return 2;
  267. }
  268. }
  269. case ',':
  270. {
  271. tokenType = TK_COMMA;
  272. return 1;
  273. }
  274. case '&':
  275. {
  276. tokenType = TK_BITAND;
  277. return 1;
  278. }
  279. case '~':
  280. {
  281. tokenType = TK_BITNOT;
  282. return 1;
  283. }
  284. case '`':
  285. case '\'':
  286. case '"':
  287. {
  288. int delim = z[iOffset + 0];
  289. testcase( delim == '`' );
  290. testcase( delim == '\'' );
  291. testcase( delim == '"' );
  292. for ( i = 1; ( iOffset + i ) < z.Length && ( c = (byte)z[iOffset + i] ) != 0; i++ )
  293. {
  294. if ( c == delim )
  295. {
  296. if ( z.Length > iOffset + i + 1 && z[iOffset + i + 1] == delim )
  297. {
  298. i++;
  299. }
  300. else
  301. {
  302. break;
  303. }
  304. }
  305. }
  306. if ( ( iOffset + i == z.Length && c != delim ) || z[iOffset + i] != delim )
  307. {
  308. tokenType = TK_ILLEGAL;
  309. return i + 1;
  310. }
  311. if ( c == '\'' )
  312. {
  313. tokenType = TK_STRING;
  314. return i + 1;
  315. }
  316. else if ( c != 0 )
  317. {
  318. tokenType = TK_ID;
  319. return i + 1;
  320. }
  321. else
  322. {
  323. tokenType = TK_ILLEGAL;
  324. return i;
  325. }
  326. }
  327. case '.':
  328. {
  329. #if !SQLITE_OMIT_FLOATING_POINT
  330. if ( !sqlite3Isdigit( z[iOffset + 1] ) )
  331. #endif
  332. {
  333. tokenType = TK_DOT;
  334. return 1;
  335. }
  336. /* If the next character is a digit, this is a floating point
  337. ** number that begins with ".". Fall thru into the next case */
  338. goto case '0';
  339. }
  340. case '0':
  341. case '1':
  342. case '2':
  343. case '3':
  344. case '4':
  345. case '5':
  346. case '6':
  347. case '7':
  348. case '8':
  349. case '9':
  350. {
  351. testcase( z[iOffset] == '0' ); testcase( z[iOffset] == '1' ); testcase( z[iOffset] == '2' );
  352. testcase( z[iOffset] == '3' ); testcase( z[iOffset] == '4' ); testcase( z[iOffset] == '5' );
  353. testcase( z[iOffset] == '6' ); testcase( z[iOffset] == '7' ); testcase( z[iOffset] == '8' );
  354. testcase( z[iOffset] == '9' );
  355. tokenType = TK_INTEGER;
  356. for ( i = 0; z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ); i++ ) { }
  357. #if !SQLITE_OMIT_FLOATING_POINT
  358. if ( z.Length > iOffset + i && z[iOffset + i] == '.' )
  359. {
  360. i++;
  361. while ( z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ) ) { i++; }
  362. tokenType = TK_FLOAT;
  363. }
  364. if ( z.Length > iOffset + i + 1 && ( z[iOffset + i] == 'e' || z[iOffset + i] == 'E' ) &&
  365. ( sqlite3Isdigit( z[iOffset + i + 1] )
  366. || z.Length > iOffset + i + 2 && ( ( z[iOffset + i + 1] == '+' || z[iOffset + i + 1] == '-' ) && sqlite3Isdigit( z[iOffset + i + 2] ) )
  367. )
  368. )
  369. {
  370. i += 2;
  371. while ( z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ) ) { i++; }
  372. tokenType = TK_FLOAT;
  373. }
  374. #endif
  375. while ( iOffset + i < z.Length && IdChar( (byte)z[iOffset + i] ) )
  376. {
  377. tokenType = TK_ILLEGAL;
  378. i++;
  379. }
  380. return i;
  381. }
  382. case '[':
  383. {
  384. for ( i = 1, c = (byte)z[iOffset + 0]; c != ']' && ( iOffset + i ) < z.Length && ( c = (byte)z[iOffset + i] ) != 0; i++ ) { }
  385. tokenType = c == ']' ? TK_ID : TK_ILLEGAL;
  386. return i;
  387. }
  388. case '?':
  389. {
  390. tokenType = TK_VARIABLE;
  391. for ( i = 1; z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ); i++ ) { }
  392. return i;
  393. }
  394. case '#':
  395. {
  396. for ( i = 1; z.Length > iOffset + i && sqlite3Isdigit( z[iOffset + i] ); i++ ) { }
  397. if ( i > 1 )
  398. {
  399. /* Parameters of the form #NNN (where NNN is a number) are used
  400. ** internally by sqlite3NestedParse. */
  401. tokenType = TK_REGISTER;
  402. return i;
  403. }
  404. /* Fall through into the next case if the '#' is not followed by
  405. ** a digit. Try to match #AAAA where AAAA is a parameter name. */
  406. goto case ':';
  407. }
  408. #if !SQLITE_OMIT_TCL_VARIABLE
  409. case '$':
  410. #endif
  411. case '@': /* For compatibility with MS SQL Server */
  412. case ':':
  413. {
  414. int n = 0;
  415. testcase( z[iOffset + 0] == '$' ); testcase( z[iOffset + 0] == '@' ); testcase( z[iOffset + 0] == ':' );
  416. tokenType = TK_VARIABLE;
  417. for ( i = 1; z.Length > iOffset + i && ( c = (byte)z[iOffset + i] ) != 0; i++ )
  418. {
  419. if ( IdChar( c ) )
  420. {
  421. n++;
  422. #if !SQLITE_OMIT_TCL_VARIABLE
  423. }
  424. else if ( c == '(' && n > 0 )
  425. {
  426. do
  427. {
  428. i++;
  429. } while ( ( iOffset + i ) < z.Length && ( c = (byte)z[iOffset + i] ) != 0 && !sqlite3Isspace( c ) && c != ')' );
  430. if ( c == ')' )
  431. {
  432. i++;
  433. }
  434. else
  435. {
  436. tokenType = TK_ILLEGAL;
  437. }
  438. break;
  439. }
  440. else if ( c == ':' && z[iOffset + i + 1] == ':' )
  441. {
  442. i++;
  443. #endif
  444. }
  445. else
  446. {
  447. break;
  448. }
  449. }
  450. if ( n == 0 ) tokenType = TK_ILLEGAL;
  451. return i;
  452. }
  453. #if !SQLITE_OMIT_BLOB_LITERAL
  454. case 'x':
  455. case 'X':
  456. {
  457. testcase( z[iOffset + 0] == 'x' ); testcase( z[iOffset + 0] == 'X' );
  458. if ( z.Length > iOffset + 1 && z[iOffset + 1] == '\'' )
  459. {
  460. tokenType = TK_BLOB;
  461. for ( i = 2; z.Length > iOffset + i && ( c = (byte)z[iOffset + i] ) != 0 && c != '\''; i++ )
  462. {
  463. if ( !sqlite3Isxdigit( c ) )
  464. {
  465. tokenType = TK_ILLEGAL;
  466. }
  467. }
  468. if ( i % 2 != 0 || z.Length == iOffset + i && c != '\'' ) tokenType = TK_ILLEGAL;
  469. if ( c != 0 ) i++;
  470. return i;
  471. }
  472. goto default;
  473. /* Otherwise fall through to the next case */
  474. }
  475. #endif
  476. default:
  477. {
  478. if ( !IdChar( (byte)z[iOffset] ) )
  479. {
  480. break;
  481. }
  482. for ( i = 1; i < z.Length - iOffset && IdChar( (byte)z[iOffset + i] ); i++ ) { }
  483. tokenType = keywordCode( z, iOffset, i );
  484. return i;
  485. }
  486. }
  487. tokenType = TK_ILLEGAL;
  488. return 1;
  489. }
  490. /*
  491. ** Run the parser on the given SQL string. The parser structure is
  492. ** passed in. An SQLITE_ status code is returned. If an error occurs
  493. ** then an and attempt is made to write an error message into
  494. ** memory obtained from sqlite3_malloc() and to make pzErrMsg point to that
  495. ** error message.
  496. */
  497. static int sqlite3RunParser( Parse pParse, string zSql, ref string pzErrMsg )
  498. {
  499. int nErr = 0; /* Number of errors encountered */
  500. int i; /* Loop counter */
  501. yyParser pEngine; /* The LEMON-generated LALR(1) parser */
  502. int tokenType = 0; /* type of the next token */
  503. int lastTokenParsed = -1; /* type of the previous token */
  504. byte enableLookaside; /* Saved value of db->lookaside.bEnabled */
  505. sqlite3 db = pParse.db; /* The database connection */
  506. int mxSqlLen; /* Max length of an SQL string */
  507. mxSqlLen = db.aLimit[SQLITE_LIMIT_SQL_LENGTH];
  508. if ( db.activeVdbeCnt == 0 )
  509. {
  510. db.u1.isInterrupted = false;
  511. }
  512. pParse.rc = SQLITE_OK;
  513. pParse.zTail = new StringBuilder( zSql );
  514. i = 0;
  515. Debug.Assert( pzErrMsg != null );
  516. pEngine = sqlite3ParserAlloc();//sqlite3ParserAlloc((void*(*)(size_t))sqlite3Malloc);
  517. if ( pEngine == null )
  518. {
  519. //// db.mallocFailed = 1;
  520. return SQLITE_NOMEM;
  521. }
  522. Debug.Assert( pParse.pNewTable == null );
  523. Debug.Assert( pParse.pNewTrigger == null );
  524. Debug.Assert( pParse.nVar == 0 );
  525. Debug.Assert( pParse.nVarExpr == 0 );
  526. Debug.Assert( pParse.nVarExprAlloc == 0 );
  527. Debug.Assert( pParse.apVarExpr == null );
  528. enableLookaside = db.lookaside.bEnabled;
  529. if ( db.lookaside.pStart != 0 ) db.lookaside.bEnabled = 1;
  530. while ( /* 0 == db.mallocFailed && */ i < zSql.Length )
  531. {
  532. Debug.Assert( i >= 0 );
  533. //pParse->sLastToken.z = &zSql[i];
  534. pParse.sLastToken.n = sqlite3GetToken( zSql, i, ref tokenType );
  535. pParse.sLastToken.z = zSql.Substring( i );
  536. i += pParse.sLastToken.n;
  537. if ( i > mxSqlLen )
  538. {
  539. pParse.rc = SQLITE_TOOBIG;
  540. break;
  541. }
  542. switch ( tokenType )
  543. {
  544. case TK_SPACE:
  545. {
  546. if ( db.u1.isInterrupted )
  547. {
  548. sqlite3ErrorMsg( pParse, "interrupt" );
  549. pParse.rc = SQLITE_INTERRUPT;
  550. goto abort_parse;
  551. }
  552. break;
  553. }
  554. case TK_ILLEGAL:
  555. {
  556. sqlite3DbFree( db, ref pzErrMsg );
  557. pzErrMsg = sqlite3MPrintf( db, "unrecognized token: \"%T\"",
  558. (object)pParse.sLastToken );
  559. nErr++;
  560. goto abort_parse;
  561. }
  562. case TK_SEMI:
  563. {
  564. //pParse.zTail = new StringBuilder(zSql.Substring( i,zSql.Length-i ));
  565. /* Fall thru into the default case */
  566. goto default;
  567. }
  568. default:
  569. {
  570. sqlite3Parser( pEngine, tokenType, pParse.sLastToken, pParse );
  571. lastTokenParsed = tokenType;
  572. if ( pParse.rc != SQLITE_OK )
  573. {
  574. goto abort_parse;
  575. }
  576. break;
  577. }
  578. }
  579. }
  580. abort_parse:
  581. pParse.zTail = new StringBuilder( zSql.Length <= i ? "" : zSql.Substring( i, zSql.Length - i ) );
  582. if ( zSql.Length >= i && nErr == 0 && pParse.rc == SQLITE_OK )
  583. {
  584. if ( lastTokenParsed != TK_SEMI )
  585. {
  586. sqlite3Parser( pEngine, TK_SEMI, pParse.sLastToken, pParse );
  587. }
  588. sqlite3Parser( pEngine, 0, pParse.sLastToken, pParse );
  589. }
  590. #if YYTRACKMAXSTACKDEPTH
  591. sqlite3StatusSet(SQLITE_STATUS_PARSER_STACK,
  592. sqlite3ParserStackPeak(pEngine)
  593. );
  594. #endif //* YYDEBUG */
  595. sqlite3ParserFree( pEngine, null );//sqlite3_free );
  596. db.lookaside.bEnabled = enableLookaside;
  597. //if ( db.mallocFailed != 0 )
  598. //{
  599. // pParse.rc = SQLITE_NOMEM;
  600. //}
  601. if ( pParse.rc != SQLITE_OK && pParse.rc != SQLITE_DONE && pParse.zErrMsg == "" )
  602. {
  603. sqlite3SetString( ref pParse.zErrMsg, db, sqlite3ErrStr( pParse.rc ) );
  604. }
  605. //assert( pzErrMsg!=0 );
  606. if ( pParse.zErrMsg != null )
  607. {
  608. pzErrMsg = pParse.zErrMsg;
  609. sqlite3_log(pParse.rc, "%s", pzErrMsg);
  610. pParse.zErrMsg = "";
  611. nErr++;
  612. }
  613. if ( pParse.pVdbe != null && pParse.nErr > 0 && pParse.nested == 0 )
  614. {
  615. sqlite3VdbeDelete( ref pParse.pVdbe );
  616. pParse.pVdbe = null;
  617. }
  618. #if !SQLITE_OMIT_SHARED_CACHE
  619. if ( pParse.nested == 0 )
  620. {
  621. sqlite3DbFree( db, ref pParse.aTableLock );
  622. pParse.aTableLock = null;
  623. pParse.nTableLock = 0;
  624. }
  625. #endif
  626. #if !SQLITE_OMIT_VIRTUALTABLE
  627. sqlite3DbFree(db,pParse.apVtabLock);
  628. #endif
  629. if ( !IN_DECLARE_VTAB )
  630. {
  631. /* If the pParse.declareVtab flag is set, do not delete any table
  632. ** structure built up in pParse.pNewTable. The calling code (see vtab.c)
  633. ** will take responsibility for freeing the Table structure.
  634. */
  635. sqlite3DeleteTable( ref pParse.pNewTable );
  636. }
  637. #if !SQLITE_OMIT_TRIGGER
  638. sqlite3DeleteTrigger( db, ref pParse.pNewTrigger );
  639. #endif
  640. sqlite3DbFree( db, ref pParse.apVarExpr );
  641. sqlite3DbFree( db, ref pParse.aAlias );
  642. while ( pParse.pAinc != null )
  643. {
  644. AutoincInfo p = pParse.pAinc;
  645. pParse.pAinc = p.pNext;
  646. sqlite3DbFree( db, ref p );
  647. }
  648. while ( pParse.pZombieTab != null )
  649. {
  650. Table p = pParse.pZombieTab;
  651. pParse.pZombieTab = p.pNextZombie;
  652. sqlite3DeleteTable( ref p );
  653. }
  654. if ( nErr > 0 && pParse.rc == SQLITE_OK )
  655. {
  656. pParse.rc = SQLITE_ERROR;
  657. }
  658. return nErr;
  659. }
  660. }
  661. }