VirtualMailManager/maillocation.py
branchv0.6.x
changeset 352 22d115376e4d
parent 320 011066435e6f
child 366 d6573da35b5f
equal deleted inserted replaced
351:4bba5fb90b78 352:22d115376e4d
   128     def _load_by_names(self, mbfmt, directory):
   128     def _load_by_names(self, mbfmt, directory):
   129         """Try to load mail_location relevant information by *mbfmt* and
   129         """Try to load mail_location relevant information by *mbfmt* and
   130         *directory* name. If it fails goto _save()."""
   130         *directory* name. If it fails goto _save()."""
   131         dbc = self._dbh.cursor()
   131         dbc = self._dbh.cursor()
   132         dbc.execute("SELECT mid FROM maillocation WHERE fid = (SELECT fid "
   132         dbc.execute("SELECT mid FROM maillocation WHERE fid = (SELECT fid "
   133                     "FROM mailboxformat WHERE format = '%s') AND directory = "
   133                     "FROM mailboxformat WHERE format = %s) AND directory = %s",
   134                     "'%s'" % (mbfmt, directory))
   134                     (mbfmt, directory))
   135         result = dbc.fetchone()
   135         result = dbc.fetchone()
   136         dbc.close()
   136         dbc.close()
   137         if not result:
   137         if not result:
   138             self._save(mbfmt, directory)
   138             self._save(mbfmt, directory)
   139         else:
   139         else:
   145         """Save a new mail_location in the database."""
   145         """Save a new mail_location in the database."""
   146         dbc = self._dbh.cursor()
   146         dbc = self._dbh.cursor()
   147         dbc.execute("SELECT nextval('maillocation_id')")
   147         dbc.execute("SELECT nextval('maillocation_id')")
   148         mid = dbc.fetchone()[0]
   148         mid = dbc.fetchone()[0]
   149         dbc.execute("INSERT INTO maillocation (fid, mid, directory) VALUES ("
   149         dbc.execute("INSERT INTO maillocation (fid, mid, directory) VALUES ("
   150                     "(SELECT fid FROM mailboxformat WHERE format = '%s'), %u, "
   150                     "(SELECT fid FROM mailboxformat WHERE format = %s), %s, "
   151                     "'%s')" % (mbfmt, mid, directory))
   151                     "%s)",  (mbfmt, mid, directory))
   152         self._dbh.commit()
   152         self._dbh.commit()
   153         dbc.close()
   153         dbc.close()
   154         self._mid = mid
   154         self._mid = mid
   155         self._mbfmt = mbfmt
   155         self._mbfmt = mbfmt
   156         self._directory = directory
   156         self._directory = directory