[gevice] Add explicit sql commit.



commit 40475066ad08a7e93be42a38e907fcaa959bc9b4
Author: Alejandro Valdes Jimenez <avaldes gnome org>
Date:   Wed Dec 4 12:59:09 2013 -0300

    Add explicit sql commit.

 ChangeLog             |    4 ++++
 src/gevice.py         |   14 +++++++++-----
 src/gevicedatabase.py |    3 ++-
 3 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a007ee2..9f011bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-12-04  Alejandro Valdes Jimenez   <avaldes gnome org>
+       * src/gevice.py:
+       * src/gevicedatabase.py: Add explicit sql commit.
+
 2013-03-14  Alejandro Valdes Jimenez  <avaldes gnome org>
        * src/gevice.py: Fixed wrong call to function.
 
diff --git a/src/gevice.py b/src/gevice.py
index 91d9f3d..f0b35f7 100755
--- a/src/gevice.py
+++ b/src/gevice.py
@@ -39,7 +39,7 @@ gettext.bind_textdomain_codeset (config.PACKAGE, "UTF-8")
 from gettext import gettext as _
 
 class Gevice:
-  def __init__ (self,openfilename=None):
+  def __init__ (self, openfilename=None):
     self.dbsqlite = openfilename
     self.connected_to_database = False
     self.context_id = None
@@ -280,7 +280,7 @@ class Gevice:
       self.gmodel.insert_new_item (itern,n.name,n.ip,n.com)
       self.insert_data_into_model(n,itern)
 
-  def on_action_open (self,action):
+  def on_action_open (self, action):
     self.gmodel.treestore.clear()
     self.gmodel.treeview.set_model(None)
     
@@ -390,7 +390,7 @@ class Gevice:
     else:
       self.gmodel.treeview.collapse_row(path)
 
-  def on_action_save (self,action):
+  def on_action_save (self, action):
     self.devices_to_connect = []
     self.gdbase.clear_database()
 
@@ -408,11 +408,13 @@ class Gevice:
 
   def copy_device_to_dbase (self,model,path,iter,data):
     data = self.gmodel.treestore.get(iter,0,1,2)
-
+    
+    # save first level.
     self.gdbase.insert_device (data)
-    if (self.gdbase.get_status_sql() == False):
+    if (self.gdbase.get_status_sql()==False):
       return
     else:
+      # If no error, save your children
       if (self.gmodel.treestore.iter_has_child(iter)):
         iterc = self.gmodel.treestore.iter_children(iter)
         next = iterc
@@ -422,6 +424,7 @@ class Gevice:
           self.devices_to_connect.append ("'" + data[0] + "','" + child[0] + "'")
           next2 = self.gmodel.treestore.iter_next(next)
           next = next2
+    
 
   def on_toggle_tree (self,action):
     if (action.get_active() == True):
@@ -598,6 +601,7 @@ class Gevice:
 
 if __name__ == "__main__":
   if len(sys.argv)>1:
+    # Database to open.
     gevice = Gevice(sys.argv[1])
   else:
     gevice = Gevice()
diff --git a/src/gevicedatabase.py b/src/gevicedatabase.py
index 4c3b09e..e5a4024 100644
--- a/src/gevicedatabase.py
+++ b/src/gevicedatabase.py
@@ -208,7 +208,7 @@ class GeviceDatabase:
   def insert_device (self,data):
     """
     Insert data into database.
-    @param data The [name,ip] as list.
+    @param data The [name,ip,comment] as list.
     """
     sql = "insert into device (id_dev,ip_dev,obs_dev) "
     sql = sql + "values ('" + data[0] + "','" + data[1] + "','" + data[2] + "');"
@@ -231,6 +231,7 @@ class GeviceDatabase:
     try:
       self.__cur.execute(sql)
       self.__status_sql = True
+      self.__conn.commit()
     except sqlite3.Error as e:
       self.__conn.rollback()
       print "An error occurred: ", e.args[0]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]