MariaDB / mariadb_kernel

A MariaDB Jupyter kernel
BSD 3-Clause "New" or "Revised" License
30 stars 21 forks source link

Display a confirmation message for successful empty-result queries #21

Closed a97410985 closed 3 years ago

a97410985 commented 3 years ago

related to https://github.com/MariaDB/mariadb_kernel/issues/15

my ideas :

mariadb_kernel/kernel.py is reponsible for execute the code when frontend run a cell, and the function handle this is do_execute(...),which would parse sql and magic command and execute it. The following code for execute sql statements.

 # part of mariadb\_kernel/kernel.py
 statements = parser.get_sql()
 for s in statements:
     result = self.mariadb_client.run_statement(s)
     if self.mariadb_client.iserror():
        self._send_message("stderr", self.mariadb\_client.error\_message())
        continue
    self._update_data(result)
    display_content = {"data": {"text/html": str(result)}, "metadata": {}}
    if not silent:
        self.send_response(self.iopub_socket, "display_data", display_content)

when error occur, if self.mariadb_client.iserror(): will handle this. After that, if the result is empty we should display a pure text, show ''Query OK", make the user assure execution success

demonstration(video)

https://www.youtube.com/watch?v=-3GKlLQjwGA&ab_channel=%E6%B1%9F%E6%96%B0%E7%9F%A5

a97410985 commented 3 years ago

sorry for not code formatting my code, I rebase and force push to my PR. Seems fine.

robertbindar commented 3 years ago

Hey @a97410985! No worries, we're lucky we can format so easy using this tool. Please update the PR again, sorry for this, when you rebased, you missed the self._styled_result(result) call I introduced before your commit.

robertbindar commented 3 years ago

Thanks a lot for the contribution @a97410985! Awesome work :-)