• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Application crashing due to unicode characters in string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Application crashing due to unicode characters in string


  • Subject: Re: Application crashing due to unicode characters in string
  • From: "email@hidden" <email@hidden>
  • Date: Wed, 1 Dec 2010 17:05:39 +0000

On 1 Dec 2010, at 14:26, Devarshi Kulshreshtha wrote:
>
> Problem is - when any string to be inserted contains unicode character such
> as: \U00a0 or \U2022 or \U2019, it crashes.
>
> The part of code which crashes is this-
>
> NSString *insertQuery = @"insert into XYZ(field1,field2) values
> (@"1",[recordDict objectForKey:@"field2"]);
>
> // recordDict contains value: @"\U00a0 \U00a0 \U00a0 \U00a0The
> Cadfsdfsdfptain\U2019s" for key: @"field2"
>
> sqlite3_stmt *insertStmnt;
> const char *sql = [insertQuery cStringUsingEncoding:1];

You have a requested an ASCII encoding using
- (const char *)cStringUsingEncoding:(NSStringEncoding)encoding

A NULL return indicates that the receiver cannot be losslessly converted to the desired encoding (a clear case of  read the manual).

The sqlite3_prepare_v2 function prototype indicates that you should be using UTF8 encoding. This will probably handle most of the UTF that you throw at it.

int sqlite3_prepare_v2(
  sqlite3 *db,            /* Database handle */
  const char *zSql,       /* SQL statement, UTF-8 encoded */
  int nByte,              /* Maximum length of zSql in bytes. */
  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
);


Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Application crashing due to unicode characters in string (From: Devarshi Kulshreshtha <email@hidden>)

  • Prev by Date: Streaming with offset
  • Next by Date: NIB Object instantiation of missing class
  • Previous by thread: Re: Application crashing due to unicode characters in string
  • Next by thread: Re: UIWindow orientation
  • Index(es):
    • Date
    • Thread