Skip to content

Commit

Permalink
Merge pull request #961 from Sequel-Ace/feature-requests-955
Browse files Browse the repository at this point in the history
#changed/#fixed - Feature requests 955
  • Loading branch information
Jason-Morcos committed Mar 16, 2021
2 parents 25942e3 + 9e4af4e commit 672b44a
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 44 deletions.
14 changes: 7 additions & 7 deletions Interfaces/Preferences.xib
Expand Up @@ -216,7 +216,7 @@ Gw
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<clipView key="contentView" id="eRr-LP-c79">
<rect key="frame" x="1" y="1" width="263" height="152"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" id="1774">
<rect key="frame" x="0.0" y="0.0" width="263" height="152"/>
Expand Down Expand Up @@ -1992,11 +1992,11 @@ Warning: If Sequel Ace and the server do not have at least one cipher suite in c
<constraint firstAttribute="height" constant="16" id="UHj-Wq-xiC"/>
<constraint firstAttribute="width" constant="11" id="nHg-43-jBJ"/>
</constraints>
<stepperCell key="cell" controlSize="small" continuous="YES" enabled="NO" alignment="left" increment="0.10000000000000001" minValue="0.5" maxValue="5" doubleValue="1" id="1526">
<stepperCell key="cell" controlSize="small" continuous="YES" enabled="NO" alignment="left" increment="0.10000000000000001" maxValue="5" doubleValue="1" id="1526">
<font key="font" metaFont="message" size="11"/>
</stepperCell>
<connections>
<action selector="takeFloatValueFrom:" target="1520" id="1529"/>
<action selector="delayStepperChanged:" target="2144" id="jTJ-rr-cCf"/>
<binding destination="117" name="enabled" keyPath="values.CustomQueryAutoComplete" id="1541"/>
<binding destination="117" name="value" keyPath="values.CustomQueryAutoCompleteDelay" id="1540"/>
</connections>
Expand All @@ -2021,11 +2021,11 @@ Warning: If Sequel Ace and the server do not have at least one cipher suite in c
<constraints>
<constraint firstAttribute="height" constant="22" id="UbU-HI-GT2"/>
</constraints>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" enabled="NO" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" alignment="right" title=".5" drawsBackground="YES" usesSingleLineMode="YES" id="1523">
<numberFormatter key="formatter" formatterBehavior="custom10_4" positiveFormat="#.0" alwaysShowsDecimalSeparator="YES" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="0" maximumIntegerDigits="1" minimumFractionDigits="1" maximumFractionDigits="1" decimalSeparator="." groupingSeparator="" id="1524">
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" enabled="NO" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" alignment="right" title="0.5" drawsBackground="YES" usesSingleLineMode="YES" id="1523">
<numberFormatter key="formatter" formatterBehavior="custom10_4" positiveFormat="#.0" allowsFloats="NO" alwaysShowsDecimalSeparator="YES" usesGroupingSeparator="NO" groupingSize="0" minimumIntegerDigits="1" maximumIntegerDigits="1" minimumFractionDigits="1" maximumFractionDigits="1" decimalSeparator="." groupingSeparator="" id="1524">
<nil key="negativeInfinitySymbol"/>
<nil key="positiveInfinitySymbol"/>
<real key="minimum" value="0.5"/>
<real key="minimum" value="0.0"/>
<real key="maximum" value="20"/>
</numberFormatter>
<font key="font" metaFont="message" size="11"/>
Expand Down Expand Up @@ -2362,7 +2362,7 @@ Warning: If Sequel Ace and the server do not have at least one cipher suite in c
<rect key="frame" x="20" y="46" width="500" height="212"/>
<clipView key="contentView" id="u3q-XC-nUM">
<rect key="frame" x="1" y="1" width="498" height="210"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="firstColumnOnly" tableStyle="fullWidth" alternatingRowBackgroundColors="YES" columnReordering="NO" columnSelection="YES" columnResizing="NO" autosaveColumns="NO" id="eH2-Ed-Xh3">
<rect key="frame" x="0.0" y="0.0" width="498" height="210"/>
Expand Down
3 changes: 3 additions & 0 deletions Resources/Localization/en.lproj/Localizable.strings
Expand Up @@ -3279,6 +3279,9 @@
/* Tool tip for the Show alert when update is available preference on the Notifications pane */
"Only available for GitHub downloads" = "Only available for GitHub downloads";

