views:

216

answers:

1

I am having some problem with sqlite. I want to insert some data to database,however,when I use the function

sqlite3_exec(db,sql,0,0,&zErrMsg);,

the zErrMsg returns:

near '\x90' syntax error.

the code is :

(void) ExecuteCommand:(NSString *)command DBRef:(sqlite3 *)db
{
    const char *sql = [command UTF8String];    
    char *zErrMsg  = 0;

    sqlite3_exec(db,sql,0,0,&zErrMsg);    
    sqlite3_free(zErrMsg);
}

I inserted some characters successfully before. But when I try this time, I failed. Does the problem due to the characters I use this time?

the sql statement is :

insert into b_1663 values(1,'1663','    \u7b2c1\u7ae0','\u9752\u86c7','    \u7b2c1\u7ae0

\u6211\u4eca\u5e74\u4e00\u5343\u4e09\u767e\u591a\u5c81\u3002

\u4f4f\u5728\u897f\u6e56\u4e00\u9053\u6865\u7684\u5e95\u4e0b\u3002\u8fd9\u6865\u53eb"\u65ad\u6865"\u3002\u4ece\u524d\u5b83\u4e0d\u53eb\u65ad\u6865\uff0c\u53eb\u6bb5\u5bb6\u6865\u3002

\u51ac\u5929\u3002\u6211\u5403\u9971\u4e86\uff0c\u5341\u5206\u6175\u5012\u5934\u5927\u7761\u3002\u7761\u5728\u8eab\u7554\u7684\u662f\u6211\u59ca\u59ca\u3002\u6211\u4eec\u76d8\u9519\u7ea0\u7f20\u7740\uff0c\u4e0d\u77e5\u4eba\u95f4\u4f55\u4e16\u3002

"\u8fd9\u662f\u9ad8\u4eba\uff01"

\u6211\u95ee\uff1a

"\u548c\u5c1a\u4e5f\u662f\u4eba\uff1f"

\u2014\u2014\u548c\u5c1a\u662f"\u4eba"\uff1f\u8fd9\u4e2a\u96c4\u4f1f\u505a\u5cb8\u7684\u548c\u5c1a\uff0c\u5e94\u8be5\u6bd4\u4eba\u9ad8\u660e\u70b9\u5427\uff1f

\u4ed6\u4e0a\u8def\u4e86\u3002

\u524d\u9762\u662f\u90a3\u8001\u548c\u5c1a\u3002 

');

the table structure:

create table b_1663(
   Num int primary key, 
   b_id varchar(20),
   b_sec_title varchar(50),
   b_name varchar(20),
   content text
);

Tell me if you know the answer.Thanks in advance!

A: 

Just a guess:

You probably need to quote the string (i.e. replace characters that cause the parser to barf), or, better yet, use a parametrized query. Parametrized queries look something like:

sql="insert foo into bar values (?,?)"
sqlexec(sql, data)
Bear
If so, the error should get on first line `const char *sql = [command UTF8String];` not on zErrMsg.
S.Mark
when I create the table , it works ok, the zErrMsg is nil.But when I insert something, it have syntax error. Does the problem due to the sql statement or the code?
syntax error? so you cannot compile at all or got exceptions?
S.Mark
If the zErMsg returns nil, it executes ok. If the zErMsg returns error, the db changes nothing.