[GRASS-SVN] r39343 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 29 17:15:38 EDT 2009
Author: martinl
Date: 2009-09-29 17:15:38 -0400 (Tue, 29 Sep 2009)
New Revision: 39343
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
Log:
wxGUI/ATM: full SQL statements
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py 2009-09-29 19:31:31 UTC (rev 39342)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py 2009-09-29 21:15:38 UTC (rev 39343)
@@ -145,12 +145,13 @@
self.mapDBInfo = mapDBInfo
self.LoadData(self.layer)
- def LoadData(self, layer, columns=None, where=None):
+ def LoadData(self, layer, columns=None, where=None, sql=None):
"""!Load data into list
@param layer layer number
- @param columns list of columns for output
- @param where where statement
+ @param columns list of columns for output (-> v.db.select)
+ @param where where statement (-> v.db.select)
+ @param sql full sql statement (-> db.select)
@return id of key column
@return -1 if key column is not displayed
@@ -195,23 +196,31 @@
# TODO: more effective way should be implemented...
outFile = tempfile.NamedTemporaryFile(mode='w+b')
- if columns:
- ret = gcmd.RunCommand('v.db.select',
+ if sql:
+ ret = gcmd.RunCommand('db.select',
quiet = True,
+ parent = self,
flags = 'c',
- map = self.mapDBInfo.map,
- layer = layer,
- columns = ','.join(columns),
- where = where,
- stdout=outFile)
+ sql = sql,
+ output = outFile.name)
else:
- ret = gcmd.RunCommand('v.db.select',
- quiet = True,
- flags = 'c',
- map = self.mapDBInfo.map,
- layer = layer,
- where = where,
- stdout=outFile)
+ if columns:
+ ret = gcmd.RunCommand('v.db.select',
+ quiet = True,
+ flags = 'c',
+ map = self.mapDBInfo.map,
+ layer = layer,
+ columns = ','.join(columns),
+ where = where,
+ stdout=outFile)
+ else:
+ ret = gcmd.RunCommand('v.db.select',
+ quiet = True,
+ flags = 'c',
+ map = self.mapDBInfo.map,
+ layer = layer,
+ where = where,
+ stdout=outFile)
# These two should probably be passed to init more cleanly
# setting the numbers of items = number of elements in the dictionary
@@ -244,6 +253,7 @@
while True:
# os.linesep doesn't work here (MSYS)
record = outFile.readline().replace('\n', '')
+
if not record:
break
@@ -1787,6 +1797,8 @@
"""!Apply simple/advanced sql statement"""
keyColumn = -1 # index of key column
listWin = self.FindWindowById(self.layerPage[self.layer]['data'])
+ sql = None
+
if self.FindWindowById(self.layerPage[self.layer]['simple']).GetValue():
# simple sql statement
whereCol = self.FindWindowById(self.layerPage[self.layer]['whereColumn']).GetStringSelection()
@@ -1806,6 +1818,8 @@
win = self.FindWindowById(self.layerPage[self.layer]['statement'])
try:
cols, where = self.ValidateSelectStatement(win.GetValue())
+ if cols is None and where is None:
+ sql = win.GetValue()
except TypeError:
wx.MessageBox(parent=self,
message=_("Loading attribute data failed.\n"
@@ -1815,10 +1829,10 @@
cols = None
where = None
- if cols or where:
+ if cols or where or sql:
try:
keyColumn = listWin.LoadData(self.layer, columns=cols,
- where=where)
+ where=where, sql=sql)
except gcmd.CmdError, e:
wx.MessageBox(parent=self,
message=_("Loading attribute data failed.\n\n%s") % e.message,
@@ -1826,11 +1840,14 @@
win.SetValue("SELECT * FROM %s" % self.mapDBInfo.layers[self.layer]['table'])
# sort by key column
- if keyColumn > -1:
- listWin.SortListItems(col=keyColumn, ascending=True)
+ if sql and 'order by' in sql.lower():
+ pass # don't order by key column
else:
- listWin.SortListItems(col=0, ascending=True)
-
+ if keyColumn > -1:
+ listWin.SortListItems(col=keyColumn, ascending=True)
+ else:
+ listWin.SortListItems(col=0, ascending=True)
+
# update statusbar
self.log.write(_("Number of loaded records: %d") % \
self.FindWindowById(self.layerPage[self.layer]['data']).GetItemCount())
@@ -1868,7 +1885,7 @@
if index > -1:
where = statement[index+6:]
else:
- return None
+ where = None
else:
where = None
@@ -2042,18 +2059,19 @@
"""!Get vector name"""
return self.vectorName
- def LoadData(self, layer, columns=None, where=None):
+ def LoadData(self, layer, columns=None, where=None, sql=None):
"""!Load data into list
@param layer layer number
@param columns list of columns for output
@param where where statement
-
+ @param sql full sql statement
+
@return id of key column
@return -1 if key column is not displayed
"""
listWin = self.FindWindowById(self.layerPage[layer]['data'])
- return listWin.LoadData(layer, columns, where)
+ return listWin.LoadData(layer, columns, where, sql)
class TableListCtrl(wx.ListCtrl,
listmix.ListCtrlAutoWidthMixin):
More information about the grass-commit
mailing list