Skip to content

Commit

Permalink
Merge pull request #945 from gduh/fix-875-cannot-create-foreign-key
Browse files Browse the repository at this point in the history
#changed - foreign key creation when skip-show-database is on
  • Loading branch information
Jason-Morcos committed Mar 7, 2021
2 parents a704611 + e29d0ca commit 6018892
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Resources/Localization/en.lproj/Localizable.strings
Expand Up @@ -3288,6 +3288,9 @@
/* Menu item title for checking for updates */
"Check for updates" = "Check for updates";

/* Warning message during connection in case the variable skip-show-database is set to ON */
"The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges." = "The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges.";

/* Error alert title when the request to GitHub fails */
"GitHub Request Failed" = "GitHub Request Failed";

Expand Down
3 changes: 3 additions & 0 deletions Resources/Localization/es-ES.lproj/Localizable.strings
Expand Up @@ -3233,3 +3233,6 @@

/* New Connection Error informative message */
"Failed to create new database connection window. Please restart Sequel Ace and try again." = "Failed to create new database connection window. Please restart Sequel Ace and try again.";

/* Warning message during connection in case the variable skip-show-database is set to ON */
"The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges." = "The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges.";
3 changes: 3 additions & 0 deletions Resources/Localization/es.lproj/Localizable.strings
Expand Up @@ -3233,3 +3233,6 @@

/* New Connection Error informative message */
"Failed to create new database connection window. Please restart Sequel Ace and try again." = "Failed to create new database connection window. Please restart Sequel Ace and try again.";

/* Warning message during connection in case the variable skip-show-database is set to ON */
"The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges." = "The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges.";
3 changes: 3 additions & 0 deletions Resources/Localization/zh-Hans.lproj/Localizable.strings
Expand Up @@ -3233,3 +3233,6 @@

/* New Connection Error informative message */
"Failed to create new database connection window. Please restart Sequel Ace and try again." = "Failed to create new database connection window. Please restart Sequel Ace and try again.";

/* Warning message during connection in case the variable skip-show-database is set to ON */
"The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges." = "The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges.";
3 changes: 3 additions & 0 deletions Resources/Localization/zh-Hant.lproj/Localizable.strings
Expand Up @@ -3233,3 +3233,6 @@

/* New Connection Error informative message */
"Failed to create new database connection window. Please restart Sequel Ace and try again." = "Failed to create new database connection window. Please restart Sequel Ace and try again.";

/* Warning message during connection in case the variable skip-show-database is set to ON */
"The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges." = "The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges.";
10 changes: 10 additions & 0 deletions Source/Controllers/MainViewControllers/SPDatabaseDocument.m
Expand Up @@ -413,6 +413,16 @@ - (void)setConnection:(SPMySQLConnection *)theConnection
// Ensure the connection encoding is set to utf8 for database/table name retrieval
[mySQLConnection setEncoding:@"utf8mb4"];

// Check if skip-show-database is set to ON
SPMySQLResult *result = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'skip_show_database'"];
[result setReturnDataAsStrings:YES];
if(![mySQLConnection queryErrored] && [result numberOfRows] == 1) {
NSString *skip_show_database = [[result getRowAsDictionary] objectForKey:@"Value"];
if ([skip_show_database.lowercaseString isEqualToString:@"on"]) {
[NSAlert createWarningAlertWithTitle:NSLocalizedString(@"Warning",@"warning") message:NSLocalizedString(@"The skip-show-database variable of the database server is set to ON. Thus, you won't be able to list databases unless you have the SHOW DATABASES privilege.\n\nHowever, the databases are still accessible directly through SQL queries depending on your privileges.", @"Warning message during connection in case the variable skip-show-database is set to ON") callback:nil];
}
}

// Update the database list
[self setDatabases:self];

Expand Down
Expand Up @@ -141,9 +141,12 @@ - (IBAction)confirmAddRelation:(id)sender
NSString *thisTable = [tablesListInstance tableName];
NSString *thisColumn = [columnPopUpButton titleOfSelectedItem];
NSString *thatDatabase = [refDatabasePopUpButton titleOfSelectedItem];
NSString *thatTable = [refTablePopUpButton titleOfSelectedItem];
NSString *thatColumn = [refColumnPopUpButton titleOfSelectedItem];

if (!thatDatabase) {
thatDatabase = [tableDocumentInstance database];
}
NSString *thatTable = [refTablePopUpButton titleOfSelectedItem];
NSString *thatColumn = [refColumnPopUpButton titleOfSelectedItem];

NSString *query = [NSString stringWithFormat:@"ALTER TABLE %@ ADD ",[thisTable backtickQuotedString]];

// Set constraint name?
Expand Down Expand Up @@ -587,6 +590,9 @@ - (void)_updateAvailableTables
{
// Get selected database
NSString *database = [refDatabasePopUpButton titleOfSelectedItem];
if (!database) {
database = [tableDocumentInstance database];
}

[refTablePopUpButton setEnabled:NO];
[refColumnPopUpButton setEnabled:NO];
Expand Down

0 comments on commit 6018892

Please sign in to comment.