iphone - My application crashes if i get no records from SQLite -


i'm working sqlite first time.... discount in db, , every things works fine, until select "nothing". happens if amount (adnumbers) higher or lower specified in db.

then when trying retrieve discount value db column error , application crashes. have tried make null check, doesn't seems help/work.

i have tried use while( sqlite3_step(compiledstatement) == sqlite_row){

but don't returned @ all...

please point me in right direction - how check if db returns records (adnumbers between values en db )

this method..

-(nsstring *) addisq:(nsstring *)strdisq:(nsinteger)adnumbers{

nsstring *strdiscount; strdiscount = @"00";  if(adstmt == nil) {     const char *sql = "select id, discount_type, description, ad_from, ad_to, ad_disq discount "                       "where (((discount_type)=?) , ((?) between ad_from , ad_to))";      if(sqlite3_prepare_v2(database, sql, -1, &adstmt, null) != sqlite_ok)         nsassert1(0, @"error while creating detail view statement. '%s'", sqlite3_errmsg(database)); }  sqlite3_bind_text(adstmt, 1, [strdisq utf8string], -1, sqlite_static); sqlite3_bind_int(adstmt, 2, adnumbers);     if(sqlite_done != sqlite3_step(adstmt)) {     nslog(@"select went ok, getting rows");     const char *columntext = (const char *)sqlite3_column_text(adstmt, 5);     if(columntext != null){         strdiscount = [nsstring stringwithutf8string:(char *)sqlite3_column_text(adstmt, 5)];         nslog(@"discount: %@", strdiscount);     }     else {         strdiscount = @"00";     } } else{     nsassert1(0, @"error while getting discount'%s'", sqlite3_errmsg(database)); }  //reset detail statement. sqlite3_reset(adstmt); return strdiscount; 

}

problem solved

nsassert1(0, @"error while getting discount'%s'", sqlite3_errmsg(database));

was making crash - expected - doh !


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -