コード例 #1
0
ファイル: ConfigurationDB.py プロジェクト: babytux/PyCamimg
 def save(self):
     '''
     @summary: Saves current configuration.
     '''
     conn = Util.getConnection()
     if (conn != None):
         queryString = 'insert or ignore into %s (key, value) values (?, ?)' % Constants.TBL_PARAMS
         updateQueryString = 'update %s set value = ? where key = ?' % Constants.TBL_PARAMS
         curr = conn.cursor()
         try:
             curr.execute(updateQueryString, (self.__photoFolder__, Constants.CONFIG_PARAM_PHOTO_DIR,))
             if (curr.rowcount == 0):
                 curr.execute(queryString, (Constants.CONFIG_PARAM_PHOTO_DIR, self.__photoFolder__,))                
             conn.commit()
         except Error, e:
             __log__.error('An error was occurred when it was saving configuration into database. %s', e)
             conn.rollback()
         curr.close()
コード例 #2
0
ファイル: ConfigurationDB.py プロジェクト: babytux/PyCamimg
 def __load__(self):
     '''
     @summary: Load parameters from database. 
     '''
     conn = Util.getConnection()
     if (conn != None):
         pass
         curr = conn.cursor()
         curr.execute('select key, value from %s' % Constants.TBL_PARAMS)
         
         pair = curr.fetchone()
         while (pair != None):
             __log__.debug('Read parameter %s with value %s' % (pair[0], pair[1]))
             if (pair[0] == Constants.CONFIG_PARAM_PHOTO_DIR):
                 self.__photoFolder__ = pair[1]                
             pair = curr.fetchone()
             
         conn.commit()
         curr.close()
         conn.close()
     else:
         __log__.error('It can not get connection with database.')