SQL statements have a flag for auto commit after executing (default is yes)

This commit is contained in:
bjschuma 2010-01-30 14:40:17 -05:00
parent 6f06e3cc62
commit 9b74966e2c
3 changed files with 23 additions and 6 deletions

View File

@ -39,20 +39,25 @@ class Statement():
def __init__(self):
self.statement = ""
self.con = connect()
self.commit = True
def __del__(self):
self.con.close()
def commit(self):
def commitdb(self):
self.con.commit()
def execute(self,vals=None):
if self.statement == "":
return
if vals==None:
return self.con.execute(self.statement)
result = self.con.execute(self.statement)
else:
return self.con.execute(self.statement,vals)
result = self.con.execute(self.statement,vals)
if self.commit == True:
self.commitdb()
return result
@ -81,6 +86,7 @@ class CTable(Statement):
class Select(Statement):
def __init__(self,What,From,Where=None):
Statement.__init__(self)
self.commit = False
self.What = What
self.From = From
self.Where = Where
@ -112,7 +118,18 @@ class Insert(Statement):
qs+=","
qs+="?"
self.statement+=qs + ")"
#write(self.statement)
#write(self.values)
Statement.execute(self, self.values)
class Remove(Statement):
def __init__(self,table,where=""):
Statement.__init__(self)
self.table = table
self.where = where
def execute(self):
self.statement = "DELETE FROM " + self.table
if not self.where=="":
self.statement += " WHERE "+self.where
Statement.execute(self)

View File

@ -50,6 +50,7 @@ class Plugin(plugin.Plugin):
def run(self,args):
if args==None or len(args)<1:
write(self.usage)
return
if args[0]=="prompt":
settings.set("prompt",args[1]+" ")

View File

@ -34,7 +34,6 @@ class Plugin(plugin.Plugin):
ins.addval("one")
ins.addval(1)
ins.execute()
ins.commit()
def run(self, args=None):