gSqlClient plugin for Gedit
gSqlClient is a Python plugin for Gedit that turns it into a lightweight SQL client, currently it supports MySQL, PostgreSQL, SQLite and SQLServer databases. You can examine queries resultsets on a grid, run any SQL file as a script or export resultsets as SQL, XML or CSV, taking advantage of Gedit as SQL editor.
I wrote this plugin because I missed some features of the great Oracle client Toad when working with MySQL databases, mainly the flexibility of a powerful SQL text editor where you can edit many queries on the same file and execute them separately one at a time or run the entire file as a script. With gSqlClient I can take advantage of Gedit as a powerful SQL query editor, which is an improvement over the MySQL console client (Don't you think?), and examine the results on a more comfortable grid.
I know there are many MySQL clients out there (I always recommend MySQL Query Browser) and they are great so, why do I need one more client?. Well, when I come interested in Python language this was the first thing I thought for learning the language, something easy, something useful, what else?
The project is licensed under the terms of the GNU General Public License version 3. Until 2011-08-22 it was hosted on GoogleCode, and since then, the development of the 1.0 branches are hosted in GitHub. You can browse the sources and download the last version from https://github.com/ahdiaz/gSqlClient or http://code.google.com/p/gsqlclient
And give some feedback please, report bugs or simply let me know what do you think about gSqlClient, enjoy!.
- Important, install the database driver you want to connect to.
- Download the last version of gSqlClient.
- Extract the content of the tarball under $HOME/.gnome2/gedit/plugins/ directory.
- (Re)start Gedit.
- Go to Edit->Preferences->Plugins and check the box for gSqlClient.
You will need to install only the drivers you want to use. It's possible that your Linux distribution has precompiled packages available.
|MySQL (MySQLdb)||0.1||http://mysql-python.sourceforge.net/MySQLdb.html||Linux / MySQL 5|
|SQLite (Pysqlite)||0.4||http://code.google.com/p/pysqlite/||Linux / SQLite 3|
|PostgreSQL (Psycopg)||0.5||http://www.initd.org/psycopg/||Linux / PostgreSQL 8.4|
Usage and features
Open Gedit, create a new document, and follow the next instructions:
Connect/disconnect Gedit to a server
Access to that operations by pressing Ctrl+Shift+C, a dialog appears where you have to fill the form with your specific server information. The server host can be written as HOST_NAME[:PORT] or as a path to a socket file. The schema field is optional.
When you want to disconnect from the server press Ctrl+Shift+C again, if the connection was successfully a new button, Disconnect, will be available.
Remember that you can have one diferent open connection on each Gedit tab so you can query diferent databases from the same instance of Gedit.
When you close Gedit, the plugin will attempt to disconnect all the opened connections for you.
Write some queries and be sure to separate them by empty lines, put the cursor over one of the queries and press Ctrl+Return, you should see a panel with the resultset (Or maybe with a SQL error...). The query separator is an empty line so you don't need a semicolon after the query, this way allows you to have many queries on the same document and execute them separately.
If you want to execute only part of a query you can select the part you are interested on and press Ctrl+Return, the plugin will only execute the selection.
For example, you are going to run this query: SELECT * FROM Table1 WHERE field_id IN (SELECT field_id FROM Table2) but first you want to examine the returned data from the subquery, ok, don't write the subquery again, only select it and press Ctrl+Return, easy?.
Not only can execute DML and DDL queries, you can run anything you run habitually from the console client, server administration, user administration or whatever.
Running files as scripts
This is interesting when you need to run many queries. By pressing Ctrl+Shift+R gSqlClient will execute all the queries on the document one after one (remember to separate them by empty lines) and show the results of each one in the bottom panel.
Before the execution, a dialog appears where you can choose three diferent options for the error control:
- Ask to the user what to do if some query throws an error.
- Stop the script execution if some query throws an error.
- Ignore all errors and run the script to the end (Beware, this option could be very harmful for your database).
Copying and exporting resultset data (since version 0.2)
There is a contextual menu with options for copy grid values and export resultsets as SQL, XML or CSV formats, simply right click on the resultset grid and select the option you want.
I don't have in mind to add much more features, but I have two things pending:
Improvements on the way the database connections are handled, create a connection pool and reuse them.
- Maybe an UI tool for handle those connection, that would be nice.
- Support for PostgreSQL and SQLServer.
- Refactorization of database connectors.
- Conditional import of database drivers.
- Added an option for export data as SQL sentences.
- Fixed a bug getting the query when it is at the beginning of the document.
- Change the keyboard shortcuts, avoid possible collisions with system shortcuts.
- SQLite support.
- Refactorization of the ConnectionDialog class.
- Pool of connections.
- Fixed some minor bugs.
- The host field is parsed correctly and now can connect using host:port or a socket file.
- Added a contextual menu with options for copy grid values and export resultsets.
- Added a dialog with error control options for "Run as script" mode.
- Improvements parsing the queries.
- Show MySQL errors in the bottom panel.
- Show resultset information below the grid.
- Added feature "Run as script".
- Improves the TextBuffer parsing for searching queries.
- Initial import of the beta version (Database connections and query executions).