51 lines
940 B
Python
51 lines
940 B
Python
# Basic plugin class
|
|
|
|
__author__="bjschuma"
|
|
__date__ ="$Jan 23, 2010 9:05:45 PM$"
|
|
|
|
|
|
from bt import plugin
|
|
from bt.message import write
|
|
from bt import sql
|
|
|
|
|
|
class Plugin(plugin.Plugin):
|
|
def __init__(self):
|
|
plugin.Plugin.__init__(self)
|
|
self.help = "Use to execute sql commands"
|
|
self.usage = "sql [insert, select, table]"
|
|
|
|
|
|
def createTable(self,args):
|
|
table = sql.CTable("test")
|
|
table.addcol("col","text")
|
|
table.addcol("id","int")
|
|
table.execute()
|
|
|
|
|
|
def select(self,args):
|
|
sel = sql.Select("*", "test")
|
|
result = sel.execute().fetchall()
|
|
write(result)
|
|
|
|
|
|
def insert(self,args):
|
|
ins = sql.Insert("test")
|
|
ins.addval("one")
|
|
ins.addval(1)
|
|
ins.execute()
|
|
|
|
|
|
def run(self, args=None):
|
|
if args==None or len(args)<1:
|
|
write("Usage: "+self.usage)
|
|
return
|
|
|
|
if args[0] == "table":
|
|
self.createTable(args[1:])
|
|
elif args[0] == "select":
|
|
self.select(args[1:])
|
|
elif args[0] == "insert":
|
|
self.insert(args[1:])
|
|
|