/* Tool tip warning for when the user sets auto-complete delay to zero */
"WARNING: Setting the auto-complete delay to 0.0 can result in strange output." = "WARNING: Setting the auto-complete delay to 0.0 can result in strange output.";

/* downloading new version bytes of bytes done */
"%@ of %@" = "%@ of %@";

Expand Down
2 changes: 2 additions & 0 deletions Resources/Plists/PreferenceDefaults.plist
Expand Up @@ -51,6 +51,8 @@
<true/>
<key>CustomQueryAutoCompleteDelay</key>
<real>1.5</real>
<key>CustomQueryAutoCompleteFuzzy</key>
<false/>
<key>CustomQueryAutoHelpDelay</key>
<real>1</real>
<key>CustomQueryAutoIndent</key>
Expand Down
119 changes: 91 additions & 28 deletions Source/Controllers/MainViewControllers/SPCustomQuery.m
Expand Up @@ -2129,38 +2129,101 @@ - (void)saveCellValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn
newObject = [mySQLConnection escapeAndQuoteString:desc];
}
}

[mySQLConnection queryString:
[NSString stringWithFormat:@"UPDATE %@.%@ SET %@.%@.%@ = %@ %@ LIMIT 1",
[[columnDefinition objectForKey:@"db"] backtickQuotedString], [[columnDefinition objectForKey:@"org_table"] backtickQuotedString],
[[columnDefinition objectForKey:@"db"] backtickQuotedString], [[columnDefinition objectForKey:@"org_table"] backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryString]];

// Check for errors while UPDATE
if ([mySQLConnection queryErrored]) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Error", @"error") message:[NSString stringWithFormat:NSLocalizedString(@"Couldn't write field.\nMySQL said: %@", @"message of panel when error while updating field to db"), [mySQLConnection lastErrorMessage]] callback:nil];
return;
}

// This shouldn't happen – for safety reasons
if ( ![mySQLConnection rowsAffectedByLastQuery] ) {
if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Warning", @"warning") message:NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db") callback:nil];

NSString *queryStr = [NSString stringWithFormat:@"UPDATE %@.%@ SET %@.%@.%@ = %@ %@ LIMIT 1",
[[columnDefinition objectForKey:@"db"] backtickQuotedString], [[columnDefinition objectForKey:@"org_table"] backtickQuotedString],
[[columnDefinition objectForKey:@"db"] backtickQuotedString], [[columnDefinition objectForKey:@"org_table"] backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryString];


SPLog(@"queryStr: %@", queryStr);

if ([prefs boolForKey:SPQueryWarningEnabled] == NO) {
[mySQLConnection queryString:queryStr];

// Check for errors while UPDATE
if ([mySQLConnection queryErrored]) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Error", @"error") message:[NSString stringWithFormat:NSLocalizedString(@"Couldn't write field.\nMySQL said: %@", @"message of panel when error while updating field to db"), [mySQLConnection lastErrorMessage]] callback:nil];
return;
}

// This shouldn't happen – for safety reasons
if ( ![mySQLConnection rowsAffectedByLastQuery] ) {
if ( [prefs boolForKey:SPShowNoAffectedRowsError] ) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Warning", @"warning") message:NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db") callback:nil];
} else {
NSBeep();
}
return;
}

// On success reload table data by executing the last query if reloading is enabled
if ([prefs boolForKey:SPReloadAfterEditingRow]) {
reloadingExistingResult = YES;
[self storeCurrentResultViewForRestoration];
[self performQueries:@[lastExecutedQuery] withCallback:NULL];
} else {
NSBeep();
// otherwise, just update the data in the data storage
[resultData replaceObjectInRow:rowIndex column:[[aTableColumn identifier] intValue] withObject:anObject];
}
return;
}

