PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/wp/csharp-sqlite-src/tokenize_c.cs

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