浏览代码

db_select: clean up afterwards

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47266 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 13 年之前
父节点
当前提交
7074e894c3
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      lib/python/db.py

+ 9 - 4
lib/python/db.py

@@ -92,21 +92,26 @@ def db_select(table, sql, file = False, **args):
     @param file  True if sql is filename
     @param args  see db.select arguments
     """
-    ofile = pytempfile.NamedTemporaryFile(mode = 'w+b')
+    fname = tempfile(create = False)
     if not file:
         ret = run_command('db.select', quiet = True,
                           flags = 'c',
                           table = table,
                           sql = sql,
-                          output = ofile.name)
+                          output = fname)
     else: # -> sql is file
         ret = run_command('db.select', quiet = True,
                           flags = 'c',
                           table = table,
                           input = sql,
-                          output = ofile.name)
+                          output = fname)
     
     if ret != 0:
         fatal(_("Fetching data from table <%s> failed") % table)
+    ofile = open(fname)
+
+    result = ofile.readlines()
+    ofile.close()
+    try_remove(fname)
         
-    return ofile.readlines()
+    return result