View difference between Paste ID: znTPau6P and w8QuVunM
SHOW: | | - or go back to the newest paste.
1
class Field(object):
2
3
	def __init__(self, fid, sid, name, unit):
4
		self.fid = fid
5
		self.sid = sid
6
		self.name = name
7
		self.unit = unit
8
9-
	def get_by_fid(self, fid):
9+
	@staticmethod
10
	def get_by_fid(fid):
11
		with sqlite3.connect("db.sqlite") as conn:
12
			results = conn.execute("SELECT * FROM fields WHERE fid=?;",[fid])
13
			result = results[0]
14
			return Field(result[0], result[1], result[2], result[3])
15-
	def get_by_name(self, sid, name):
15+
16
	@staticmethod
17
	def get_by_name(sid, name):
18
		with sqlite3.connect("db.sqlite") as conn:
19
			results = conn.execute("SELECT * FROM fields WHERE sid=? AND name=?;",[sid,name])
20
			result = results[0]
21
			return Field(result[0], result[1], result[2], result[3])
22
23
my_field = Field.get_by_fid(123)
24
print("Field name is: {}".format(my_field.name))