objective c - insert special character on SQLite with FMDB -
i have issue inserting value table fmdb. have sql string this:
nsstring *sql = [nsstring stringwithformat:@"insert table( company, page_no ) values ('%@',%d,%d)",value1,value2,value3];
and use fmdb sql string above:
[fmdatabase: 0x433e80> executeupdate: sql]
it works, when use value1 = @"test'12"
. has character " ' "
, fails.
please me, want keep using method executeupdate
fmdb
thanks
looks you're not passing correct number of parameters query, you're listing 2 columns , passing 3 parameters. i'll assume that's typo.
you should parameterise query; use ?
parameters should go , instead pass them executeupdate
. way, problematic characters handled automatically.
that change code more like;
nsstring *sql = @"insert table(company, page_no) values (?,?)"; [database executeupdate:sql, value1, [nsnumber numberwithint:value2], nil];
note call numberwithint
required convert int
nsnumber
, since executeupdate
requires arguments objects, not primitive types.
Comments
Post a Comment