From 6f8253e66be9dac0c3c96e16d9f97fda3fc7e818 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Tue, 9 Jun 2009 22:19:15 +0000 Subject: =?UTF-8?q?=E2=80=A2=20introduced=20the=20method=20(NSArray=20*)fe?= =?UTF-8?q?tchResultFieldsStructure=20to=20CMMCPResult=20-=20it=20returns?= =?UTF-8?q?=20an=20array=20of=20dicts=20containing=20general=20information?= =?UTF-8?q?=20about=20each=20field=20of=20the=20result=20array=20of=20the?= =?UTF-8?q?=20last=20executed=20query=20dict=20example=20so=20far=20for:?= =?UTF-8?q?=20SELECT=20ucs=5Fcomp=20AS=20co=20FROM=20comp=5Fucs3=20AS=20co?= =?UTF-8?q?=5Ftable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AUTO_INCREMENT_FLAG = 0; BINARY_FLAG = 0; BLOB_FLAG = 0; ENUM_FLAG = 0; MULTIPLE_KEY_FLAG = 1; NOT_NULL_FLAG = 0; NUM_FLAG = 0; PART_KEY_FLAG = 1; PRI_KEY_FLAG = 0; SET_FLAG = 0; UNIQUE_KEY_FLAG = 0; UNSIGNED_FLAG = 0; ZEROFILL_FLAG = 0; byte_length = 30; char_length = 10; charset_collation = utf8_general_ci; charset_name = utf8; charsetnr = 33; db = test; decimals = 0; flags = 16392; max_byte_length = 4; max_char_length = 1; name = co; org_name = ucs_comp; org_table = comp_ucs3; table = co_table; type = VARCHAR; typegrouping = string; Hint: To test that new method one can add the following code after the execution of a mysql query: NSArray *fStruct = [NSArray arrayWithArray:[theResult fetchResultFieldsStructure]]; --- Source/CMMCPResult.h | 21 +- Source/CMMCPResult.m | 649 ++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 582 insertions(+), 88 deletions(-) (limited to 'Source') diff --git a/Source/CMMCPResult.h b/Source/CMMCPResult.h index 68f7061a..e6c99fde 100644 --- a/Source/CMMCPResult.h +++ b/Source/CMMCPResult.h @@ -26,10 +26,29 @@ #import #import -#define FIELD_TYPE_BIT 16 +#define FIELD_TYPE_BIT 16 +#define MAGIC_BINARY_CHARSET_NR 63 @interface CMMCPResult : MCPResult +typedef struct st_our_charset +{ + unsigned int nr; + const char *name; + const char *collation; + unsigned int char_minlen; + unsigned int char_maxlen; +} OUR_CHARSET; + + - (id)fetchRowAsType:(MCPReturnType)aType; +- (NSArray *)fetchResultFieldsStructure; + + +- (NSString *)mysqlTypeToStringForType:(unsigned int)type withCharsetNr:(unsigned int)charsetnr withFlags:(unsigned int)flags withLength:(unsigned long long)length; +- (NSString *)mysqlTypeToGroupForType:(unsigned int)type withCharsetNr:(unsigned int)charsetnr withFlags:(unsigned int)flags; +- (NSString *)find_charsetName:(unsigned int)charsetnr; +- (NSString *)find_charsetCollation:(unsigned int)charsetnr; +- (unsigned int)find_charsetMaxByteLengthPerChar:(unsigned int)charsetnr; @end diff --git a/Source/CMMCPResult.m b/Source/CMMCPResult.m index cd3ce51a..b970b17d 100644 --- a/Source/CMMCPResult.m +++ b/Source/CMMCPResult.m @@ -27,16 +27,176 @@ @implementation CMMCPResult + +const OUR_CHARSET our_charsets60[] = +{ + { 1, "big5","big5_chinese_ci", 1, 2}, + { 3, "dec8", "dec8_swedisch_ci", 1, 1}, + { 4, "cp850", "cp850_general_ci", 1, 1}, + { 6, "hp8", "hp8_english_ci", 1, 1}, + { 7, "koi8r", "koi8r_general_ci", 1, 1}, + { 8, "latin1", "latin1_swedish_ci", 1, 1}, + { 9, "latin2", "latin2_general_ci", 1, 1}, + { 10, "swe7", "swe7_swedish_ci", 1, 1}, + { 11, "ascii", "ascii_general_ci", 1, 1}, + { 12, "ujis", "ujis_japanese_ci", 1, 3}, + { 13, "sjis", "sjis_japanese_ci", 1, 2}, + { 16, "hebrew", "hebrew_general_ci", 1, 1}, + { 18, "tis620", "tis620_thai_ci", 1, 1}, + { 19, "euckr", "euckr_korean_ci", 1, 2}, + { 22, "koi8u", "koi8u_general_ci", 1, 1}, + { 24, "gb2312", "gb2312_chinese_ci", 1, 2}, + { 25, "greek", "greek_general_ci", 1, 1}, + { 26, "cp1250", "cp1250_general_ci", 1, 1}, + { 28, "gbk", "gbk_chinese_ci", 1, 2}, + { 30, "latin5", "latin5_turkish_ci", 1, 1}, + { 32, "armscii8", "armscii8_general_ci", 1, 1}, + { 33, "utf8", "utf8_general_ci", 1, 3}, + { 35, "ucs2", "ucs2_general_ci", 2, 2}, + { 36, "cp866", "cp866_general_ci", 1, 1}, + { 37, "keybcs2", "keybcs2_general_ci", 1, 1}, + { 38, "macce", "macce_general_ci", 1, 1}, + { 39, "macroman", "macroman_general_ci", 1, 1}, + { 40, "cp852", "cp852_general_ci", 1, 1}, + { 41, "latin7", "latin7_general_ci", 1, 1}, + { 51, "cp1251", "cp1251_general_ci", 1, 1}, + { 57, "cp1256", "cp1256_general_ci", 1, 1}, + { 59, "cp1257", "cp1257_general_ci", 1, 1}, + { 63, "binary", "binary", 1, 1}, + { 92, "geostd8", "geostd8_general_ci", 1, 1}, + { 95, "cp932", "cp932_japanese_ci", 1, 2}, + { 97, "eucjpms", "eucjpms_japanese_ci", 1, 3}, + { 2, "latin2", "latin2_czech_cs", 1, 1}, + { 5, "latin1", "latin1_german_ci", 1, 1}, + { 14, "cp1251", "cp1251_bulgarian_ci", 1, 1}, + { 15, "latin1", "latin1_danish_ci", 1, 1}, + { 17, "filename", "filename", 1, 5}, + { 20, "latin7", "latin7_estonian_cs", 1, 1}, + { 21, "latin2", "latin2_hungarian_ci", 1, 1}, + { 23, "cp1251", "cp1251_ukrainian_ci", 1, 1}, + { 27, "latin2", "latin2_croatian_ci", 1, 1}, + { 29, "cp1257", "cp1257_lithunian_ci", 1, 1}, + { 31, "latin1", "latin1_german2_ci", 1, 1}, + { 34, "cp1250", "cp1250_czech_cs", 1, 1}, + { 42, "latin7", "latin7_general_cs", 1, 1}, + { 43, "macce", "macce_bin", 1, 1}, + { 44, "cp1250", "cp1250_croatian_ci", 1, 1}, + { 45, "utf8", "utf8_general_ci", 1, 1}, + { 46, "utf8", "utf8_bin", 1, 1}, + { 47, "latin1", "latin1_bin", 1, 1}, + { 48, "latin1", "latin1_general_ci", 1, 1}, + { 49, "latin1", "latin1_general_cs", 1, 1}, + { 50, "cp1251", "cp1251_bin", 1, 1}, + { 52, "cp1251", "cp1251_general_cs", 1, 1}, + { 53, "macroman", "macroman_bin", 1, 1}, + { 58, "cp1257", "cp1257_bin", 1, 1}, + { 60, "armascii8", "armascii8_bin", 1, 1}, + { 65, "ascii", "ascii_bin", 1, 1}, + { 66, "cp1250", "cp1250_bin", 1, 1}, + { 67, "cp1256", "cp1256_bin", 1, 1}, + { 68, "cp866", "cp866_bin", 1, 1}, + { 69, "dec8", "dec8_bin", 1, 1}, + { 70, "greek", "greek_bin", 1, 1}, + { 71, "hebew", "hebrew_bin", 1, 1}, + { 72, "hp8", "hp8_bin", 1, 1}, + { 73, "keybcs2", "keybcs2_bin", 1, 1}, + { 74, "koi8r", "koi8r_bin", 1, 1}, + { 75, "koi8u", "koi8u_bin", 1, 1}, + { 77, "latin2", "latin2_bin", 1, 1}, + { 78, "latin5", "latin5_bin", 1, 1}, + { 79, "latin7", "latin7_bin", 1, 1}, + { 80, "cp850", "cp850_bin", 1, 1}, + { 81, "cp852", "cp852_bin", 1, 1}, + { 82, "swe7", "swe7_bin", 1, 1}, + { 93, "geostd8", "geostd8_bin", 1, 1}, + { 83, "utf8", "utf8_bin", 1, 3}, + { 84, "big5", "big5_bin", 1, 2}, + { 85, "euckr", "euckr_bin", 1, 2}, + { 86, "gb2312", "gb2312_bin", 1, 2}, + { 87, "gbk", "gbk_bin", 1, 2}, + { 88, "sjis", "sjis_bin", 1, 2}, + { 89, "tis620", "tis620_bin", 1, 1}, + { 90, "ucs2", "ucs2_bin", 2, 2}, + { 91, "ujis", "ujis_bin", 1, 3}, + { 94, "latin1", "latin1_spanish_ci", 1, 1}, + { 96, "cp932", "cp932_bin", 1, 2}, + { 99, "cp1250", "cp1250_polish_ci", 1, 1}, + { 98, "eucjpms", "eucjpms_bin", 1, 3}, + { 128, "ucs2", "ucs2_unicode_ci", 2, 2}, + { 129, "ucs2", "ucs2_icelandic_ci", 2, 2}, + { 130, "ucs2", "ucs2_latvian_ci", 2, 2}, + { 131, "ucs2", "ucs2_romanian_ci", 2, 2}, + { 132, "ucs2", "ucs2_slovenian_ci", 2, 2}, + { 133, "ucs2", "ucs2_polish_ci", 2, 2}, + { 134, "ucs2", "ucs2_estonian_ci", 2, 2}, + { 135, "ucs2", "ucs2_spanish_ci", 2, 2}, + { 136, "ucs2", "ucs2_swedish_ci", 2, 2}, + { 137, "ucs2", "ucs2_turkish_ci", 2, 2}, + { 138, "ucs2", "ucs2_czech_ci", 2, 2}, + { 139, "ucs2", "ucs2_danish_ci", 2, 2}, + { 140, "ucs2", "ucs2_lithunian_ci", 2, 2}, + { 141, "ucs2", "ucs2_slovak_ci", 2, 2}, + { 142, "ucs2", "ucs2_spanish2_ci", 2, 2}, + { 143, "ucs2", "ucs2_roman_ci", 2, 2}, + { 144, "ucs2", "ucs2_persian_ci", 2, 2}, + { 145, "ucs2", "ucs2_esperanto_ci", 2, 2}, + { 146, "ucs2", "ucs2_hungarian_ci", 2, 2}, + { 147, "ucs2", "ucs2_sinhala_ci", 2, 2}, + { 192, "utf8mb3", "utf8mb3_general_ci", 1, 3}, + { 193, "utf8mb3", "utf8mb3_icelandic_ci", 1, 3}, + { 194, "utf8mb3", "utf8mb3_latvian_ci", 1, 3}, + { 195, "utf8mb3", "utf8mb3_romanian_ci", 1, 3}, + { 196, "utf8mb3", "utf8mb3_slovenian_ci", 1, 3}, + { 197, "utf8mb3", "utf8mb3_polish_ci", 1, 3}, + { 198, "utf8mb3", "utf8mb3_estonian_ci", 1, 3}, + { 119, "utf8mb3", "utf8mb3_spanish_ci", 1, 3}, + { 200, "utf8mb3", "utf8mb3_swedish_ci", 1, 3}, + { 201, "utf8mb3", "utf8mb3_turkish_ci", 1, 3}, + { 202, "utf8mb3", "utf8mb3_czech_ci", 1, 3}, + { 203, "utf8mb3", "utf8mb3_danish_ci", 1, 3}, + { 204, "utf8mb3", "utf8mb3_lithunian_ci", 1, 3}, + { 205, "utf8mb3", "utf8mb3_slovak_ci", 1, 3}, + { 206, "utf8mb3", "utf8mb3_spanish2_ci", 1, 3}, + { 207, "utf8mb3", "utf8mb3_roman_ci", 1, 3}, + { 208, "utf8mb3", "utf8mb3_persian_ci", 1, 3}, + { 209, "utf8mb3", "utf8mb3_esperanto_ci", 1, 3}, + { 210, "utf8mb3", "utf8mb3_hungarian_ci", 1, 3}, + { 211, "utf8mb3", "utf8mb3_sinhala_ci", 1, 3}, + { 224, "utf8", "utf8_unicode_ci", 1, 3}, + { 225, "utf8", "utf8_icelandic_ci", 1, 3}, + { 226, "utf8", "utf8_latvian_ci", 1, 3}, + { 227, "utf8", "utf8_romanian_ci", 1, 3}, + { 228, "utf8", "utf8_slovenian_ci", 1, 3}, + { 229, "utf8", "utf8_polish_ci", 1, 3}, + { 230, "utf8", "utf8_estonian_ci", 1, 3}, + { 231, "utf8", "utf8_spanish_ci", 1, 3}, + { 232, "utf8", "utf8_swedish_ci", 1, 3}, + { 233, "utf8", "utf8_turkish_ci", 1, 3}, + { 234, "utf8", "utf8_czech_ci", 1, 3}, + { 235, "utf8", "utf8_danish_ci", 1, 3}, + { 236, "utf8", "utf8_lithuanian_ci", 1, 3}, + { 237, "utf8", "utf8_slovak_ci", 1, 3}, + { 238, "utf8", "utf8_spanish2_ci", 1, 3}, + { 239, "utf8", "utf8_roman_ci", 1, 3}, + { 240, "utf8", "utf8_persian_ci", 1, 3}, + { 241, "utf8", "utf8_esperanto_ci", 1, 3}, + { 242, "utf8", "utf8_hungarian_ci", 1, 3}, + { 243, "utf8", "utf8_sinhala_ci", 1, 3}, + { 254, "utf8mb3", "utf8mb3_general_cs", 1, 3}, + { 0, NULL, NULL, 0, 0} +}; + + /* modified version for use with sequel-pro */ - (id)fetchRowAsType:(MCPReturnType)aType { - MYSQL_ROW theRow; - unsigned long *theLengths; - MYSQL_FIELD *theField; + MYSQL_ROW theRow; + unsigned long *theLengths; + MYSQL_FIELD *theField; int i; - id theReturn; + id theReturn; if (mResult == NULL) { // If there is no results, returns nil, as after the last row... @@ -48,104 +208,419 @@ modified version for use with sequel-pro return nil; } - switch (aType) { - case MCPTypeArray: - theReturn = [NSMutableArray arrayWithCapacity:mNumOfFields]; - break; - case MCPTypeDictionary: - if (mNames == nil) { - [self fetchFieldNames]; - } - theReturn = [NSMutableDictionary dictionaryWithCapacity:mNumOfFields]; - break; - default : - NSLog (@"Unknown type : %d, will return an Array!\n", aType); - theReturn = [NSMutableArray arrayWithCapacity:mNumOfFields]; - break; - } - - theLengths = mysql_fetch_lengths(mResult); - theField = mysql_fetch_fields(mResult); - - for (i=0; inr == charsetnr) + return [self stringWithCString:c->name]; + ++c; + } while (c[0].nr != 0); + return @"UNKNOWN"; +} + +/* + * Convert a mysql_charsetnr into a collation name as string + */ +- (NSString *)find_charsetCollation:(unsigned int)charsetnr +{ + const OUR_CHARSET * c = our_charsets60; + + do { + if (c->nr == charsetnr) + return [self stringWithCString:c->collation]; + ++c; + } while (c[0].nr != 0); + return @"UNKNOWN"; +} + +/* + * Return the max byte length to store a char by using + * a specific mysql_charsetnr + */ +- (unsigned int)find_charsetMaxByteLengthPerChar:(unsigned int)charsetnr +{ + const OUR_CHARSET * c = our_charsets60; + + do { + if (c->nr == charsetnr) + return c->char_maxlen; + ++c; + } while (c[0].nr != 0); + return 1; +} + + @end -- cgit v1.2.3