|
From: <Z3...@us...> - 2010-12-29 22:07:14
|
Revision: 328
http://spd.svn.sourceforge.net/spd/?rev=328&view=rev
Author: Z3po
Date: 2010-12-29 22:07:08 +0000 (Wed, 29 Dec 2010)
Log Message:
-----------
bugfix. accidentially killed PRIMARY KEY in delColumn function of spdCore
Modified Paths:
--------------
branches/spd-ng/src/spdCore.py
branches/spd-ng/src/test.db
Modified: branches/spd-ng/src/spdCore.py
===================================================================
--- branches/spd-ng/src/spdCore.py 2010-12-28 21:46:06 UTC (rev 327)
+++ branches/spd-ng/src/spdCore.py 2010-12-29 22:07:08 UTC (rev 328)
@@ -10,11 +10,6 @@
class Core(object):
- # Writes back to the Store
- def __commit(self): # {{{
- self.db.commit()
- #}}}
-
# create the database from the stuff out of the store
def __init__(self,ConfigSection='Main',PasswordColumn='Password'): # {{{
self.ConfigSection = ConfigSection
@@ -24,7 +19,6 @@
self.dbc = self.db.cursor()
self.deletedColumns = []
- atexit.register(self.__commit) # Make Sure to Write back changes to sqldb exiting
# }}}
def __ErrorHandler(self,function,message): # {{{
@@ -74,7 +68,6 @@
except KeyError:
result[j] = [i[j]]
-
return result
# }}}
@@ -89,17 +82,16 @@
query += cols[0:-2] + ') VALUES ( ' + vals[0:-2] + ')'
self.dbc.execute(query,NewDict)
-
+ self.db.commit()
# }}}
def delEntry(self,ID): # {{{
query = 'delete from '+ self.ConfigSection +' where __ID='+str(ID)
self.dbc.execute(query)
-
+ self.db.commit()
# }}}
def getColumns(self,showid=True): # {{{
-
query = "pragma Table_info('" + self.ConfigSection + "')"
self.dbc.execute(query)
@@ -109,9 +101,7 @@
continue
if i['name'] not in self.deletedColumns:
result.append(i['name'])
-
return result
-
# }}}
def addColumn(self,columnname): # {{{
@@ -119,14 +109,26 @@
self.__ErrorHandler('addColumn','Column already exists')
query='alter table ' + self.ConfigSection + ' add column ' + columnname + ' text '
self.db.execute(query)
-
+ self.db.commit()
# }}}
def delColumn(self,columnname): # {{{
__columns = ''
+ __newcolumns = ''
for __column in self.getColumns(showid=True):
if __column == columnname and columnname != '__ID':
continue
+
+ if __column == '__ID':
+ __newcolumn = __column + ' INTEGER PRIMARY KEY'
+ else:
+ __newcolumn = __column + ' text'
+
+ if __newcolumns == '':
+ __newcolumns = __newcolumn
+ else:
+ __newcolumns = __newcolumns + ',' + __newcolumn
+
if __columns == '':
__columns = __column
else:
@@ -134,13 +136,14 @@
# it's not that easy, to delete a column in SQLite
self.dbc.executescript("""
- CREATE TEMPORARY TABLE """ + self.ConfigSection + """_backup(""" + __columns + """);
+ CREATE TEMPORARY TABLE """ + self.ConfigSection + """_backup(""" + __newcolumns + """);
INSERT INTO """ + self.ConfigSection + """_backup SELECT """ + __columns + """ FROM """ + self.ConfigSection + """;
DROP TABLE """ + self.ConfigSection + """;
- CREATE TABLE """ + self.ConfigSection + """(""" + __columns + """);
+ CREATE TABLE """ + self.ConfigSection + """(""" + __newcolumns + """);
INSERT INTO """ + self.ConfigSection + """ SELECT """ + __columns + """ FROM """ + self.ConfigSection + """_backup;
DROP TABLE """ + self.ConfigSection + """_backup;
""")
+ self.db.commit()
# }}}
# EOF
Modified: branches/spd-ng/src/test.db
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|