def __init__(self, tbid=minint): cur = geocacher.db().cursor() if tbid < 0: cur.execute("SELECT id FROM Travelbugs WHERE id=?", (tbid, )) if cur.fetchone() is None: cur.execute('SELECT MIN(id) FROM Travelbugs') row = cur.fetchone() if row[0] is None: bid = -1 else: bid = min(row[0] - 1, -1) cur.execute("SELECT id FROM Travelbugs WHERE id=?", (tbid, )) if cur.fetchone() is None: cur.execute( "INSERT INTO Travelbugs(id, cache_id, name, ref) VALUES (?, -1, '', '')", (tbid, )) cur.execute( 'SELECT id, cache_id, name, ref FROM Travelbugs WHERE id=?', (tbid, )) row = cur.fetchone() if type(row) is sqlite3.dbapi2.Row: self.id = row[0] self.cache_id = row[1] self.name = row[2] self.ref = row[3] else: raise geocacher.InvalidID('Invalid Travel Bug ID: %d' % tbid)
def __init__(self, lid=minint): cur = geocacher.db().cursor() if lid < 0: cur.execute("SELECT id FROM Logs WHERE id=?", (lid, )) if cur.fetchone() is None: cur.execute('SELECT MIN(id) FROM logs') row = cur.fetchone() if row[0] is None: lid = -1 else: lid = min(row[0] - 1, -1) cur.execute("SELECT id FROM Logs WHERE id=?", (lid, )) if cur.fetchone() is None: cur.execute("INSERT INTO Logs(id) VALUES (?)", (lid, )) #cur.execute("INSERT INTO Logs(id, cache_id, date, type, finder_id, finder_name, encoded, text) VALUES (?, -1, -0.1, '', 0, '', 0, '')", (lid,)) cur.execute( 'SELECT id, cache_id, log_date, type, finder_id, finder_name, encoded, text FROM Logs WHERE id=?', (lid, )) row = cur.fetchone() if type(row) is sqlite3.dbapi2.Row: self.logId = row[0] self.cache_id = row[1] self.date = row[2] self.logType = row[3] self.finder_id = row[4] self.finder_name = row[5] self.encoded = row[6] self.text = row[7] else: raise geocacher.InvalidID('Invalid Log ID: %d' % lid)
def refreshOwnLog(self): self.own_log = "" self.own_log_encoded = False if self.own_log_id not in [0, None]: cur = geocacher.db().cursor() cur.execute("SELECT encoded, text FROM Logs WHERE id=?", (self.own_log_id, )) row = cur.fetchone() if type(row) is not sqlite3.dbapi2.Row: raise geocacher.InvalidID("Invalid Log ID: %s" % str(self.own_log_id)) self.own_log_encoded = (row[0] == 1) self.own_log = row[1]
def __init__(self, attribid, cacheid): cur = geocacher.db().cursor() cur.execute( "SELECT id, cache_id FROM Attributes WHERE id=? AND cache_id=?", (attribid, cacheid)) if cur.fetchone() is None: cur.execute( "INSERT INTO Attributes (id, inc, cache_id, description) VALUES (?, ?, ?, ?)", (attribid, True, cacheid, '')) cur.execute( "SELECT id, inc, cache_id, description FROM Attributes WHERE id=? AND cache_id=?", (attribid, cacheid)) row = cur.fetchone() if type(row) is sqlite3.dbapi2.Row: self.attribid = row[0] self.inc = row[1] self.cache_id = row[2] self.description = row[3] else: raise geocacher.InvalidID( 'Invalid Attribute/Cache ID pair: %d/%d' % (attribid, cacheid))
def __init__(self, code): cur = geocacher.db().cursor() cur.execute("SELECT code FROM Waypoints WHERE code=?", (code, )) if cur.fetchone() is None: cur.execute("INSERT INTO Waypoints(code) VALUES (?)", (code, )) #cur.execute("INSERT INTO Waypoints(code, cache_id, lat, lon, name, url, time, cmt, sym) VALUES (?, -1, 0.0, 0.0, '', '', ?, '', '')", (code,None,)) cur.execute( 'SELECT code, cache_id, lat, lon, name, url, time, cmt, sym FROM Waypoints WHERE code=?', (code, )) row = cur.fetchone() if type(row) is sqlite3.dbapi2.Row: self.code = row[0] self.cache_id = row[1] self.lat = row[2] self.lon = row[3] self.name = row[4] self.url = row[5] self.time = row[6] self.cmt = row[7] self.sym = row[8] else: raise geocacher.InvalidID('Invalid Waypoint Code: %d' % id)
def __init__(self, cid=minint): cur = geocacher.db().cursor() if cid < 0: cur.execute('select id from caches where id=?', (cid, )) if cur.fetchone() is None: cur.execute('select min(id) from caches') row = cur.fetchone() if row[0] is None: cid = -1 else: cid = min(row[0] - 1, -1) cur.execute('select id from caches where id=?', (cid, )) if cur.fetchone() is None: cur.execute("INSERT INTO Caches(id, code) VALUES(?, '')", (cid, )) cur.execute( "SELECT id, code, lat, lon, name, url, locked, user_date, gpx_date, placed,placed_by, owner, owner_id, container, difficulty, terrain, type, available, archived, state, country, short_desc, short_desc_html, long_desc, long_desc_html, encoded_hints, ftf, found, found_date, dnf, dnf_date, own_log_id, source, corrected, clat, clon, cnote, user_comments, user_flag, user_data1, user_data2, user_data3, user_data4 FROM Caches WHERE id=?", (cid, )) row = cur.fetchone() if type(row) is not sqlite3.dbapi2.Row: raise geocacher.InvalidID("Invalid Cache ID: %s" % str(cid)) self.id = row[0] self.code = row[1] self.lat = row[2] self.lon = row[3] self.name = row[4] self.url = row[5] self.locked = row[6] self.user_date = row[7] self.gpx_date = row[8] self.placed = row[9] self.placed_by = row[10] self.owner = row[11] self.owner_id = row[12] self.container = row[13] self.difficulty = row[14] self.terrain = row[15] self.type = row[16] self.available = row[17] self.archived = row[18] self.state = row[19] self.country = row[20] self.short_desc = row[21] self.short_desc_html = row[22] self.long_desc = row[23] self.long_desc_html = row[24] self.encoded_hints = row[25] self.ftf = row[26] self.found = row[27] self.found_date = row[28] self.dnf = row[29] self.dnf_date = row[30] self.own_log_id = row[31] self.source = row[32] self.corrected = row[33] self.clat = row[34] self.clon = row[35] self.cnote = row[36] self.user_comments = row[37] self.user_flag = row[38] self.user_data1 = row[39] self.user_data2 = row[40] self.user_data3 = row[41] self.user_data4 = row[42] self.refreshOwnLog()