WinSQL

From TheBeard Science Project Wiki
Revision as of 13:32, 13 March 2020 by Beard (talk | contribs) (Better Comment Parsing)

Jump to: navigation, search

Easier Query Termination

I used to use a program called SqlDbx, which is free but it's only 32-bit unless you pay $300 for the paid version. When my workplace moved to Windows 10, I could no longer install the 32-bit Informix ODBC drivers, and so I could no longer use SqlDbx with Informix.

Moving over to WinSQL, I discovered a difference that annoyed me. In SqlDbx, I would write a sequence of queries that create temp tables, like this simplified example:

select id,
       name,
       sex
  from employees
 where sex = "F"
  into temp employees_female with no log;

select id,
       name,
       sex
  from employees_female
 where name[0] = "A";

In SqlDbx, I could just run this whole thing exactly as I've written it. It runs the first query and creates the temp table, then the second query could select from the temp table. In WinSQL, it says the table "employees_female" is not in the database. It wasn't treating these as separate queries.

I discovered a simple solution:

  1. Go to the Edit menu and click Options.
  2. Under the General tab, there is a text field in the right pane called "Query terminator string". By default it is set to "go". Change it to ";" (semicolon).
  3. Uncheck the checkbox right underneath that which says "Terminators must be on a new line". Now click Ok.

So the default query terminator is "go," which makes sense I guess because that's common syntax in SQL Server, but I'm used to something more streamlined, and even our vendor's software uses queries terminated in the way I've written above, so this configuration change just makes it so much easier to work with thos queries, and it more streamlined.

Clear Recent Files List

In WinSQL go to File > "Open Data Folder..."

This opens C:\Users\username\AppData\Roaming\WinSQL in Explorer.

Delete the file RecentFiles.dat.

Now close and re-open WinSQL.

Better Comment Parsing

The default way WinSQL handles comments is to pass them to the server, which is unnecessary. Anyone using T-SQL or MySQL might not experience issues, but Informix is the oddball that uses curly braces for multi-line comments, like { This is a comment. }

If you try to use the C-style /* */ across multiple lines, like:

/*
select *
  from user_rec;
*/

select count(*) as user_count
  from user_rec;

You will get an error, and it will still execute the commented query:

Found a non-terminated comment ("/*" with no matching "*/").
756,806 Row(s) affected
1 Row(s) affected
A syntax error has occurred.

You have two options:

  1. Just use the curly brace commenting when working with Informix and accept that the editor's color highlighting will not identify them as comments, which reduced readability.
  2. Make WinSQL parse comments locally.

You can make WinSQL parse comments locally by going to: Edit > Options and checking the box "Parse comments locally" in the General tab.

Doing this will make sure that any lines that the editor identifies as a comment will not be passed to the server. I, personally, prefer this.