def run(self): self.dom = parse(self.args.inputFileName) version = self.dom.documentElement.getAttribute("dbversion") version = int(version) if version != nafdb.DATABASE_VERSION[0]: raise cImportException( "Database version %d in Xml file does not match required version %d" % (version, nafdb.DATABASE_VERSION[0]) ) if os.path.exists(self.args.databaseName): raise cImportException("database already exists: %s" % self.args.databaseName) nafdb.createEmptyDatabase(self.args.databaseName) nafdb.openDatabase(self.args.databaseName) map(self.importXmlSection, nafdb.getTableNames()) # -- relations relations = self.dom.getElementsByTagName("relations")[0] items = relations.getElementsByTagName("item") values = [] for item in items: value = ( int(item.getElementsByTagName("id")[0].firstChild.data.strip()), int(item.getElementsByTagName("relatedid")[0].firstChild.data.strip()), ) values.append(value) nafdb.connection.executemany("insert into relations values (?, ?);", values) # Update counter table nafdb.connection.execute("update counter set cnt=?", (self.maxId + 1,)) nafdb.connection.commit()
def run(self): self.dom = parse(self.args.inputFileName) version = self.dom.documentElement.getAttribute('dbversion') version = int(version) if version != nafdb.DATABASE_VERSION[0]: raise cImportException( 'Database version %d in Xml file does not match required version %d' % (version, nafdb.DATABASE_VERSION[0])) if os.path.exists(self.args.databaseName): raise cImportException('database already exists: %s' % self.args.databaseName) nafdb.createEmptyDatabase(self.args.databaseName) nafdb.openDatabase(self.args.databaseName) map(self.importXmlSection, nafdb.getTableNames()) #-- relations relations = self.dom.getElementsByTagName('relations')[0] items = relations.getElementsByTagName('item') values = [] for item in items: value = (int( item.getElementsByTagName('id')[0].firstChild.data.strip()), int( item.getElementsByTagName('relatedid') [0].firstChild.data.strip())) values.append(value) nafdb.connection.executemany("insert into relations values (?, ?);", values) # Update counter table nafdb.connection.execute("update counter set cnt=?", (self.maxId + 1, )) nafdb.connection.commit()
def run(self): self.setupXmlDoc() nafdb.openDatabase(self.args.databaseName) self.writeDatabaseVersion() self.cursor = nafdb.connection.cursor() command = [] for tableName in nafdb.getTableNames(): command.append('select id, typeid, title, viewpos from %s ' % (tableName, )) command = ' union '.join(command) command = 'create temporary view allitems as ' + command + ';' self.cursor.execute(command) self.cursor.execute( 'create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)' ) self.cursor.execute( 'create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid' ) tocnode = self._createElement("tableofcontents") self.root.appendChild(tocnode) node = self._createElement("contents") self.root.appendChild(node) self.traverseChilds(0, node, tocnode) self.cursor.execute('drop view allitems;') self.cursor.execute('drop view id_and_pid;') self.cursor.execute('drop view ordereditems;') self.writeXmlDoc()
def openDatabase(self, filename): nafdb.openDatabase(filename) for model in self.modelList: model.beginResetModel() model.endResetModel() index = self.treeModel.index(0, 0, QtCore.QModelIndex()) # root index self.mainView.treeView.selectionModel().setCurrentIndex(index, QtGui.QItemSelectionModel.SelectCurrent) self.mainView.treeView.setExpanded(index, True) self.emit(QtCore.SIGNAL('databaseLoaded()')) self.clipBoardChanged()
def run(self): self.setupXmlDoc() nafdb.openDatabase(self.args.databaseName) self.writeDatabaseVersion() for table in nafdb.tables: self.exportTable(table) for name, _ in nafdb.lookupTables.iteritems(): self.exportSimpleTable(name, ['key', 'value']) self.exportSimpleTable('relations', ['id', 'relatedid']) self.writeXmlDoc(pretty=False)
def openDatabase(self, filename): nafdb.openDatabase(filename) for model in self.modelList: model.beginResetModel() model.endResetModel() index = self.treeModel.index(0, 0, QtCore.QModelIndex()) # root index self.mainView.treeView.selectionModel().setCurrentIndex( index, QtGui.QItemSelectionModel.SelectCurrent) self.mainView.treeView.setExpanded(index, True) self.emit(QtCore.SIGNAL('databaseLoaded()')) self.clipBoardChanged()
def _setUp(self): nafdb.openDatabase(self.databaseName) self.cursor = nafdb.connection.cursor() self.cursor.execute("select version from __info__") self.dbVersion = str(self.cursor.fetchone()[0]) command = [] for tableName in nafdb.getTableNames(): command.append('select id, typeid, title, viewpos from %s ' % (tableName, )) command = ' union '.join(command) command = 'create temporary view allitems as ' + command + ';' self.cursor.execute(command) self.cursor.execute('create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)') self.cursor.execute('create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid')
def _setUp(self): nafdb.openDatabase(self.databaseName) self.cursor = nafdb.connection.cursor() self.cursor.execute("select version from __info__") self.dbVersion = str(self.cursor.fetchone()[0]) command = [] for tableName in nafdb.getTableNames(): command.append('select id, typeid, title, viewpos from %s ' % (tableName, )) command = ' union '.join(command) command = 'create temporary view allitems as ' + command + ';' self.cursor.execute(command) self.cursor.execute( 'create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)' ) self.cursor.execute( 'create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid' )
def run(self): self.setupXmlDoc() nafdb.openDatabase(self.args.databaseName) self.writeDatabaseVersion() self.cursor = nafdb.connection.cursor() command = [] for tableName in nafdb.getTableNames(): command.append('select id, typeid, title, viewpos from %s ' % (tableName, )) command = ' union '.join(command) command = 'create temporary view allitems as ' + command + ';' self.cursor.execute(command) self.cursor.execute('create temporary view id_and_pid as select relatedid as "id", id as "parentid" from relations where id in (select id from folders)') self.cursor.execute('create temporary view ordereditems as select id, parentid, typeid, title from id_and_pid inner join (select id as childid, typeid, title from allitems order by viewpos) on id==childid') tocnode = self._createElement("tableofcontents") self.root.appendChild(tocnode) node = self._createElement("contents") self.root.appendChild(node) self.traverseChilds(0, node, tocnode) self.cursor.execute('drop view allitems;'); self.cursor.execute('drop view id_and_pid;'); self.cursor.execute('drop view ordereditems;'); self.writeXmlDoc()