在FMDB中使用了一个variables表名
我在数据库中使用variablestable'name,比如:
BOOL judge=[self.database executeUpdate:@"insert into ?(id,name,headimg,excerpt,postion) values (?,?,?,?,?)",tableName,aID,aName,aImg,aExcept,aCoor];
但是这个“插入”不起作用! 我不怎么做
如果你想使用tablename作为variables,你可以尝试下面的内容
NSString *sql=[NSString stringWithFormat:@"insert into %@ (id,name,headimg,excerpt,postion) values (%@,%@,%@,%@,%@)",tablename,aID,aName,aImg,aExcept,aCoor]; BOOL judge=[self.database executeUpdate:sql];
尝试这个:
NSString *query = [NSString stringWithFormat:@"insert into '%@' (id,name,headimg,excerpt,postion) values (%d,'%@','%@','%@','%@')",tableName,aID,aName,aImg,aExcept,aCoor]; BOOL judge=[self.database executeUpdate:query];
还要根据您的需要更改格式说明符。 (可能是id被如此使用%d,其他variables被视为string,所以使用%@)
我这样做的方式保持SQLite绑定工作:)
NSString * queryString = [NSString stringWithFormat:@"SELECT * FROM %@ ",[self modelDatabaseTableName]]; queryString = [queryString stringByAppendingString:@"WHERE UUID = ?;"]; FMResultSet *existenceCheckResultSet = [database executeQuery:queryString,[modelObject valueForKey:@"UUID"]];
希望能帮助到你。
Giova