Objective C : Assertion Failure when reading data from database

I am using the functions describes HERE to access an sqlite database. I am having issue with the function:

-(NSArray *)find:(NSString *)field from:(NSString *)table where:(NSString *)condition.

This function works well for when the condition is nil and when the condition is a string without any format or method; ie it works well when it is either of the following

NSArray *result = [[SQLiteManager singleton] find:@"field1,field2" from:@"tableName" where:nil];

NSArray *result = [[SQLiteManager singleton] find:@"field1,field2" from:@"tableName" where:@"field2=value"];

However, I have a condition that should read from a UITextField. for example

NSArray *result = [[SQLiteManager singleton] find:@"field1,field2" from:@"tableName" where:[NSString stringWithFormat:@"field3=%@",[textFieldName text]]];

Unfortunately, the code breaks when I try this giving me an Assertion Failure error. ANy reason why? Any help is greatly appreciated.


At the very least you probably want to put single quotes around your %@. Like this:

NSArray *result = [[SQLiteManager singleton] find:@"field1,field2"
 from:@"tableName" where:[NSString stringWithFormat:@"field3='%@'",
 [textFieldName text]]];

But in addition to that you may also want to escape the string.

Need Your Help

Swift can't retrieve images from parse.com

ios xcode swift parse.com xcode7

I was using 6.4 of Xcode and it was working fine but when I updated to Xcode 7 it seems like query isn't working for photos.

Using Mono packages from badgerports, getting an exception on runtime

c# ubuntu mono

I'm trying to port over a .NET application that was written in C#, into linux.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.