// On success reload table data by executing the last query if reloading is enabled
if ([prefs boolForKey:SPReloadAfterEditingRow]) {
reloadingExistingResult = YES;
[self storeCurrentResultViewForRestoration];
[self performQueries:@[lastExecutedQuery] withCallback:NULL];
} else {
// otherwise, just update the data in the data storage
[resultData replaceObjectInRow:rowIndex column:[[aTableColumn identifier] intValue] withObject:anObject];
else{
// we know it does, but let's check
BOOL queryContainsDestructiveSQL = [self queriesContainDestructiveSQL:@[queryStr]];
SPLog(@"queryContainsDestructiveSQL: %hhd", queryContainsDestructiveSQL);

if(queryContainsDestructiveSQL == YES){

NSMutableString *theQueries = [queryStr mutableCopy];

SPLog(@"theQueriesLen: %lu", theQueries.length);

NSString *infoText = [NSString stringWithFormat:NSLocalizedString(@"Do you really want to proceed with this query?\n\n %@", @"message of panel asking for confirmation for exec query"),theQueries];

if(theQueries.length > SPMaxQueryLengthForWarning){
theQueries = (NSMutableString*)[theQueries summarizeToLength:SPMaxQueryLengthForWarning withEllipsis:YES];
infoText = [NSString stringWithFormat:NSLocalizedString(@"Do you really want to proceed with these queries?\n\n %@", @"message of panel asking for confirmation for exec query"), theQueries];
}

[NSAlert createDefaultAlertWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Execute SQL?", @"Execute SQL?")]
message:infoText
primaryButtonTitle:NSLocalizedString(@"Proceed", @"Proceed")
primaryButtonHandler:^{
SPLog(@"User clicked Yes, exec queries");
[self->mySQLConnection queryString:queryStr];

// Check for errors while UPDATE
if ([self->mySQLConnection queryErrored]) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Error", @"error") message:[NSString stringWithFormat:NSLocalizedString(@"Couldn't write field.\nMySQL said: %@", @"message of panel when error while updating field to db"), [self->mySQLConnection lastErrorMessage]] callback:nil];
return;
}

// This shouldn't happen – for safety reasons
if ( ![self->mySQLConnection rowsAffectedByLastQuery] ) {
if ( [self->prefs boolForKey:SPShowNoAffectedRowsError] ) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Warning", @"warning") message:NSLocalizedString(@"The row was not written to the MySQL database. You probably haven't changed anything.\nReload the table to be sure that the row exists and use a primary key for your table.\n(This error can be turned off in the preferences.)", @"message of panel when no rows have been affected after writing to the db") callback:nil];
} else {
NSBeep();
}
return;
}

// On success reload table data by executing the last query if reloading is enabled
if ([self->prefs boolForKey:SPReloadAfterEditingRow]) {
self->reloadingExistingResult = YES;
[self storeCurrentResultViewForRestoration];
[self performQueries:@[self->lastExecutedQuery] withCallback:NULL];
} else {
// otherwise, just update the data in the data storage
[self->resultData replaceObjectInRow:rowIndex column:[[aTableColumn identifier] intValue] withObject:anObject];
}
}
cancelButtonHandler:^{
SPLog(@"Cancel pressed");
}];
}
}
} else {
}
else {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Error", @"error") message:[NSString stringWithFormat:NSLocalizedString(@"Updating field content failed. Couldn't identify field origin unambiguously (%1$ld matches). It's very likely that while editing this field of table `%2$@` was changed.", @"message of panel when error while updating field to db after enabling it"), (numberOfPossibleUpdateRows < 1) ? 0 : numberOfPossibleUpdateRows, [columnDefinition objectForKey:@"org_table"]] callback:nil];
}
}
Expand Down
16 changes: 16 additions & 0 deletions Source/Controllers/Preferences/Panes/SPEditorPreferencePane.m
Expand Up @@ -352,6 +352,22 @@ - (void)updateDisplayedEditorFontName
[colorSettingTableView reloadData];
}

