Illep
Illep

Reputation: 16841

Writing SQL statement UPDATE query FMDB

I am having trouble UPDATING my database using FMDB. Here's my SQL

BOOL success = [db executeUpdate:[NSString stringWithFormat:@"UPDATE Person SET gender= '%@' WHERE name= '%@'",gender,name]];

I wonder if i made a mistake by using the = sign to compare (If so how could i correct it). Or any other solution. Help?

EDIT :

DB Error 7: out of memory
2012-03-30 16:10:03.341 den[5168:f803] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-03-30 16:10:03.343 den[5168:f803] DB Query: COMMIT TRANSACTION;

Upvotes: 0

Views: 10353

Answers (5)

user2991651
user2991651

Reputation: 1

Please try this:

NSString *updateQuery = [NSString stringWithFormat:@"UPDATE YOUR_DATABASE_TABLE_NAME SET row_value = %@",@"fmdb"];
Bool updateSuccess = [FMDataBaseObject ExecuteUpdate:updateQuery];

Upvotes: 0

toby941
toby941

Reputation: 378

try this:

BOOL success = [db executeUpdate:[NSString 
  stringWithFormat:@"UPDATE Person SET gender=? WHERE name LIKES ?",gender,name]];

In fmdb method [executeUpdate] use "?" instead of "%@"

Upvotes: 1

ccgus
ccgus

Reputation: 2916

You should probably use this format:

BOOL success = [db executeUpdate:@"UPDATE Person SET gender = ? WHERE name = ?",gender,name];

You're also using a commit without starting a transaction, so take that bit out as well.

Upvotes: 8

Deviator
Deviator

Reputation: 688

I used this:

FMDatabase * database = [self openDB:[DELEGATE getDatabasePath]];
NSString *query = @"";
query = [NSString stringWithFormat:@"UPDATE Person SET gender= '%@' WHERE name LIKES '%@'",gender,name];
[database executeUpdate:query];
[database commit];
[database close];

Upvotes: 3

Deviator
Deviator

Reputation: 688

Try this:

BOOL success = [db executeUpdate:[NSString stringWithFormat:@"UPDATE Person SET gender= '%@' WHERE name LIKES '%@'",gender,name]];

Upvotes: 0

Related Questions