Sarah wrote:
I'm facing new problems right now. the record cann't be inserted correctly when I execute the following statements. ......
char * database = ":memory:";
 sqlite3 * db;
  sqlite3_open(database, &db);
  sqlite3_exec(db, "create table myt(name varchar(30),age smallint)", NULL, 
NULL, NULL);
  sqlite3_exec(db, "insert into myt values('sarah',27)", NULL, NULL, NULL);
  sqlite3_exec(db, "select * from myt", NULL, NULL, NULL);
  sqlite3_close(db);
......

The behavior is that , when executing "insert into myt values('sarah',27)", the program goes into the following statements in sqlite3RunParser() and returns SQLITE_NOMEM. How and why? ......
abort_parse:
  if( zSql[i]==0 && nErr==0 && pParse->rc==SQLITE_OK ){
    if( lastTokenParsed!=TK_SEMI ){
      sqlite3Parser(pEngine, TK_SEMI, pParse->sLastToken, pParse);
      pParse->zTail = &zSql[i];
    }
    sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
  }
  sqlite3ParserFree(pEngine, sqlite3FreeX);
  if( sqlite3MallocFailed() ){
    pParse->rc = SQLITE_NOMEM;
  }
......

I totally have no idea of the principals of parser and how it works. Could 
someone tell me or give me some links?

finally, a stupid question:
should I add a semicolon at the end of the sql statement in sqlite3_exec(); 
Will that affect the execution of parser?

Sarah,

First adding a semicolon at the end of your SQL statements will make no difference.

What happened was that sqlite ran out of memory at some point while parsing your SQL. The sqlite3MallocFailed call simply checks if sqlite's internal malloc has ever failed to get the requested memory. Since this is a very simple SQL statement, the memory requirements for parsing should be quite low. I would suspect a problem with your memory allocator which is being called by sqlite through the standard malloc API. You should be able to see where this is happening by setting a breakpoint on sqlite3FailedMalloc in util.c and looking back through the call stack.

HTH
Dennis Cote

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to