[GRASS-SVN] r38793 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 19 06:55:47 EDT 2009


Author: hamish
Date: 2009-08-19 06:55:47 -0400 (Wed, 19 Aug 2009)
New Revision: 38793

Modified:
   grass/trunk/gui/wxpython/gui_modules/sqlbuilder.py
Log:
merge fixes from devbr6-
 fix backwards >=,> button labels;
 use RunCommand instead of os.system();
 Verify messages to Command Output window;
 add some debug comments about broken curson posn


Modified: grass/trunk/gui/wxpython/gui_modules/sqlbuilder.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/sqlbuilder.py	2009-08-19 10:52:59 UTC (rev 38792)
+++ grass/trunk/gui/wxpython/gui_modules/sqlbuilder.py	2009-08-19 10:55:47 UTC (rev 38793)
@@ -11,9 +11,10 @@
 
 AUTHOR(S): GRASS Development Team
            Original author: Jachym Cepicky <jachym.cepicky gmail.com>
-           Various updates: Martin Landa <landa.martin gmail.com>
+           Various updates: Martin Landa <landa.martin gmail.com>,
+                            Hamish Bowman <hamish_b yahoo com>
 
-COPYRIGHT: (C) 2007 by the GRASS Development Team
+COPYRIGHT: (C) 2007-2009 by the GRASS Development Team
 
            This program is free software under the GNU General Public
            License (>=v2). Read the file COPYING that comes with GRASS
@@ -50,15 +51,24 @@
         self.vectmap = vectmap
         if not "@" in self.vectmap:
             self.vectmap = self.vectmap + "@" + grass.gisenv()['MAPSET']
+
         self.mapname, self.mapset = self.vectmap.split("@")
-        self.layer,self.tablename, self.column, self.database, self.driver =\
-                 os.popen("v.db.connect -g fs=\"|\" map=%s" %\
-                (self.vectmap)).readlines()[0].strip().split("|")
 
-        self.qtype = qtype        # type of the uqery: SELECT, UPDATE, DELETE, ...
-        self.column_names = []       # array with column names
+        #FIXME: pass layer number to v.db.connect ???
+        ret = gcmd.RunCommand('v.db.connect',
+                      quiet = True,
+                      read = True,
+                      flags = 'g',
+                      fs = '|',
+                      map = self.vectmap)
+        for line in ret.splitlines():
+            self.layer,self.tablename, self.column, self.database, self.driver =\
+                line.strip().split("|")
+
+        self.qtype = qtype      # type of the uqery: SELECT, UPDATE, DELETE, ...
+        self.column_names = []  # array with column names
         self.columns = {}       # array with colum properties
-        self.colvalues = []     # arrya with uniqe values in selected column
+        self.colvalues = []     # array with uniqe values in selected column
         self.heading = ""
         self.parent = parent
 
@@ -86,10 +96,10 @@
         self.btn_is = wx.Button(self, -1, "=")
         self.btn_isnot = wx.Button(self, -1, "!=")
         self.btn_like = wx.Button(self, -1, "LIKE")
-        self.btn_gt = wx.Button(self, -1, ">=")
-        self.btn_gtis = wx.Button(self, -1, ">")
-        self.btn_lt = wx.Button(self, -1, "<=")
-        self.btn_ltis = wx.Button(self, -1, "<")
+        self.btn_gt = wx.Button(self, -1, ">")
+        self.btn_gtis = wx.Button(self, -1, ">=")
+        self.btn_lt = wx.Button(self, -1, "<")
+        self.btn_ltis = wx.Button(self, -1, "<=")
         self.btn_or = wx.Button(self, -1, "OR")
         self.btn_not = wx.Button(self, -1, "NOT")
         self.btn_and = wx.Button(self, -1, "AND")
@@ -249,15 +259,24 @@
         self.list_values.Clear()
         column = self.list_columns.GetString(idx)
         i = 0
-        for line in os.popen("db.select -c database=\"%s\" driver=%s sql=\"SELECT %s FROM %s\"" %\
-                (self.database,self.driver,column,self.tablename)):
-                if justsample and i < 256 or \
-                   not justsample:
-                    self.list_values.Insert(line.strip(),0)
-                else:
-                    break
-                i += 1
+        querystring = "SELECT %s FROM %s" % (column, self.tablename)
 
+        ret = gcmd.RunCommand('db.select',
+                              read = True,
+                              quiet = True,
+                              flags = 'c',
+                              database = self.database,
+                              driver = self.driver,
+                              sql = querystring)
+
+        for line in ret.splitlines():
+            if justsample and i < 256 or \
+               not justsample:
+                self.list_values.Insert(line.strip(),0)
+            else:
+                break
+            i += 1
+
     def GetSampleValues(self,event):
         self.GetUniqueValues(None,True)
 
@@ -277,8 +296,6 @@
         self.__addSomething(value)
 
     def AddMark(self,event):
-
-
         if event.GetId() == self.btn_is.GetId(): mark = "="
         elif event.GetId() == self.btn_isnot.GetId(): mark = "!="
         elif event.GetId() == self.btn_like.GetId(): mark = "LIKE"
@@ -306,11 +323,20 @@
                 newsqlstr += " "
         except:
             pass
+
         newsqlstr += what
         newsqlstr += " "+sqlstr[position:]
 
         self.text_sql.SetValue(newsqlstr)
+        # FIXME: cursor position is messed up
+        #   see also   http://trac.wxwidgets.org/ticket/10051
+        #DEBUG: print "before: %d" % (position)
         self.text_sql.SetInsertionPoint(position)
+        #? self.text_sql.SetInsertionPoint(position+len(what))
+        #? self.text_sql.SetInsertionPointEnd()
+        #DEBUG: print "len(what)=%d" % (len(what))
+        #DEBUG: print "after: %d" % (self.text_sql.GetPosition()[0])
+        #DEBUG: print " "
 
     def OnApply(self,event):
         if self.parent:
@@ -318,13 +344,25 @@
                 self.parent.text_query.SetValue= self.text_sql.GetValue().strip().replace("\n"," ")
             except:
                 pass
+
     def OnVerify(self,event):
         if self.text_sql.GetValue():
-            if os.system("""db.select -t --verbose driver=%s database="%s" sql="SELECT * FROM %s WHERE %s" """ % \
-                    (self.driver, self.database,self.tablename,
-                        self.text_sql.GetValue().strip().replace("\n"," "))):
-                # FIXME: LOG
-                # print self.text_sql.GetValue().strip().replace("\n"," "), "not correct!"
+            querystring = "SELECT * FROM %s WHERE %s" % \
+                          (self.tablename,
+                           self.text_sql.GetValue().strip().replace("\n"," "))
+            # FIXME: LOG
+            # print self.text_sql.GetValue().strip().replace("\n"," "), "not correct!"
+
+            print "Testing [%s] ..." % (querystring)
+            ret, msg = gcmd.RunCommand('db.select',
+                                  getErrorMsg = True,
+                                  verbose = True,
+                                  flags = 't',
+                                  driver = self.driver,
+                                  database = self.database,
+                                  sql = querystring)
+            print msg, " "
+            if ret == 0:
                 pass
 
     def OnClear(self, event):



More information about the grass-commit mailing list