瀏覽代碼

pythonlib: implement db_begin/commit_transaction (see https://trac.osgeo.org/grass/ticket/2759)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67370 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 年之前
父節點
當前提交
7a90280cf0
共有 1 個文件被更改,包括 21 次插入1 次删除
  1. 21 1
      lib/python/script/db.py

+ 21 - 1
lib/python/script/db.py

@@ -10,7 +10,7 @@ Usage:
     grass.db_describe(table)
     ...
 
-(C) 2008-2009, 2012 by the GRASS Development Team
+(C) 2008-2015 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
 for details.
@@ -196,3 +196,23 @@ def db_table_in_vector(table):
         return used
     else:
         return None
+
+def db_begin_transaction(driver):
+    """Begin transaction.
+
+    :return: SQL command as string
+    """
+    if driver in ('sqlite', 'pg'):
+        return 'BEGIN'
+    if driver == 'mysql':
+        return 'START TRANSACTION'
+    return ''
+
+def db_commit_transaction(driver):
+    """Commit transaction.
+
+    :return: SQL command as string
+    """
+    if driver in ('sqlite', 'pg', 'mysql'):
+        return 'COMMIT'
+    return ''