- (IBAction)delayStepperChanged:(id)sender {

NSStepper *stepper = ((NSStepper*)sender);

if(stepper.floatValue < 0.1){
SPLog(@"delayStepperChanged to zero: %f", stepper.floatValue);
stepper.toolTip = NSLocalizedString(@"WARNING: Setting the auto-complete delay to 0.0 can result in strange output.", @"WARNING: Setting the auto-complete delay to 0.0 can result in strange output.");

// automatically display the tooltip
NSHelpManager *helpManager = [NSHelpManager sharedHelpManager];
[helpManager setContextHelp:[[NSAttributedString alloc] initWithString:stepper.toolTip] forObject:stepper];
[helpManager showContextHelpForObject:stepper locationHint:[NSEvent mouseLocation]];
[helpManager removeContextHelpForObject:stepper];
}
}

/**
* Updates the colour scheme selection menu according to the available schemes.
*/
Expand Down
1 change: 1 addition & 0 deletions Source/Other/Data/SPConstants.h
Expand Up @@ -367,6 +367,7 @@ extern NSString *SPCustomQueryUpdateAutoHelp;
extern NSString *SPCustomQueryAutoHelpDelay;
extern NSString *SPCustomQueryHighlightCurrentQuery;
extern NSString *SPCustomQueryEnableBracketHighlighting;
extern NSString *SPCustomQueryAutoCompleteFuzzy;
extern NSString *SPCustomQueryEditorTabStopWidth;
extern NSString *SPCustomQueryEditorCompleteWithBackticks;
extern NSString *SPCustomQueryAutoComplete;
Expand Down
1 change: 1 addition & 0 deletions Source/Other/Data/SPConstants.m
Expand Up @@ -179,6 +179,7 @@ - (SPTableViewType)tableViewTypeEnumFromString{
NSString *SPCustomQueryEditorCompleteWithBackticks = @"SPCustomQueryEditorCompleteWithBackticks";
NSString *SPCustomQueryAutoComplete = @"CustomQueryAutoComplete";
NSString *SPCustomQueryAutoCompleteDelay = @"CustomQueryAutoCompleteDelay";
NSString *SPCustomQueryAutoCompleteFuzzy = @"CustomQueryAutoCompleteFuzzy";
NSString *SPCustomQueryFunctionCompletionInsertsArguments = @"CustomQueryFunctionCompletionInsertsArguments";
NSString *SPCustomQueryEditorThemeName = @"CustomQueryEditorThemeName";
NSString *SPCustomQuerySoftIndent = @"CustomQuerySoftIndent";
Expand Down
6 changes: 4 additions & 2 deletions Source/Views/TextViews/SPTextView.h
Expand Up @@ -57,7 +57,8 @@ typedef struct {
IBOutlet SPTablesList *tablesListInstance;
IBOutlet SPCustomQuery *customQueryInstance;

BOOL autoindentEnabled;
BOOL autoindentEnabled;
BOOL autocompleteEnabled;
BOOL autopairEnabled;
BOOL autoindentIgnoresEnter;
BOOL autouppercaseKeywordsEnabled;
Expand Down Expand Up @@ -89,7 +90,6 @@ typedef struct {
BOOL completionIsOpen;
BOOL completionWasReinvokedAutomatically;
BOOL completionWasRefreshed;
BOOL completionFuzzyMode;
NSUInteger completionParseRangeLocation;

NSColor *queryHiliteColor;
Expand Down Expand Up @@ -123,6 +123,7 @@ typedef struct {
@property (assign) BOOL syntaxHighlightingApplied;
@property (assign) BOOL completionIsOpen;
@property (assign) BOOL completionWasReinvokedAutomatically;
@property (assign) BOOL completionFuzzyMode;

- (IBAction)showMySQLHelpForCurrentWord:(id)sender;

Expand All @@ -134,6 +135,7 @@ typedef struct {
- (BOOL) shiftSelectionRight;
- (BOOL) shiftSelectionLeft;
- (void) setAutoindent:(BOOL)enableAutoindent;
- (void) setAutoComplete:(BOOL)enableAutocomplete;
- (BOOL) autoindent;
- (void) setAutoindentIgnoresEnter:(BOOL)enableAutoindentIgnoresEnter;
- (BOOL) autoindentIgnoresEnter;
Expand Down

0 comments on commit 672b44a

Please sign in to comment.