[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5010 - in trunk/gnue-dbtools/src/sql: . commands formatters
From: |
jcater |
Subject: |
r5010 - in trunk/gnue-dbtools/src/sql: . commands formatters |
Date: |
Fri, 19 Dec 2003 17:01:11 -0600 (CST) |
Author: jcater
Date: 2003-12-19 17:01:10 -0600 (Fri, 19 Dec 2003)
New Revision: 5010
Modified:
trunk/gnue-dbtools/src/sql/Client.py
trunk/gnue-dbtools/src/sql/Instance.py
trunk/gnue-dbtools/src/sql/commands/clear.py
trunk/gnue-dbtools/src/sql/commands/command.py
trunk/gnue-dbtools/src/sql/commands/comment.py
trunk/gnue-dbtools/src/sql/commands/commit.py
trunk/gnue-dbtools/src/sql/commands/heading.py
trunk/gnue-dbtools/src/sql/commands/help.py
trunk/gnue-dbtools/src/sql/commands/input.py
trunk/gnue-dbtools/src/sql/commands/list.py
trunk/gnue-dbtools/src/sql/commands/print.py
trunk/gnue-dbtools/src/sql/commands/rollback.py
trunk/gnue-dbtools/src/sql/commands/set.py
trunk/gnue-dbtools/src/sql/commands/spool.py
trunk/gnue-dbtools/src/sql/formatters/Base.py
trunk/gnue-dbtools/src/sql/formatters/csv.py
Log:
added basic output support and some new command line options; defaults to CSV
output for now
Modified: trunk/gnue-dbtools/src/sql/Client.py
===================================================================
--- trunk/gnue-dbtools/src/sql/Client.py 2003-12-19 22:59:59 UTC (rev
5009)
+++ trunk/gnue-dbtools/src/sql/Client.py 2003-12-19 23:01:10 UTC (rev
5010)
@@ -49,7 +49,10 @@
COMMAND = "gnue-sql"
NAME = "GNUe DBTools - SQL Shell"
USAGE = GClientApp.USAGE + " [file] [param=value ...]"
- COMMAND_OPTIONS = [ ]
+ COMMAND_OPTIONS = [
+ [ 'connection',None,'connect',1,None, 'name',
+ _('Connect to the specified database. <name> refers to a
connections.conf definition.')],
+ ]
SUMMARY = \
_("GNUe SQL Shell is the sql shell interpreter for the GNUe project.")
USE_DATABASE_OPTIONS = 1
@@ -83,7 +86,7 @@
userParameters = self.getCommandLineParameters(arguments)
- self.instance = Instance(scriptname, userParameters, self.OPTIONS)
+ self.instance = Instance(self.connections, scriptname, userParameters,
self.OPTIONS)
if __name__ == '__main__':
Modified: trunk/gnue-dbtools/src/sql/Instance.py
===================================================================
--- trunk/gnue-dbtools/src/sql/Instance.py 2003-12-19 22:59:59 UTC (rev
5009)
+++ trunk/gnue-dbtools/src/sql/Instance.py 2003-12-19 23:01:10 UTC (rev
5010)
@@ -31,8 +31,11 @@
from gnue.dbtools import VERSION
from commands import initCommands
from commands import Base
-import os, sys
+import os, sys, string
+from formatters.csv import Formatter
+
+
#
# Try to open up a "readline" compatable shell
# if supported. Otherwise, do a plain shell
@@ -51,7 +54,8 @@
# Basic instance
#
class _Instance:
- def __init__(self, script="", parameters={}, options={}):
+ def __init__(self, connections, script="", parameters={}, options={}):
+ self.connections = connections
self.options = options
self.parameters = parameters
@@ -63,6 +67,15 @@
self.ignoreexit = 0
self.commands = initCommands(self)
+ self.connection = None
+ if options.get('connection',None):
+ self.connection_name = options['connection']
+ else:
+ self.connection_name = ""
+
+ # TODO: Handle more elegantly
+ self.formatter = Formatter(sys.stdout)
+
# Process the script
if script:
self.processFile(script)
@@ -150,9 +163,25 @@
self.buffer = []
return
- print "I don't actually query yet!"
+ if not self.connection_name:
+ print _("ERROR: Not connected to a database.")
+ elif not self.connection:
+ # TODO: Error handling
+ self.connection = self.connections.getConnection(self.connection_name,
login=1)
+ if not hasattr(self.connection,'sql'):
+ print "WARNING: this connection type does not support SQL extensions."
+
+ results = self.connection.sql(string.join(self.buffer,'\n'))
+ self.formatter.begin() # TODO: Doesn't belong here
+ self.formatter.beginTable(None)
+ for row in results:
+ self.formatter.writeCells(row)
+
+ self.formatter.endTable()
+ self.formatter.end() # TODO: Doesn't belong here
+
print
-
+
self.lastbuffer = self.buffer
self.buffer = []
Modified: trunk/gnue-dbtools/src/sql/commands/clear.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/clear.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/clear.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -32,4 +32,4 @@
class Command(BaseCommand):
SHORT = "Clears the screen"
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/command.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/command.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/command.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/comment.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/comment.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/comment.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/commit.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/commit.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/commit.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/heading.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/heading.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/heading.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/help.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/help.py 2003-12-19 22:59:59 UTC (rev
5009)
+++ trunk/gnue-dbtools/src/sql/commands/help.py 2003-12-19 23:01:10 UTC (rev
5010)
@@ -76,10 +76,10 @@
* For help with formatting fields, run HELP FORMAT
* For help with outputting
-To Exit GNUe SQL Shell, enter QUIT and press RETURN.
+To exit GNUe SQL Shell, enter QUIT and press RETURN.
""")
else:
print _("""
Help is currently unavailable for this topic. Bug the developers.
-(Or volunteer to write this module :)
+(Or volunteer to write help for this module :)
""")
Modified: trunk/gnue-dbtools/src/sql/commands/input.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/input.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/input.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/list.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/list.py 2003-12-19 22:59:59 UTC (rev
5009)
+++ trunk/gnue-dbtools/src/sql/commands/list.py 2003-12-19 23:01:10 UTC (rev
5010)
@@ -36,3 +36,7 @@
for line in self.instance.lastbuffer:
print "%3d " % i + line
i += 1
+
+ if i == 1:
+ print _("(no lines in buffer)")
+
Modified: trunk/gnue-dbtools/src/sql/commands/print.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/print.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/print.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -30,5 +30,9 @@
from Base import BaseCommand
class Command(BaseCommand):
+ SHORT = _("Prints a string to the current output stream")
def call(self, args):
- pass
+ # TODO: support for variables, etc?
+ for arg in args:
+ print arg,
+ print
Modified: trunk/gnue-dbtools/src/sql/commands/rollback.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/rollback.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/rollback.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/set.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/set.py 2003-12-19 22:59:59 UTC (rev
5009)
+++ trunk/gnue-dbtools/src/sql/commands/set.py 2003-12-19 23:01:10 UTC (rev
5010)
@@ -31,4 +31,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/commands/spool.py
===================================================================
--- trunk/gnue-dbtools/src/sql/commands/spool.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/commands/spool.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -32,4 +32,4 @@
class Command(BaseCommand):
def call(self, args):
- pass
+ print "(not implemented)"
Modified: trunk/gnue-dbtools/src/sql/formatters/Base.py
===================================================================
--- trunk/gnue-dbtools/src/sql/formatters/Base.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/formatters/Base.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -82,10 +82,10 @@
def writeText(self, text):
pass
- def beginTable(self, cells)
+ def beginTable(self, cells):
pass
- def endTable(self)
+ def endTable(self):
pass
def writeCells(self, cells):
Modified: trunk/gnue-dbtools/src/sql/formatters/csv.py
===================================================================
--- trunk/gnue-dbtools/src/sql/formatters/csv.py 2003-12-19 22:59:59 UTC
(rev 5009)
+++ trunk/gnue-dbtools/src/sql/formatters/csv.py 2003-12-19 23:01:10 UTC
(rev 5010)
@@ -36,17 +36,20 @@
def writeText(self, text):
self.stream.write(str(text) + '\n')
- def beginTable(self, cells)
+ def beginTable(self, cells):
pass
- def endTable(self)
+ def endTable(self):
pass
def writeCells(self, cells):
i = 0
for cell in cells:
- self._sanitize(self.formatCell(i, text) [0])
+ if i:
+ self.stream.write(',')
+ self._sanitize(self.formatCell(i, cell))
i += 1
+ self.stream.write('\n')
def writeSummary(self, cells):
self.writeCells(cells)
@@ -59,5 +62,5 @@
if ',' in text:
self.stream.write('"%s"' % text)
else:
- self.stream.write(return text)
+ self.stream.write(text)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5010 - in trunk/gnue-dbtools/src/sql: . commands formatters,
jcater <=