Пример #1
0
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
Пример #2
0
	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()