0

IOS - Objective C - SQLite Query.

I want records from user table which is name start with a special character or digit or else (Not start with alphabet a-z or A-Z).

If i have tried like following query then i got a result which is name start with 'a'.

  char ch = 'a';
    
  NSLog(@"%@",[db writeQuery:[NSString stringWithFormat:@"SELECT * from user where first_name like '%c%%'",ch]]);

If have tried following query, But got app crash.

 NSLog(@"%@",[db writeQuery:[NSString stringWithFormat:@"SELECT * from user where first_name REGEXP '^[^a-zA-Z]'"]]);

Got error like follow.

SQLite Prepare Failed: no such function: REGEXP

  • Query: SELECT * from user where first_name REGEXP '^[^a-zA-Z]'
Community
  • 1
  • 1
AtulParmar
  • 4,358
  • 1
  • 24
  • 45

1 Answers1

1

REGEXP is not available by default; you'd have to add your own implementation for it to work.

You can get this to work with GLOB instead:

... WHERE first_name GLOB '[^a-zA-Z]*'
CL.
  • 173,858
  • 17
  • 217
  • 259