def __create_table__(self, tablename,permission,*attrs): if tablename in self.dbtables: raise TABLEEXISTS(tablename) self.dbtables.append(tablename) self.dbattrs[tablename] = attrs """CreatFIle""" rcformat = attrs[-1][1] rchandle = RecordHandle(tablename,rcformat) rchandle.create_file() """ENDCOMMENT""" self.__update_db_file_()
def TestDele(): rh = RecordHandle(ctx.filename,struct.calcsize(ctx.format), ctx.format) try: rh.create_file() rh.open_file() except Exception ,e: rh.open_file()
def TestUpdateRc(): rcdata = [random_str(10),random_str(5),random_num(10),17] rh = RecordHandle(ctx.filename,struct.calcsize(ctx.format), ctx.format) try: rh.create_file() rh.open_file() except Exception ,e: rh.open_file()
def TestRecordChanged(): print "=====StartTestingInsertFunc======" rh = RecordHandle(ctx.filename,struct.calcsize(ctx.format), ctx.format) try: rh.create_file() rh.open_file() except Exception ,e: rh.open_file()
def TestOpenAndClose(): print '======StartTestingOpenandCloseFunc======' rh = RecordHandle(ctx.filename,struct.calcsize(ctx.format), ctx.format) try: rh.create_file() rh.open_file() print rh.fileinfo_.show() rh.close_file() except Exception, e: print e
def insert_record(self,tablename,values): if not self.use: raise NODBSELE if not self.has_table(tablename): raise TABLENOTEXISTS(tablename) attrformat = self.dbattrs[tablename][-1][1] attrs = self.get_tableattrs(tablename) data = [] if isinstance(values,dict): allkey = values.keys() for key in allkey: flag = False for attr in attrs: if key == attr[0]: flag = True break if not flag: raise ATTRNOTEXISTS(key) limit = attrformat.split("s") while "" in limit: limit.remove("") index = 0 for attr in attrs: valuename = attr[0] valuelen = attr[1] if valuename == "__format__": continue l = int(limit[index]) index+=1 if "PRIMARY KEY" in attr or "NOT NULL" in attr: if valuename not in values: raise NONEVALUE(valuename) if valuename in values: if len(values[valuename]) > l: raise ExceedLimit data.append(values[valuename]) else: data.append("\x00") elif isinstance(values,list): data = values else: raise Exception("Unkonw Value") rchandle = RecordHandle() rchandle.open_file(tablename,attrformat) rchandle.insert_record(data) rchandle.close_file()
def do_select(self,sqldic): tablename = sqldic["FROM"][0] rchandle = new RecordHandle() attrformat = self.dbattrs[tablename][-1][1] rchandle.open_file(tablename,attrformat) rchandle.show_all_record()