diff --git a/source/copytable.pas b/source/copytable.pas index 7494d818..e069c208 100644 --- a/source/copytable.pas +++ b/source/copytable.pas @@ -279,44 +279,48 @@ begin if radioStructure.Checked then strquery := strquery + ' WHERE 1 = 0'; - Mainform.Connection.Query(strquery, False); + try + Mainform.Connection.Query(strquery, False); - // Fix missing auto_increment property and CURRENT_TIMESTAMP defaults in new table - Results := Mainform.Connection.GetResults('SHOW FIELDS FROM ' + mainform.mask(oldtablename)); - Fixes := TWideStringlist.Create; - while not Results.Eof do begin - notnull := ''; - if Results.Col('Null') = '' then - notnull := 'NOT NULL'; - default := ''; - if Results.Col('Default') <> '' then begin - default := 'DEFAULT '; - if Results.Col('Default') = 'CURRENT_TIMESTAMP' then - default := default + Results.Col('Default') - else - default := default + esc(Results.Col('Default')); + // Fix missing auto_increment property and CURRENT_TIMESTAMP defaults in new table + Results := Mainform.Connection.GetResults('SHOW FIELDS FROM ' + mainform.mask(oldtablename)); + Fixes := TWideStringlist.Create; + while not Results.Eof do begin + notnull := ''; + if Results.Col('Null') = '' then + notnull := 'NOT NULL'; + default := ''; + if Results.Col('Default') <> '' then begin + default := 'DEFAULT '; + if Results.Col('Default') = 'CURRENT_TIMESTAMP' then + default := default + Results.Col('Default') + else + default := default + esc(Results.Col('Default')); + end; + + if (CheckBoxWithIndexes.Checked and (Results.Col('Extra') = 'auto_increment')) + or (Results.Col('Default') = 'CURRENT_TIMESTAMP') then begin + Fixes.Add('CHANGE '+Mainform.mask(Results.Col('Field'))+' '+ + Mainform.mask(Results.Col('Field'))+' '+ + Results.Col('Type')+' '+default+' '+notnull+' '+Results.Col('Extra')); + end; + + Results.Next; end; - - if (CheckBoxWithIndexes.Checked and (Results.Col('Extra') = 'auto_increment')) - or (Results.Col('Default') = 'CURRENT_TIMESTAMP') then begin - Fixes.Add('CHANGE '+Mainform.mask(Results.Col('Field'))+' '+ - Mainform.mask(Results.Col('Field'))+' '+ - Results.Col('Type')+' '+default+' '+notnull+' '+Results.Col('Extra')); + if Fixes.Count > 0 then begin + Mainform.Connection.Query('ALTER TABLE '+Mainform.mask(ComboSelectDatabase.Text) + '.'+Mainform.mask(editNewTablename.Text)+ ' '+ + ImplodeStr(', ', Fixes) + ); + end; + Results.Free; + FreeAndNil(Fixes); + Mainform.actRefresh.Execute; + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOk], 0); + ModalResult := mrNone; end; - - Results.Next; end; - if Fixes.Count > 0 then begin - Mainform.Connection.Query('ALTER TABLE '+Mainform.mask(ComboSelectDatabase.Text) + '.'+Mainform.mask(editNewTablename.Text)+ ' '+ - ImplodeStr(', ', Fixes) - ); - end; - Results.Free; - FreeAndNil(Fixes); - - Mainform.actRefresh.Execute; - close; - end; procedure TCopyTableForm.CheckListBoxFieldsClickCheck(Sender: TObject); diff --git a/source/editvar.pas b/source/editvar.pas index 327cd3fe..3002537c 100644 --- a/source/editvar.pas +++ b/source/editvar.pas @@ -72,8 +72,10 @@ begin try Mainform.Connection.Query(sql); except - ModalResult := mrNone; - Raise; + on E:Exception do begin + ModalResult := mrNone; + MessageDlg(E.Message, mtError, [mbOK], 0); + end; end; end; diff --git a/source/loaddata.pas b/source/loaddata.pas index 40aeebe6..e70749e5 100644 --- a/source/loaddata.pas +++ b/source/loaddata.pas @@ -290,8 +290,14 @@ begin // if col.Count < ColumnsCheckListBox.Items.Count then query := query + '(' + implodestr(',', col) + ')'; - Mainform.Connection.Query(query); - close; + try + Mainform.Connection.Query(query); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOk], 0); + ModalResult := mrNone; + end; + end; end; procedure Tloaddataform.btnOpenFileClick(Sender: TObject); diff --git a/source/main.pas b/source/main.pas index b19c54cc..5eef8257 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1009,15 +1009,20 @@ var begin flushwhat := UpperCase(TAction(Sender).Caption); delete(flushwhat, pos('&', flushwhat), 1); - Connection.Query('FLUSH ' + flushwhat); - if Sender = actFlushTableswithreadlock then begin - MessageDlg( - 'Tables have been flushed and read lock acquired.'#10 + - 'Perform backup or snapshot of table data files now.'#10 + - 'Press OK to unlock when done...', - mtInformation, [mbOk], 0 - ); - Connection.Query('UNLOCK TABLES'); + try + Connection.Query('FLUSH ' + flushwhat); + if Sender = actFlushTableswithreadlock then begin + MessageDlg( + 'Tables have been flushed and read lock acquired.'#10 + + 'Perform backup or snapshot of table data files now.'#10 + + 'Press OK to unlock when done...', + mtInformation, [mbOk], 0 + ); + Connection.Query('UNLOCK TABLES'); + end; + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOK], 0); end; end; @@ -2221,15 +2226,15 @@ begin lntDb: begin if MessageDlg('Drop Database "'+activeDB+'"?' + crlf + crlf + 'WARNING: You will lose all tables in database '+activeDB+'!', mtConfirmation, [mbok,mbcancel], 0) <> mrok then Abort; - Screen.Cursor := crHourglass; try Connection.Query('DROP DATABASE ' + mask(activeDB)); - finally DBtree.FocusedNode := DBtree.GetFirst; DBTree.Selected[DBtree.FocusedNode] := True; ClearDbTableList(activeDB); RefreshTree(False); - Screen.Cursor := crDefault; + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOK], 0); end; Exit; end; @@ -2266,14 +2271,18 @@ begin if MessageDlg(msg, mtConfirmation, [mbok,mbcancel], 0) <> mrok then Exit; - // Compose and run DROP [TABLE|VIEW|...] queries - DoDrop('TABLE', Tables, True); - DoDrop('VIEW', Views, True); - DoDrop('PROCEDURE', Procedures, False); - DoDrop('FUNCTION', Functions, False); - - // Refresh ListTables + dbtree so the dropped tables are gone: - actRefresh.Execute; + try + // Compose and run DROP [TABLE|VIEW|...] queries + DoDrop('TABLE', Tables, True); + DoDrop('VIEW', Views, True); + DoDrop('PROCEDURE', Procedures, False); + DoDrop('FUNCTION', Functions, False); + // Refresh ListTables + dbtree so the dropped tables are gone: + actRefresh.Execute; + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOK], 0); + end; end; @@ -2481,10 +2490,15 @@ begin else sql_pattern := 'TRUNCATE '; - for i:=0 to t.count-1 do - Connection.Query( sql_pattern + mask(t[i]) ); + try + for i:=0 to t.count-1 do + Connection.Query( sql_pattern + mask(t[i]) ); + actRefresh.Execute; + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOK], 0); + end; t.Free; - actRefresh.Execute; Screen.Cursor := crDefault; end; @@ -3902,13 +3916,17 @@ begin ProcessIDs := GetVTCaptions( ListProcesses, True ); if MessageDlg('Kill '+inttostr(ProcessIDs.count)+' Process(es)?', mtConfirmation, [mbok,mbcancel], 0) = mrok then begin - for i := 0 to ProcessIDs.Count - 1 do - begin - // Don't kill own process - if ProcessIDs[i] = IntToStr(Connection.ThreadId) then - LogSQL('Ignoring own process id '+ProcessIDs[i]+' when trying to kill it.') - else - Connection.Query('KILL '+ProcessIDs[i]); + try + for i:=0 to ProcessIDs.Count-1 do begin + // Don't kill own process + if ProcessIDs[i] = IntToStr(Connection.ThreadId) then + LogSQL('Ignoring own process id '+ProcessIDs[i]+' when trying to kill it.') + else + Connection.Query('KILL '+ProcessIDs[i]); + end; + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOK], 0); end; ListProcesses.Tag := VTREE_NOTLOADED; ListProcesses.Repaint; @@ -4354,10 +4372,8 @@ begin RefreshActiveDbTableList; DBTree.InvalidateChildren(FindDBNode(ActiveDatabase), True); except - On E : Exception do - begin - MessageDlg( E.Message, mtError, [mbOK], 0 ); - end; + on E:Exception do + MessageDlg(E.Message, mtError, [mbOK], 0); end; end; diff --git a/source/routine_editor.pas b/source/routine_editor.pas index 6f6201ce..203d3d36 100644 --- a/source/routine_editor.pas +++ b/source/routine_editor.pas @@ -439,46 +439,51 @@ begin // There is no way to ALTER parameters or the name of it. // Create a temp routine, check for syntax errors, then drop the old routine and create it. // See also: http://dev.mysql.com/doc/refman/5.0/en/alter-procedure.html - if FAlterRoutineName <> '' then begin - // Create temp name - i := 0; - allRoutineNames := Mainform.Connection.GetCol('SELECT ROUTINE_NAME FROM '+Mainform.mask(DBNAME_INFORMATION_SCHEMA)+'.'+Mainform.mask('ROUTINES')+ - ' WHERE ROUTINE_SCHEMA = '+esc(Mainform.ActiveDatabase)+ - ' AND ROUTINE_TYPE = '+esc(ProcOrFunc) - ); - TargetExists := ((editName.Text <> FAlterRoutineName) or (ProcOrFunc <> FAlterRoutineType)) and - (allRoutineNames.IndexOf(editName.Text) > -1); - if TargetExists then begin - if MessageDlg('Routine "'+editName.Text+'" already exists. Overwrite it?', - mtConfirmation, [mbOk, mbCancel], 0) = mrCancel then begin - Exit; + try + if FAlterRoutineName <> '' then begin + // Create temp name + i := 0; + allRoutineNames := Mainform.Connection.GetCol('SELECT ROUTINE_NAME FROM '+Mainform.mask(DBNAME_INFORMATION_SCHEMA)+'.'+Mainform.mask('ROUTINES')+ + ' WHERE ROUTINE_SCHEMA = '+esc(Mainform.ActiveDatabase)+ + ' AND ROUTINE_TYPE = '+esc(ProcOrFunc) + ); + TargetExists := ((editName.Text <> FAlterRoutineName) or (ProcOrFunc <> FAlterRoutineType)) and + (allRoutineNames.IndexOf(editName.Text) > -1); + if TargetExists then begin + if MessageDlg('Routine "'+editName.Text+'" already exists. Overwrite it?', + mtConfirmation, [mbOk, mbCancel], 0) = mrCancel then begin + Exit; + end; + end; + while True do begin + inc(i); + TempName := APPNAME + '_temproutine_' + IntToStr(i); + if allRoutineNames.IndexOf(TempName) = -1 then + break; + end; + TempSQL := 'CREATE '+ProcOrFunc+' '+Mainform.mask(tempName)+'(' + BaseSQL; + Mainform.Connection.Query(TempSQL); + // Drop temporary routine, used for syntax checking + Mainform.Connection.Query('DROP '+ProcOrFunc+' IF EXISTS '+Mainform.mask(TempName)); + // Drop edited routine + Mainform.Connection.Query('DROP '+FAlterRoutineType+' IF EXISTS '+Mainform.mask(FAlterRoutineName)); + if TargetExists then begin + // Drop target routine - overwriting has been confirmed, see above + Mainform.Connection.Query('DROP '+ProcOrFunc+' IF EXISTS '+Mainform.mask(editName.Text)); end; end; - while True do begin - inc(i); - TempName := APPNAME + '_temproutine_' + IntToStr(i); - if allRoutineNames.IndexOf(TempName) = -1 then - break; - end; - TempSQL := 'CREATE '+ProcOrFunc+' '+Mainform.mask(tempName)+'(' + BaseSQL; - Mainform.Connection.Query(TempSQL); - // Drop temporary routine, used for syntax checking - Mainform.Connection.Query('DROP '+ProcOrFunc+' IF EXISTS '+Mainform.mask(TempName)); - // Drop edited routine - Mainform.Connection.Query('DROP '+FAlterRoutineType+' IF EXISTS '+Mainform.mask(FAlterRoutineName)); - if TargetExists then begin - // Drop target routine - overwriting has been confirmed, see above - Mainform.Connection.Query('DROP '+ProcOrFunc+' IF EXISTS '+Mainform.mask(editName.Text)); - end; + FinalSQL := 'CREATE '+ProcOrFunc+' '+Mainform.mask(editName.Text)+'(' + BaseSQL; + Mainform.Connection.Query(FinalSQL); + // Set editing name if create/alter query was successful + FAlterRoutineName := editName.Text; + FAlterRoutineType := ProcOrFunc; + Mainform.SetEditorTabCaption(Self, FAlterRoutineName); + Mainform.actRefresh.Execute; + Modified := False; + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOk], 0); end; - FinalSQL := 'CREATE '+ProcOrFunc+' '+Mainform.mask(editName.Text)+'(' + BaseSQL; - Mainform.Connection.Query(FinalSQL); - // Set editing name if create/alter query was successful - FAlterRoutineName := editName.Text; - FAlterRoutineType := ProcOrFunc; - Mainform.SetEditorTabCaption(Self, FAlterRoutineName); - Mainform.actRefresh.Execute; - Modified := False; end; diff --git a/source/table_editor.pas b/source/table_editor.pas index 69d2dcd2..33e5dfc8 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -560,46 +560,51 @@ var FocusChangeEvent: procedure(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex) of object; begin // Create or alter table - if FAlterTableName = '' then - sql := ComposeCreateStatement - else begin - sql := ComposeAlterStatement; - // Special case for altered foreign keys: These have to be dropped in a seperate query - // otherwise the server would return error 121 "Duplicate key on write or update" - // See also http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html : - // "You cannot add a foreign key and drop a foreign key in separate clauses of a single - // ALTER TABLE statement. Separate statements are required." - Specs := TWideStringList.Create; - for i:=0 to ForeignKeys.Count-1 do begin - Key := ForeignKeys[i] as TForeignKey; - if Key.Modified and (not Key.Added) then - Specs.Add('DROP FOREIGN KEY '+Mainform.mask(Key.KeyName)); + try + if FAlterTableName = '' then + sql := ComposeCreateStatement + else begin + sql := ComposeAlterStatement; + // Special case for altered foreign keys: These have to be dropped in a seperate query + // otherwise the server would return error 121 "Duplicate key on write or update" + // See also http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html : + // "You cannot add a foreign key and drop a foreign key in separate clauses of a single + // ALTER TABLE statement. Separate statements are required." + Specs := TWideStringList.Create; + for i:=0 to ForeignKeys.Count-1 do begin + Key := ForeignKeys[i] as TForeignKey; + if Key.Modified and (not Key.Added) then + Specs.Add('DROP FOREIGN KEY '+Mainform.mask(Key.KeyName)); + end; + if Specs.Count > 0 then + Mainform.Connection.Query('ALTER TABLE '+Mainform.mask(FAlterTableName)+' '+ImplodeStr(', ', Specs)); end; - if Specs.Count > 0 then - Mainform.Connection.Query('ALTER TABLE '+Mainform.mask(FAlterTableName)+' '+ImplodeStr(', ', Specs)); - end; - Mainform.Connection.Query(sql); - // Set table name for altering if Apply was clicked - FAlterTableName := editName.Text; - tabALTERcode.TabVisible := FAlterTableName <> ''; - if chkCharsetConvert.Checked then begin - // Autoadjust column collations - for i:=0 to FColumns.Count-1 do begin - Col := FColumns[i] as TColumn; - if Col.Collation <> '' then - Col.Collation := comboCollation.Text; + Mainform.Connection.Query(sql); + // Set table name for altering if Apply was clicked + FAlterTableName := editName.Text; + tabALTERcode.TabVisible := FAlterTableName <> ''; + if chkCharsetConvert.Checked then begin + // Autoadjust column collations + for i:=0 to FColumns.Count-1 do begin + Col := FColumns[i] as TColumn; + if Col.Collation <> '' then + Col.Collation := comboCollation.Text; + end; end; - end; - ResetModificationFlags; + ResetModificationFlags; - // Refresh db tree and reselect edited table node. - // Supress tab jumping, implicitely invoked by RefreshTreeDB. - FocusChangeEvent := Mainform.DBtree.OnFocusChanged; - Mainform.DBtree.OnFocusChanged := nil; - Mainform.RefreshTreeDB(Mainform.ActiveDatabase); - Mainform.DBtree.OnFocusChanged := FocusChangeEvent; - Mainform.ResetSelectedTableStuff; - Mainform.SelectDBObject(FAlterTableName, lntTable); + // Refresh db tree and reselect edited table node. + // Supress tab jumping, implicitely invoked by RefreshTreeDB. + FocusChangeEvent := Mainform.DBtree.OnFocusChanged; + Mainform.DBtree.OnFocusChanged := nil; + Mainform.RefreshTreeDB(Mainform.ActiveDatabase); + Mainform.DBtree.OnFocusChanged := FocusChangeEvent; + Mainform.ResetSelectedTableStuff; + Mainform.SelectDBObject(FAlterTableName, lntTable); + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOk], 0); + end; end; diff --git a/source/usermanager.dfm b/source/usermanager.dfm index cd3e1ad0..26eb8068 100644 --- a/source/usermanager.dfm +++ b/source/usermanager.dfm @@ -71,7 +71,6 @@ object UserManagerForm: TUserManagerForm Anchors = [akRight, akBottom] Caption = 'OK' Default = True - ModalResult = 1 TabOrder = 2 OnClick = btnOKClick end diff --git a/source/usermanager.pas b/source/usermanager.pas index a0f3d8e3..fbdec55c 100644 --- a/source/usermanager.pas +++ b/source/usermanager.pas @@ -296,7 +296,17 @@ begin lblHostHints.Caption := StringReplace(lblHostHints.Caption, '$SNR', snr, []); // Load users into memory - Users := TUsers.Create; + try + Users := TUsers.Create; + except + // At least one priv table is missing or non-accessible when we get an exception. + // Proceeding would result in follow up errors, so cancel the whole dialog in that case. + on E:Exception do begin + MessageDlg(E.Message+CRLF+CRLF+'The user manager cannot proceed with this error.', mtError, [mbOK], 0); + PostMessage(Handle, WM_CLOSE, 0, 0); + Exit; + end; + end; // Enable limitations editors only if relevant columns exist lblMaxQuestions.Enabled := dsUser.ColExists('max_questions'); editMaxQuestions.Enabled := lblMaxQuestions.Enabled; @@ -885,11 +895,6 @@ var begin Mainform.LogSQL(sql); end; - procedure Exec(sql: String); - begin - //LogSQL(sql); Exit; - Mainform.Connection.Query(sql); - end; function Mask(sql: String): String; begin Result := Mainform.Mask(sql); @@ -929,10 +934,17 @@ begin LogSQL('Deleting account ' + u.FOldName + '@' + u.FOldHost + '.'); AcctWhere := AccountSqlClause(u.FOldName, u.FOldHost, True); sql := 'DELETE FROM ' + db + '.'; - Exec(sql + mask(PRIVTABLE_COLUMNS) + AcctWhere); - Exec(sql + mask(PRIVTABLE_TABLES) + AcctWhere); - Exec(sql + mask(PRIVTABLE_DB) + AcctWhere); - Exec(sql + mask(PRIVTABLE_USERS) + AcctWhere); + try + Mainform.Connection.Query(sql + mask(PRIVTABLE_COLUMNS) + AcctWhere); + Mainform.Connection.Query(sql + mask(PRIVTABLE_TABLES) + AcctWhere); + Mainform.Connection.Query(sql + mask(PRIVTABLE_DB) + AcctWhere); + Mainform.Connection.Query(sql + mask(PRIVTABLE_USERS) + AcctWhere); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; AcctUpdates := TWideStringList.Create; @@ -958,11 +970,18 @@ begin AcctWhere := AccountSqlClause(u.FOldName, u.FOldHost); AcctValues := ' SET ' + Delim(AcctUpdates); sql := 'UPDATE ' + db + '.'; - // Todo: Allow concurrency by skipping this account and removing from Users array if changing key in mysql.user fails. - Exec(sql + mask(PRIVTABLE_USERS) + AcctValues + AcctWhere); - Exec(sql + mask(PRIVTABLE_DB) + AcctValues + AcctWhere); - Exec(sql + mask(PRIVTABLE_TABLES) + AcctValues + AcctWhere); - Exec(sql + mask(PRIVTABLE_COLUMNS) + AcctValues + AcctWhere); + try + // Todo: Allow concurrency by skipping this account and removing from Users array if changing key in mysql.user fails. + Mainform.Connection.Query(sql + mask(PRIVTABLE_USERS) + AcctValues + AcctWhere); + Mainform.Connection.Query(sql + mask(PRIVTABLE_DB) + AcctValues + AcctWhere); + Mainform.Connection.Query(sql + mask(PRIVTABLE_TABLES) + AcctValues + AcctWhere); + Mainform.Connection.Query(sql + mask(PRIVTABLE_COLUMNS) + AcctValues + AcctWhere); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; LogSQL('Applying changes to authentication details and limitations...'); @@ -1000,7 +1019,14 @@ begin AcctWhere := AccountSqlClause(u.Name, u.Host); AcctValues := ' SET ' + Delim(AcctUpdates); sql := 'UPDATE ' + db + '.'; - Exec(sql + mask(PRIVTABLE_USERS) + AcctValues + AcctWhere); + try + Mainform.Connection.Query(sql + mask(PRIVTABLE_USERS) + AcctValues + AcctWhere); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; LogSQL('Creating new accounts...'); @@ -1037,8 +1063,15 @@ begin AcctUpdates.Add(mask('x509_subject') + '=' + esc('')); sql := 'INSERT INTO ' + db + '.' + mask(PRIVTABLE_USERS); sql := sql + ' SET ' + Delim(AcctUpdates); - // Todo: Allow concurrency by skipping this account and removing from Users array if inserting key in mysql.user fails. - Exec(sql); + try + // Todo: Allow concurrency by skipping this account and removing from Users array if inserting key in mysql.user fails. + Mainform.Connection.Query(sql); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; LogSQL('Applying privilege changes...'); @@ -1100,12 +1133,26 @@ begin end; sql := 'UPDATE ' + db + '.' + mask(PRIVTABLE_USERS); sql := sql + ' SET ' + Delim(PrivUpdates); - Exec(sql + AcctWhere); + try + Mainform.Connection.Query(sql + AcctWhere); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; // Remove old privilege definition. if (p.DBOType <> lntNone) then begin sql := 'DELETE FROM ' + db + '.' + TableName; - Exec(sql + AcctWhere + PrivWhere); + try + Mainform.Connection.Query(sql + AcctWhere + PrivWhere); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end else begin // Special case: avoid removing old definition when dealing with // server-level privileges, since they're entangled with @@ -1164,7 +1211,14 @@ begin sql := sql + ' ON DUPLICATE KEY UPDATE'; sql := sql + ' ' + Delim(PrivUpdates); end; - Exec(sql); + try + Mainform.Connection.Query(sql); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; // Special case: update redundant column privileges in mysql.tables_priv. if (p.DBOType = lntColumn) and dsTables.ColExists('column_priv') then begin // We need to deduce a completely new key because column_priv in mysql.tables_priv does not have a column field next to it, sigh. @@ -1184,11 +1238,26 @@ begin sql := sql + ', ' + mask('column_priv') + '=' + esc(Delim(PrivValues, False)); sql := sql + ' ON DUPLICATE KEY UPDATE'; sql := sql + ' ' + mask('column_priv') + '=' + esc(Delim(PrivValues, False)); - Exec(sql); + try + Mainform.Connection.Query(sql); + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; end; end; - Exec('FLUSH PRIVILEGES'); + try + Mainform.Connection.Query('FLUSH PRIVILEGES'); + ModalResult := mrOK; + except + on E:Exception do begin + MessageDlg(E.Message, mtError, [mbOK], 0); + Exit; + end; + end; end; diff --git a/source/view.pas b/source/view.pas index 7cddbe72..d7f884b5 100644 --- a/source/view.pas +++ b/source/view.pas @@ -159,14 +159,18 @@ begin if rgCheck.Enabled and (rgCheck.ItemIndex > 0) then sql := sql + 'WITH '+Uppercase(rgCheck.Items[rgCheck.ItemIndex])+' CHECK OPTION'; - // Execute query and keep form open in any error case - Mainform.Connection.Query(sql); - // Probably rename view - if (FEditViewName <> '') and (FEditViewName <> editName.Text) then begin - renamed := Mainform.mask(editName.Text); - Mainform.Connection.Query('RENAME TABLE '+viewname + ' TO '+renamed); + try + Mainform.Connection.Query(sql); + // Probably rename view + if (FEditViewName <> '') and (FEditViewName <> editName.Text) then begin + renamed := Mainform.mask(editName.Text); + Mainform.Connection.Query('RENAME TABLE '+viewname + ' TO '+renamed); + end; + Mainform.RefreshTreeDB(Mainform.ActiveDatabase); + except + on E:Exception do + MessageDlg(E.Message, mtError, [mbOk], 0); end; - Mainform.RefreshTreeDB(Mainform.ActiveDatabase); end;