1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
//
// MQResultSetDataSource.m
// MySQL QueryBrowser
//
// Created by Alfredo Kojima on 3/6/05.
// Copyright 2005 MySQL AB. All rights reserved.
//
#import "MQResultSetDataSource.h"
#include "MYXResultSet.h"
@implementation MQResultSetDataSource
static MYXResultSetCallbacks callbacks= {
NULL,
NULL,
NULL
};
- (id)initWithResultSet:(MYX_RESULTSET*)rs lock: (NSLock *)lock
{
self= [super init];
if (self)
{
_resultSet= new MYXResultSet(rs, callbacks);
_zone= NSCreateZone(256*1024, 64*1024, NO);
_lock= lock;
}
return self;
}
- (MYX_RESULTSET*)resultset
{
return _resultSet->get_resultset();
}
- (MYXResultSet*)myxResultSet
{
return _resultSet;
}
- (void)dealloc
{
NSRecycleZone(_zone);
delete _resultSet;
[super dealloc];
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return _resultSet->get_row_count();
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
int column= [[aTableColumn identifier] intValue];
char *value;
size_t length;
if(_lock)
[_lock lock];
bool b= _resultSet->get(rowIndex, column, value, length);
if(_lock)
[_lock unlock];
if (b)
{
if (_resultSet->get_column_type(column) == MYX_RSCT_BLOB)
return @"";
else
return [[NSString allocWithZone:_zone] initWithBytesNoCopy:value
length:length
encoding:NSUTF8StringEncoding
freeWhenDone:NO];
}
else
return nil;
}
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
int column= [[aTableColumn identifier] intValue];
id ovalue= [self tableView:aTableView
objectValueForTableColumn:aTableColumn
row:rowIndex];
unsigned int nr;
if (ovalue && [ovalue isEqualTo:anObject])
return;
nr= _resultSet->get_row_count();
if ([anObject isKindOfClass:[NSString class]])
_resultSet->set(rowIndex, column, (const char*)[anObject cString], [anObject length]);
else
_resultSet->set(rowIndex, column, (const char*)[anObject bytes], [anObject length]);
if (_resultSet->get_row_count() != nr)
[aTableView noteNumberOfRowsChanged];
}
- (void)addRow
{
_resultSet->add_row();
}
- (void)deleteRow:(int)rowIndex
{
_resultSet->delete_row(rowIndex);
}
- (BOOL)isEditable
{
return _resultSet->get_resultset()->editable;
}
- (BOOL)editing
{
return _editEnabled;
}
- (BOOL)hasChanges
{
return _resultSet->has_changes();
}
- (void)setEditing:(BOOL)flag
{
_resultSet->set_placeholder_enabled(flag);
_editEnabled= flag;
}
- (MYXRSEditStatus)statusOfRow:(int)row
column:(int)column
{
return _resultSet->get_edit_status(row, column);
}
- (MYXRSCompareStatus)compareStatusOfRow:(int)row
column:(int)column
{
if(_lock)
[_lock lock];
MYXRSCompareStatus status= _resultSet->get_compare_status(row, column);
if(_lock)
[_lock unlock];
return status;
}
- (void)preCommit
{
_resultSet->pre_commit();
}
- (void)postCommit:(BOOL)failed
{
_resultSet->post_commit(failed);
}
- (void)discardChanges
{
_resultSet->discard_changes();
}
@end
|