aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-07-15 10:57:32 +0000
committerstuconnolly <stuart02@gmail.com>2010-07-15 10:57:32 +0000
commitb21ab51d37672f7e5934938d0ffde641f4de3a26 (patch)
tree0a2b670bebcaa55e046019794270beac0a699f6e /Frameworks
parent11bd9d4da5e42d5914b50c1f149d38ce6df863e7 (diff)
downloadsequelpro-b21ab51d37672f7e5934938d0ffde641f4de3a26.tar.gz
sequelpro-b21ab51d37672f7e5934938d0ffde641f4de3a26.tar.bz2
sequelpro-b21ab51d37672f7e5934938d0ffde641f4de3a26.zip
Improve handling of BIT fields, including:
- Exporting BIT fields properly in SQL dumps using b'x' notation. - Properly handling editing of BIT fields in both the content and custom query results views. - Correctly display BIT fields in the content view, where binary values are zero-padded to the specified length of the field. (Note, that the new BIT handling logic has only been added to MCPKit's MCPStreamingResult and MCPResult as the latter does not keep a record of the field's length which the new functionality depends on. Needs to be discussed).
Diffstat (limited to 'Frameworks')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m35
1 files changed, 32 insertions, 3 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
index 3b39738b..be09ed44 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPStreamingResult.m
@@ -45,8 +45,12 @@
@interface MCPStreamingResult (PrivateAPI)
+
+const char *_int2bin(unsigned int n, unsigned long len, char *buf);
+
- (void) _downloadAllData;
- (void) _freeAllDataWhenDone;
+
@end
@implementation MCPStreamingResult : MCPResult
@@ -159,7 +163,7 @@
- (NSArray *)fetchNextRowAsArray
{
MYSQL_ROW theRow;
- char *theRowData;
+ char *theRowData, *buf;
unsigned long *fieldLengths;
NSInteger i, copiedDataLength;
NSMutableArray *returnArray;
@@ -242,7 +246,12 @@
copiedDataLength += fieldLengths[i] + 1;
}
}
-
+
+ // If the field is of type BIT, then allocate the binary buffer
+ if (fieldDefinitions[i].type == FIELD_TYPE_BIT) {
+ buf = malloc(fieldDefinitions[i].length + 1);
+ }
+
// If the data hasn't already been detected as NULL - in which case it will have been
// set to NSNull - process the data by type
if (cellData == nil) {
@@ -283,7 +292,12 @@
break;
case FIELD_TYPE_BIT:
- cellData = (theData != NULL) ? [NSString stringWithFormat:@"%u", theData[0]] : @"";
+ // Get a binary representation of the data
+ _int2bin(theData[1], fieldDefinitions[i].length, buf);
+
+ cellData = (theData != NULL) ? [NSString stringWithUTF8String:buf] : @"";
+
+ free(buf);
break;
case FIELD_TYPE_TINY_BLOB:
@@ -414,6 +428,21 @@
@implementation MCPStreamingResult (PrivateAPI)
/**
+ * Provides a binary representation of the supplied integer (n) in the supplied buffer (buf). The resulting
+ * binary representation will be zero-padded according to the supplied field length (len).
+ */
+const char *_int2bin(unsigned int n, unsigned long len, char *buf)
+{
+ for (int i = (len - 1); i >= 0; --i)
+ {
+ buf[i] = (n & 1) ? '1' : '0';
+ n >>= 1;
+ }
+
+ buf[len] = '\0';
+}
+
+/**
* Used internally to download results in a background thread
*/
- (void)_downloadAllData