Archive for October, 2009

TextMate Sql Formatter Command

Oct 27 2009 Published by under Database,English,Mac,OS X,Ruby,TextMate

Recently, I am doing some heavy database migrations, so I spend a lot of time on playing with SQL again. It’s fun as always. But there are some SQL files are quite long and messy. There is no problem on running, but it’s really painful to look at and do any changes.

So I went out and tried to find any SQL Formatters. There are quite a few and I’ve tasted them as many as I can.

At the end, I found myself really enjoy using Instant SQL Formatter from Gudu Software. It has a free online sql tidy tool and it’s very powerful:

Instant SQL Formatter is a free online sql tidy tool, actually, it not only can beautify your sql but also can turn your formatted sql into html code, so you can post coloured sql code in your blog, forum,wiki and any website easily. In addition to beautifying SQL code, this sql tool can translate SQL code into C#, Java, PHP, DELPHI and other program languages. Another useful feature is find out all database objects such as table, column, function in sql by selecting output format to list database object.

Here is the Free online Tool and here are some examples you can see. Quite impressive! To format your SQL, you just need paste the sql in the textarea, choose the database and output format then press “Format SQL”, you’ll get the result right away.

Every SQL file looks great now. But after tens of copy & paste and copy & paste between TextMate and browser, it feels not as smooth as I want. I think I should find a better way.

Gudu software does provide some desktop version even add-ins, sadly there are all Windows based. It’s not a option for me.

After reading the page source of their free online tool, here is the result:

#!/usr/bin/env ruby

require 'net/http'

url = 'http://www.dpriver.com/cgi-bin/ppserver'
url = URI.parse(url)
http = Net::HTTP.new(url.host, url.port)

query = "<sqlpp_request><dbvendor>mysql</dbvendor><outputfmt>SQL</outputfmt><inputsql>#{ENV['TM_SELECTED_TEXT']}</inputsql><formatoptions><keywordcs>Uppercase</keywordcs><identifiercs>Lowercase</identifiercs><functioncs>InitCap</functioncs><lnbrwithcomma>after</lnbrwithcomma><liststyle>stack</liststyle><salign>sleft</salign><quotechar>\"</quotechar></formatoptions></sqlpp_request>"

header = {
  'Referer' => 'http://www.dpriver.com/pp/sqlformat.htm',
  'User-Agent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.1) Firefox/3.0.1'
}

resp, data = http.post(url.path, query, header)

puts resp.error! unless data
formatted_sql = data[/<formattedsql>.*<\/formattedsql>/m].gsub(/<\/?.*>/, '')

puts formatted_sql

Download TextMate SqlFormatter Command

How to install?

After save to your own disk, unzip it, just open those tmCommand files and add them into your TextMate. The shortcut key has been set to Command+Shift+F for now.

As you can see there are two tmCommand files. The “SQL Formatter – Stack” will format you sql with every fields has its own line, the “No Stack” one will put all the fields into one line. Try them and you’ll see the difference.

How to use it?

Open TextMate,  select the SQL query you want to format and press Command+Shift+F. The beautiful formatted SQL will replace the selected SQL “instantly”!

Requirement?

The command is using free online Instant SQL Formatter, so the internet is required.

What’s next?

As I said before, SQL Pretty Printer is really powerful. I really should create a complete TextMate Bundle instead of just one command. But before doing this, I should get the permission from them now.

Any update will be posted here, hopefully soon.

Enjoy the SQL Formatter Command and stay tuned for more.

10 responses so far

Seeing is not believing

Oct 22 2009 Published by under English

Can you see the squares marked A and B are the same shade of gray?

No way I can believe that, can you?

See the proof on Professor Edward’s page:

Proof of Checkshadow illusion.

No responses yet

Posting fake ads is not marketing

Oct 19 2009 Published by under Canada,Toronto

I saw a new ads on Craigslist today:

BNIB IPHONE 3GS!!!!16GB!!!BLACK!!! – $400 (Toronto)

Worth trying, right?

Two minutes later:

On Mon, Oct 19, 2009 at 12:48 PM, info@cheqd.com wrote:
We are a legitimate business, you could see the site for yourself. No scams if that is what your assuming.
Sent from my BlackBerry® smartphone

From: Libin Pan
Date: Mon, 19 Oct 2009 12:47:50 -0400
To: info@cheqd.com
Subject: Re: You received a response to your Ad!

Nice try! No, thank you.

On Mon, Oct 19, 2009 at 12:46 PM, info@cheqd.com wrote:
This item has been sold, sorry! But we will get more, So Join our mailing list to get more info on new items being sold and updates. Click the “get cheqd” tab to see how we work.

Thanks,

Cheqd team
——Original Message——
From: libinpan@gmail.com
To: info@cheqd.com
ReplyTo: libinpan@gmail.com
Subject: You received a response to your Ad!
Sent: Oct 19, 2009 12:46 PM

Dear User,
You have received a message from a user who is interested in your Ad. The following is the message and contact information of the user.
Visitor Email: libinpan@gmail.com
Message: Hey there,

Is the phone still available? How can I contact you?

Thanks,
Libin

Sent from my BlackBerry® smartphone

Ten minutes later:

On Mon, Oct 19, 2009 at 1:16 PM, ry1000@hotmail.com wrote:
Goodluck finding an iphone for 400
Sent from my BlackBerry® smartphone

From: Libin Pan
Date: Mon, 19 Oct 2009 13:05:10 -0400
To:
Subject: Re: BNIB IPHONE 3GS!!!!16GB!!!BLACK!!! – $400 (Toronto)

Sure. Do you notice it’s me again and it’s you again?

Thanks!

On Mon, Oct 19, 2009 at 1:01 PM, ry1000@hotmail.com wrote:
Hey

I sold this item already through cheqd. This site is so easy and safe to use. Everybody should try it. I’m sure people will drop more iphones off to sell.
Sent from my BlackBerry® smartphone

From: Libin Pan
Date: Mon, 19 Oct 2009 12:43:02 -0400
To: ry1000@hotmail.com
Subject: BNIB IPHONE 3GS!!!!16GB!!!BLACK!!! – $400 (Toronto)

** CRAIGSLIST ADVISORY — AVOID SCAMS BY DEALING LOCALLY
** Avoid: wiring money, cross-border deals, work-at-home
** Beware: cashier checks, money orders, escrow, shipping
** More Info: http://www.craigslist.org/about/scams.html

Hey there,

Is the phone still available? How can I contact you?

Thanks,
Libin

http://toronto.craigslist.ca/tor/ele/1424012784.html

this message was remailed to you via: sale-rtkpj-1424012784@craigslist.org

Sure, I am too naive to believe I can get a iPhone 3GS for $400. But posting fake ads on competitor’s site is really not a good marketing strategy. How can I believe the listings on your site then?

So, please, avoid doing business with cheqd.com if you can.

No responses yet