Question: SQLite - Get records which is not start with alphabet - IOS - Objective C

Question

SQLite - Get records which is not start with alphabet - IOS - Objective C

Answers 1
Added at 2017-06-14 15:06
Tags
Question

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]'
Answers to

SQLite - Get records which is not start with alphabet - IOS - Objective C

nr: #1 dodano: 2017-06-14 22:06

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]*'
Source Show
◀ Wstecz