Dear Research Colleagues,
I hope this message finds you well. I am reaching out to request your assistance with a technical challenge I am facing in a project using Harbour/MiniGUI integrated with a MySQL database.
Issue Description:
When editing a record directly in the grid interface and saving changes to MySQL, the grid freezes after the update. This prevents other records from being selected or edited, requiring an application restart to restore functionality.
Technical Details:
Environment: Windows 11 | Harbour 3.6.0 | MiniGUI Extended Edition | MySQL 8.0
Current Workflow:
Edit a field in the grid (e.g., "Name").
Click "Save" (executes an UPDATE in MySQL).
The application updates the database record, but the grid freezes and does not reflect changes until restarted.
Troubleshooting Attempts:
Refreshing the grid with RefreshGrid() after the UPDATE.
Using COMMIT and ROLLBACK to ensure proper transaction handling.
Checking persistent connections and MySQL timeouts.
Testing SELECT queries post-update to reload data.
Questions for the Group:
Has anyone encountered grid freezes in Harbour-MySQL integrations?
Is there an efficient way to reload grids after MySQL operations without freezing the interface?
Would you recommend using TMySQLQuery or specific components for real-time updates?
Code Snippet (Harbour/MiniGUI):
// Construção do Grid
@ 75,01 GRID grid_clientes ;
WIDTH GetProperty('frmPrincipal','width') - 230 ;
HEIGHT 550 ;
HEADERS {'Código','Razão Social','Nome Fantasia','CPF','Celular','Entrevistador'} ;
WIDTHS {080,375,280,135,140,130} ;
FONT "Microsoft YaHei" SIZE 12 ;
BACKCOLOR {242,245,204} ;
ON DBLCLICK dados(2) ;
ON CHANGE AtualizaGrid() // Nova função para atualização
// Função para carregar/recarregar dados do MySQL
FUNCTION CarregaGrid()
LOCAL cSQL := "SELECT id, razao, fantasia, cpf, celular, entrevistador FROM clientes"
LOCAL aDados := {}
IF ConectaMySQL()
oQuery := oServer:Query(cSQL)
IF !oQuery:NetErr()
DO WHILE !oQuery:Eof()
AADD(aDados, {;
oQuery:FieldGet(1),;
oQuery:FieldGet(2),;
oQuery:FieldGet(3),;
oQuery:FieldGet(4),;
oQuery:FieldGet(5),;
oQuery:FieldGet(6);
})
oQuery:Skip()
ENDDO
grid_clientes.DeleteAllItems()
grid_clientes.AddItems(aDados)
ENDIF
DesconectaMySQL()
ENDIF
RETURN NIL
// Função de atualização otimizada
FUNCTION AtualizaGrid()
grid_clientes.DisableUpdate()
CarregaGrid()
grid_clientes.EnableUpdate()
grid_clientes.Refresh()
RETURN NIL
// Modificação no método de salvamento
METHOD Btn_Save() CLASS MinhaJanela
LOCAL cSQL := "UPDATE clientes SET " + ;
"razao = '" + mysql_escape(ThisForm.txtRazao.Value) + "', " + ;
"fantasia = '" + mysql_escape(ThisForm.txtFantasia.Value) + "' " + ;
"WHERE id = " + AllTrim(Str(ThisForm.grid_clientes.Value))
IF ConectaMySQL()
TRY
oServer:Query("START TRANSACTION")
oServer:Query(cSQL)
oServer:Query("COMMIT")
// Atualização segura do grid
AtualizaGrid()
CATCH
oServer:Query("ROLLBACK")
MsgStop("Erro na atualização: " + ErrorMessage())
FINALLY
DesconectaMySQL()
END
ENDIF
RETURN NIL
Additional Notes:
The grid is populated via an initial SELECT query but does not reflect changes after UPDATE, even with Refresh().
I suspect the issue lies in reloading grid data after MySQL operations.
Your insights would be invaluable! If needed, I can share the full project or additional code snippets for further analysis.
Best regards,
Mr. Grigory