def mktable(args): table_name = args[0] env = greendb.GreenEnv(".") env.open() table = greendb.Table(table_name, env) schema = table.get_schema() size = schema.size() if (size != 0): print size, "table already created" return args = args[1:] i = 0 typemap = greendb.TypeMap.get_type_map() while i < len(args): type = typemap.get_type_id(args[i]) i = i + 1 name = args[i] i = i + 1 print "adding ", type, name schema.add_column(name, type, 0) table.close() env.close()
def desc(table_name): env = greendb.GreenEnv(".") env.open() table = greendb.Table("people", env) schema = table.get_schema() print table.get_name() i = 0 for i in range(0, schema.size()): type = schema.get_type_n(i) name = schema.get_name(i) print i, type, name table.close() env.close()
def desc(self, table_name, grid): env = greendb.GreenEnv(".") env.open() table = greendb.Table("people", env) schema = table.get_schema() print table.get_name() i = 0 grid.CreateGrid(20, schema.size()) for i in range(0, schema.size()): type = schema.get_type_n(i) name = schema.get_name(i) print i, type, name grid.SetLabelValue(0, name, i) table.close() env.close()
def list(self, table_name, grid): env = greendb.GreenEnv(".") env.open() table = greendb.Table("people", env) schema = table.get_schema() print table.get_name() pk = schema.get_name(0) row = table.first(pk) while (row != None): for i in range(0, row.size()): val = row.get_column_n(i) print i, ")", row.to_string_n(i) row.close() row = table.next(row, pk) table.close() env.close()
def addrow(args): table_name = args[0] args = args[1:] env = greendb.GreenEnv(".") env.open() table = greendb.Table("people", env) row = table.new_row() i = 0 for val in args: colname = table.get_col_name(i) print i, ") ", colname, "=", val row.from_string(colname, val) i = i + 1 table.save(row) table.close() env.close()
import greendb env = greendb.GreenEnv(".") env.open() db = greendb.GreenDb(env, "python.db", "data") db.open_btree() key = greendb.StrDatum("a") val = greendb.StrDatum("one") db.put(key,val) get = greendb.StrDatum("") db.fetch(key, get) print "got: ",get.value(),"\n" db.close() table = greendb.Table("perltbl", env) schema = table.get_schema() schema.add_column("userid", greendb.TypeMap.STRING, 0 ) schema.add_column("fname", greendb.TypeMap.STRING, 0) schema.add_column("lname", greendb.TypeMap.STRING, 0) pk = greendb.StrDatum("smceligot") row = greendb.Row(table, pk) row.set("userid", pk) dfn = greendb.StrDatum("Sean") dln = greendb.StrDatum("McEligot")