Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 04-05-2011, 10:17 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 6
ricuff is on a distinguished road
Default SQlite Behaves strange

Hi guys
I am developing an app that uses sqlite to store info about hotels. The table in the sqlite db is very simple, id, name, address.

I tried this sql using firefox Sqlite manager

select hotels.name,hotels.address from hotels where hotels.name like '%%hotel%%'

and I get the results

if I use this code it gives me no results at all

-(NSMutableArray*)searchString
{
NSMutableArray *ar1=[[[NSMutableArray alloc]init]autorelease];
int count = 0;
sqlite3_stmt *selectstmt;NSString *query = [NSString stringWithFormat:@"select hotels.name,hotels.address from hotels where hotels.name like '%%hotel%%'"];


NSLog(@"query %@ ", query);
const char * sql = [query UTF8String];
if (sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
{
while(sqlite3_step(selectstmt) == SQLITE_ROW)
{
element *x=[[element alloc]init];
x.name = [NSString stringWithUTF8Stringchar*)sqlite3_column_text(se lectstmt, 1)];
x.address = [NSString stringWithUTF8Stringchar*)sqlite3_column_text(se lectstmt, 2)];
}
}
}

if I change the sql query in select * from hotels' it works pefectly
-(NSMutableArray*)searchString
{
NSMutableArray *ar1=[[[NSMutableArray alloc]init]autorelease];
int count = 0;
sqlite3_stmt *selectstmt;NSString *query = [NSString stringWithFormat:@"select * from hotels'"];


NSLog(@"query %@ ", query);
const char * sql = [query UTF8String];
if (sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
{
while(sqlite3_step(selectstmt) == SQLITE_ROW)
{
element *x=[[element alloc]init];
x.name = [NSString stringWithUTF8Stringchar*)sqlite3_column_text(se lectstmt, 1)];
x.address = [NSString stringWithUTF8Stringchar*)sqlite3_column_text(se lectstmt, 2)];
}
}
}


I wonder if there are some limitations on the query

thanks for your time
ricuff is offline   Reply With Quote
Old 04-05-2011, 11:55 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

First, when you are posting code, please include it inside CODE tags. Code smiley faces are not funny

Second, you do realize that the SQL "sqlite3_column*" statements count fields starting from zero? So you are asking it to place the address in the name field. You can verify this at Result Values From A Query

Last, you should be more specific when saying "No results at all". Did you breakpoint or NSLog inside the while loop and see that there were no rows returned? A simple log statement dumping each name would probably have showed that your loop was returning the proper number of rows.
lgehrig1 is offline   Reply With Quote
Old 04-05-2011, 02:56 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 6
ricuff is on a distinguished road
Default

Sorry I forgot the CODE tags, I counted the rows after the query is executed and it returns 0 rows.

What makes me confused is that if I use the query


Code:
select * from hotels everything works perfectly
if I use

Code:
select hotels.name,hotels.address from hotels where hotels.name like '%%hotel%%'

it says no results even though I am sure there are . Thanks anyway
ricuff is offline   Reply With Quote
Old 10-20-2011, 10:57 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 113
jonusx is on a distinguished road
Default

I suggest you move to core data if you're using the database like that. I think you'll encounter less issues
__________________
What do you have to share? Share and view pics Oneshare

Play Magic: The Gathering? Try The Sylvan Archives!

Warhammer 40k your thing? W40k Manager is your thing.

Like karaoke? Try iSing Karaoke Locator
jonusx is offline   Reply With Quote
Old 12-09-2011, 10:38 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 53
fouldsc is on a distinguished road
Default

Quote:
Originally Posted by ricuff View Post
Sorry I forgot the CODE tags, I counted the rows after the query is executed and it returns 0 rows.

What makes me confused is that if I use the query


Code:
select * from hotels everything works perfectly
if I use

Code:
select hotels.name,hotels.address from hotels where hotels.name like '%%hotel%%'

it says no results even though I am sure there are . Thanks anyway
'%%hotel%%' is the problem , only needs to be '%hotel%' if you totally wildcarding it.

I recommend : SQLite Database Browser

Start your app in simulator , load database in this and try your SQL commands direct on the database rather than using firefox.
fouldsc is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 376
16 members and 360 guests
AyClass, baja_yu, checkright, dre, epaga, fvisticot, givensur, Meoz, Newbie123, Objective Zero, Punkjumper, reficul, sacha1996, skrew88, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,642
Threads: 94,110
Posts: 402,857
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pinacate
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:33 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0