简体   繁体   中英

Insert Special character in sqlite

I try this code.

    query = [NSString stringWithFormat:@"INSERT INTO Bookmark(Names,Details) Values('%@','%@')", delegate.str, delegate.str1];

    NSLog(@"%@",query);

    sqlite3_stmt *compiledStatement;

    if (sqlite3_open([databasepath UTF8String],&database) == SQLITE_OK)
    {

        if(sqlite3_prepare_v2(database,[query UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            if(SQLITE_DONE != sqlite3_step(compiledStatement))
                NSLog( @"Error while inserting data: '%s'", sqlite3_errmsg(database));
            else
                NSLog(@"New data inserted");

            sqlite3_reset(compiledStatement);
        }else
        {
            NSLog( @"Error while inserting '%s'", sqlite3_errmsg(database));
        }
        sqlite3_finalize(compiledStatement);
    }  

This is i want to store sqlite INSERT INTO Bookmark(Details) Values('Let's take an example, 23456789 divided by 7, 11, 13.

Make triplets as shown starting from unit's place.

23...456...789

Now add alternate triplets :

23 + 789 = 812 and 456.

Difference of these two sums : 812 - 456 = 356

Now divide this difference by 7, we get reminder 6

And divide this difference by 11, we get reminder 4

And divide this difference by 13, we get reminder 5')

And this the error after write your line...

2013-07-25 16:38:14.653 Maths Tricks Tips Patterns[4346:c07] Error while inserting 'near "s": syntax error'

How may i insert special charcter please help me out this thanks in advance.

You should NEVER form SQL queries manually using stringWithFormat etc.

Instead you should use prepared statements with variable binding. This will ensure the correct encoding and avoid SQL injections etc. You should begin by looking at this sqlite introduction .

The basic pattern is to use sqlite3_prepare followed by something like sqlite3_bind_text to set the value for one of the ? placeholders in your query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM