KateSQL, a new plugin for Kate

Hello,

today i will show you a new plugin for Kate, called KateSQL.
As you may have guessed, it brings to Kate the basic features of an SQL client, allowing you to open connections, execute queries, and display result data from SELECT statements or stored procedures.
Since this plugin makes an extreme use of the Qt Sql module, most of database drivers are supported..

Said this, let me explain how it works..

Kate MainWindow with KateSQL widgets

First of all, you have to create a new db connection through a simple wizard, specifying driver, connection parameters (hostname, username, password, etc…), and a descriptive name, that KateSQL will use as identifier.
Done this, what you need to do is just select the query text in the editor and press F5 (or your preferred shortcut). The whole text will be executed through the selected connection.

For SQL output, two toolbox are disposed in the bottom area:

  • The first will show messages returned from the server (errors in red, others in green, like number of affected rows).
  • The second contains a table view with a custom model associated, to show resultsets of a query. This custom model does nothing more than a QSqlQueryModel, only provides colors and formatting for each cell..

Ah, about this, my last commit implements a configuration widget that let you choose colors and font styles for text fields, numbers, blobs, nulls, booleans and dates… cool, yeah? :)

KateSQL Configuration Dialog

Last but not least, on the left panel you can find a basic and useful schema browser, that show the tree schema of the database connection currently selected. With this tree widget you can browse through tables, system tables and views, up to individual fields. obviously, primary key fields are distinguished by the classic yellow key icon.

Currently, there are few problems with multiple query handling.. Some engines doesn’t supports it natively, others can receive queries separated by a semicolon, but the QSqlQueryModel can handle only one resultset at time.. probably the best solution is to parse the text, split queries, and execute them separately.. Surely, this feature will be implemented soon.
Stay tuned!

Of course, if you want to help us with development, you are welcome!

GSoC – View differences for Kate’s swap files

Hello,

As I stated in a previous post, the swap file feature for Kate is almost done. Back then, the view differences feature wasn’t ready, but now we have a basic implementation of it.
So now, by pressing the “View changes” button, a new KProcess is created, which receives as command line arguments the ‘diff’ program and the two files to be compared. One file is the original file on the disk, and the other one is represented by the recovered data read from the standard input. Then, Kompare launches, and there you can see the differences.
But sadly, at the moment you can’t merge the changes or some of them through Kompare, but I’m working on it. All you can do is see the differences and decide whether you want to recover the lost data or not. Close Kompare, and then press the “Recover” button or the “Discard” one, depending on what you want to do.

Spotlight: Kate Scripting

Hey ho everyone.

Dominik asked me to blog about a feature in Kate that is still (sadly!) pretty unknown and seldom used: Kate Scripting. As you should know you can script KatePart completely via JavaScript. As those articles explain, it’s rather simple to write functions and put them into a file to have them reusable. But what for those write-use-throwaway kind of cases, where you simply need to get a job done quickly and don’t want to go through the overhead of writing some full fledged, documented, action-binded, localized script?

Utility Functions and why JavaScript rocks

Note: Neither map nor filter will be shipped with 4.5 to my knowledge, sorry about that. But you can still use the each helper (see below) to achieve the same with a bit more typing…

Take a look at utils.js on current git master: http://gitorious.org/kate/kate/blobs/master/part/script/data/utils.js

Put a special note on the helper functions map, filter and each and how they are used to implement e.g. rmblank, [rl]trim and the other functions. Cool eh? And the best part, you can reuse them directly from inside KatePart to get a job done:

mail-style quoting

Lets assume you write an email or use something like Markdown or Textile and want to quote. You’ll have to prepend a few lines with the two chars ‘> ‘. Instead of copy’n’pasting like a maniac do this instead and save yourself some breath:

  1. press F7 to open the Kate command line
  2. write e.g. map "function(l) { return '> ' + l; }"
  3. execute

Note: When you don’t have anything selected, the whole document will get “quoted”.

remove lines that match a pattern

This is something everyone needs to do sooner or later, happened quite a few times to me already. I bet vim has some esoteric command I cannot remember and emacs has something like C-x M-c M-butterfly. But with Kate most users only see search & replace and forfeit to the command line. Well, now it’s again a good time to use the command line:

  1. press F7 again
  2. write e.g. filter "function(l) { return l.indexOf('myNeedle') == -1; }"
  3. execute

Now all lines that contain ‘myNeedle’ will get removed. Sure, this is “verbose” but assuming you know JavaScript it’s actually quite easy, expendable and - best of all - good to remember. At least for me, YMMV.

