Guest User

Untitled

a guest
Jun 7th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  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):
  10.         with sqlite3.connect("db.sqlite") as conn:
  11.             results = conn.execute("SELECT * FROM fields WHERE fid=?;",[fid])
  12.             result = results[0]
  13.             return Field(result[0], result[1], result[2], result[3])
  14.  
  15.     def get_by_name(self, sid, name):
  16.         with sqlite3.connect("db.sqlite") as conn:
  17.             results = conn.execute("SELECT * FROM fields WHERE sid=? AND name=?;",[sid,name])
  18.             result = results[0]
  19.             return Field(result[0], result[1], result[2], result[3])
  20.  
  21. my_field = Field.get_by_fid(123)
  22. print("Field name is: {}".format(my_field.name))
Advertisement
Add Comment
Please, Sign In to add comment