私は mySql Objective-C ライブラリを使用しています: http://www.karlkraft.com/index.php/2010/09/17/mysql-for-iphone-and-osx/ と LIKE ステートメントでキリル記号を使用しようとしています:
NSString *cmd = [NSString stringWithFormat:@"select id,qrId,name,surname from users where name like '%%%@%%'",_nameField.text];
userFetch = [MysqlFetch fetchWithCommand:cmd onConnection:myConnection];
英語の文字で動作しますが、_nameField.text にキリル文字を使用すると、次のエラーが表示されます: *キャッチされない例外 'MysqlException' が原因でアプリを終了しています。構文; ''%–∞%' at line 1' 付近で使用する正しい構文については、MySQL サーバーのバージョンに対応するマニュアルを確認してください。
MysqlFetch.m で、コマンドが UT8String に変換されるため、mysql_stmt_prepare で例外が発生します。
if (mysql_stmt_prepare(myStatement, [s UTF8String],[s length])) {
[MysqlException raiseConnection:connection
withFormat:@"Could not perform mysql_stmt_bind_result() Error #%d:%s"
,mysql_errno(connection.connection),
mysql_error(connection.connection)];
}
MysqlInsert を使用して、cyrylic NSStrings で Insert を実行できます。フィールド値 (キリル記号を含む可能性があります) がなく、フィールド名のみがあるため、例外は発生しません。
NSArray *keys = [rowData allKeys];
NSMutableString *cmd = [NSMutableString string];
[cmd appendFormat:@"INSERT INTO %@ ( ",table];
BOOL firstAdd=YES;
for (NSString *columnName in keys) {
if (firstAdd) {
[cmd appendFormat:@" %@ ",[columnName mysqlEscapeInConnection:connection]];
firstAdd=NO;
} else {
[cmd appendFormat:@", %@ ",[columnName mysqlEscapeInConnection:connection]];
}
}
[cmd appendFormat:@" ) values ( ",table];
firstAdd=YES;
for (NSString *columnName in keys) {
if (firstAdd) {
[cmd appendString:@" ? "];
firstAdd=NO;
} else {
[cmd appendString:@", ? "];
}
}
[cmd appendFormat:@" ) "];
MYSQL_STMT *myStatement = mysql_stmt_init(connection.connection);
if (mysql_stmt_prepare(myStatement, [cmd UTF8String],[cmd length])) {
[MysqlException raiseConnection:connection withFormat: @"mysql_stmt_prepare failed %@ %s",cmd, mysql_stmt_error(myStatement)];
}
値は後で追加されます。
NSObject *object = [rowData objectForKey:key];
if ([object isKindOfClass:[NSString class]]) {
NSString *s = (NSString *)object;
const char *ch = [s UTF8String];
binding[x].is_null= 0;
binding[x].buffer_type = MYSQL_TYPE_STRING;
binding[x].buffer = (void *)ch;
binding[x].buffer_length= strlen(ch);
}
テキストが多すぎて簡単な質問かもしれません: キリル文字の NSString を変換して MysqlUpdate で使用するにはどうすればよいですか?