shortcuts

For simple cases I’ve now introduced a shortcut way of doing the above, that saves you even more typing, but is limited to simple evaluations like the ones above. If you need something fancy, you’ll have to stick to the type-intensive way. Aynhow, here’s the shortcut version of the two scripts:

  1. map "'> ' + line"
  2. filter "line.indexOf('myNeedle') == -1"
the guts: each (interesting for users of KDE 4.x, x < 6)

Both of the above are implemented using the each helper I introduced even before KDE 4.4 afair. If you are using KDE 4.5 and want to do one of the above, a bit more typing is required:

  1. for map, you write something like this:
    each "function(lines) { return lines.map(function(l){ /** actual map code **/ }); }"
  2. for filter you do the same but replace map with filter:
    each "function(lines) { return lines.filter(function(l){ /** actual filter code **/ }); }"
Conclusion

You see, it’s quite simple and powerful. I really love map-reduce and how easy it is to use with JavaScript. Hope you like it as well.

PS: I actually think about making it yet even easier, by allowing some syntax like this: map '> ' + line or filter line.indexOf('myNeedle') == -1, must take a look on how hard it would be (beside the need for extensive documentation, but hey we have the help command in the Kate CLI, who can complain now? :) Implemented

Bye

Spotlight: Kate Scripting

Hey ho everyone.

Dominik asked me to blog about a feature in Kate that is still (sadly!) pretty unknown and seldom used: Kate Scripting. As you should know you can script KatePart completely via JavaScript. As those articles explain, it’s rather simple to write functions and put them into a file to have them reusable. But what for those write-use-throwaway kind of cases, where you simply need to get a job done quickly and don’t want to go through the overhead of writing some full fledged, documented, action-binded, localized script?

Utility Functions and why JavaScript rocks

Note: Neither map nor filter will be shipped with 4.5 to my knowledge, sorry about that. But you can still use the each helper (see below) to achieve the same with a bit more typing…

Take a look at utils.js on current git master: http://gitorious.org/kate/kate/blobs/master/part/script/data/utils.js

Put a special note on the helper functions map, filter and each and how they are used to implement e.g. rmblank, [rl]trim and the other functions. Cool eh? And the best part, you can reuse them directly from inside KatePart to get a job done:

mail-style quoting

Lets assume you write an email or use something like Markdown or Textile and want to quote. You’ll have to prepend a few lines with the two chars ‘> ‘. Instead of copy’n’pasting like a maniac do this instead and save yourself some breath:

  1. press F7 to open the Kate command line
  2. write e.g. map "function(l) { return '> ' + l; }"
  3. execute

Note: When you don’t have anything selected, the whole document will get “quoted”.

remove lines that match a pattern

This is something everyone needs to do sooner or later, happened quite a few times to me already. I bet vim has some esoteric command I cannot remember and emacs has something like C-x M-c M-butterfly. But with Kate most users only see search & replace and forfeit to the command line. Well, now it’s again a good time to use the command line:

  1. press F7 again
  2. write e.g. filter "function(l) { return l.indexOf('myNeedle') == -1; }"
  3. execute

Now all lines that contain ‘myNeedle’ will get removed. Sure, this is “verbose” but assuming you know JavaScript it’s actually quite easy, expendable and - best of all - good to remember. At least for me, YMMV.

shortcuts

For simple cases I’ve now introduced a shortcut way of doing the above, that saves you even more typing, but is limited to simple evaluations like the ones above. If you need something fancy, you’ll have to stick to the type-intensive way. Aynhow, here’s the shortcut version of the two scripts:

  1. map "'> ' + line"
  2. filter "line.indexOf('myNeedle') == -1"
the guts: each (interesting for users of KDE 4.x, x < 6)

Both of the above are implemented using the each helper I introduced even before KDE 4.4 afair. If you are using KDE 4.5 and want to do one of the above, a bit more typing is required:

  1. for map, you write something like this:
    each "function(lines) { return lines.map(function(l){ /** actual map code **/ }); }"
  2. for filter you do the same but replace map with filter:
    each "function(lines) { return lines.filter(function(l){ /** actual filter code **/ }); }"
Conclusion

You see, it’s quite simple and powerful. I really love map-reduce and how easy it is to use with JavaScript. Hope you like it as well.

PS: I actually think about making it yet even easier, by allowing some syntax like this: map '> ' + line or filter line.indexOf('myNeedle') == -1, must take a look on how hard it would be (beside the need for extensive documentation, but hey we have the help command in the Kate CLI, who can complain now? :) Implemented

Bye