-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Langtree
committed
Jun 23, 2011
0 parents
commit 61f9803
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>author</key> | ||
<string>Hans-Jörg Bibiko</string> | ||
<key>category</key> | ||
<string>Query Editor</string> | ||
<key>command</key> | ||
<string> | ||
# Since this command will execute SQL statements at the front most | ||
# document window's connection check for a passed process ID to cancel | ||
# this command by displaying a tooltip. Otherwise the loop after | ||
# “open "sequelpro://$SP_PROCESS_ID@passToDoc/ExecuteQuery"” | ||
# won't break. | ||
if [ -z $SP_PROCESS_ID ]; then | ||
echo "<font color=red>No front most connection window found!</font>" | ||
exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP | ||
fi | ||
# send query to Sequel Pro | ||
cat <<SQL > "$SP_QUERY_FILE" | ||
EXPLAIN EXTENDED `cat` | ||
SQL | ||
# execute the SQL statement; the result will be available in the file $SP_QUERY_RESULT_FILE | ||
open "sequelpro://$SP_PROCESS_ID@passToDoc/ExecuteQuery" | ||
# wait for Sequel Pro; status file will be written to disk if query was finished | ||
while [ 1 ] | ||
do | ||
[[ -e "$SP_QUERY_RESULT_STATUS_FILE" ]] && break | ||
sleep 0.01 | ||
done | ||
# check for errors | ||
if [ `cat $SP_QUERY_RESULT_STATUS_FILE` == 1 ]; then | ||
echo "Nothing found to EXPLAIN" | ||
exit $SP_BUNDLE_EXIT_SHOW_AS_HTML_TOOLTIP | ||
fi | ||
# remove file hand shake files | ||
rm -f $SP_QUERY_RESULT_STATUS_FILE | ||
rm -f $SP_QUERY_FILE | ||
# process the EXPLAIN result | ||
cat $SP_QUERY_RESULT_FILE | perl -e ' | ||
# get the table header | ||
$firstline = <>; | ||
@header = split(/\t/, $firstline); | ||
# read all result lines | ||
@allresults = (); | ||
while($line = <>) { | ||
my @a = split(/\t/, $line); | ||
push(@allresults, \@a); | ||
} | ||
print <<HEAD; | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<center> | ||
<h3>EXPLAIN</h3> | ||
<table width=200px> | ||
<tr><td align=center> | ||
HEAD | ||
# do a syntax highlighting for the passed query | ||
qx/cp $ENV{"SP_BUNDLE_INPUT"} $ENV{"SP_QUERY_FILE"}/; | ||
$task = "sequelpro://".$ENV{'SP_PROCESS_ID'}."@"."SyntaxHighlighting/html"; | ||
qx/open "$task"/; | ||
while(!(-e $ENV{'SP_QUERY_RESULT_STATUS_FILE'})) { sleep(0.01); } | ||
open(RF, "<:utf8", $ENV{'SP_QUERY_RESULT_FILE'}) or die $!; | ||
while(<RF>) { print; } | ||
close(RF); | ||
qx/rm -f $ENV{'SP_QUERY_RESULT_FILE'}/; | ||
qx/rm -f $ENV{'SP_QUERY_RESULT_STATUS_FILE'}/; | ||
qx/rm -f $ENV{'SP_QUERY_FILE'}/; | ||
print "</td></tr></table>\n"; | ||
# print the result as vertical table | ||
print "<table>\n"; | ||
for($i = 0; $i <= $#header; $i++) { | ||
print "<tr><td align=right><b>$header[$i]:</b></td><td>&nbsp;</td>"; | ||
foreach $line (@allresults) { | ||
$r = $line->[$i]; | ||
$r =~ s/;\s*/<br>/g; | ||
print "<td>$r</td>"; | ||
} | ||
print "</tr>\n"; | ||
} | ||
print <<FOOTER; | ||
</table> | ||
</center> | ||
</body> | ||
</html> | ||
FOOTER | ||
'</string> | ||
<key>contact</key> | ||
<string>znvy@ovovxb.qr</string> | ||
<key>description</key> | ||
<string>Takes the current query or selection and execute the SQL statement: | ||
EXPLAIN EXTENDED "the_query" | ||
and displays the result as tooltip. | ||
Version 1.0</string> | ||
<key>input</key> | ||
<string>selectedtext</string> | ||
<key>input_fallback</key> | ||
<string>currentquery</string> | ||
<key>keyEquivalent</key> | ||
<string></string> | ||
<key>name</key> | ||
<string>Explain Query</string> | ||
<key>output</key> | ||
<string>showashtmltooltip</string> | ||
<key>scope</key> | ||
<string>inputfield</string> | ||
<key>tooltip</key> | ||
<string>EXPLAIN EXTENDED the current query</string> | ||
<key>uuid</key> | ||
<string>D8E68049-C53E-44EA-ADBA-E636F69F5F0E</string> | ||
</dict> | ||
</plist> |