import sqlite3


class SQLiteTool(object):
    def __init__(self):
        self.conn = sqlite3.connect('url_reports.db')

    def creat(self):
        try:
            self.conn.execute('''CREATE TABLE URLREPORTS
                   (ID TEXT PRIMARY KEY     NOT NULL,
                   URL            TEXT     NOT NULL,
                   POSITIVE       INT);''')
            # print "Table created successfully"
        except sqlite3.OperationalError, e:
            pass
            # print e

    def __update(self, key, pos):
        self.conn.execute("UPDATE URLREPORTS set POSITIVE = %d where ID = '%s'"
                           % (pos, key))
        # print "Update Operation done successfully";
        self.conn.commit()
        # print "Total number of rows updated :", self.conn.total_changes

    def __insert(self, key, url, pos):
        try:
            self.conn.execute('''INSERT INTO URLREPORTS (ID,URL,POSITIVE)
                                 VALUES (?,?,?)''', (key, url, pos))
            self.conn.commit()
        except sqlite3.IntegrityError, e:
            print '[ERROR]', e

    def insert2(self, key, url, pos):

        cursor = self.conn.execute("SELECT ID from URLREPORTS WHERE ID = '%s'"
                                    % key)

        try:
            key_in_table = cursor.next()[0]
        except StopIteration:
            key_in_table = None

        if key_in_table and key_in_table == key:
            print "[INFO] Update it"
            # if the URL in the table update it
            self.__update(key, pos)
        else:
            print "[INFO] insert the table"
            # else insert the table
            self.__insert(key, url, pos)

    def show_positive(self, key):
        cursor = self.conn.execute("SELECT POSITIVE from URLREPORTS WHERE ID = '%s'"
                                    % key)
        try:
            pos = int(cursor.next()[0])
        except StopIteration:
            pos = None

        return pos


    def show_url(self, key):
        cursor = self.conn.execute("SELECT URL from URLREPORTS WHERE ID = '%s'"
                                    % key)
        try:
            url = str(cursor.next()[0])
        except StopIteration:
            url = None

        return url

    def show(self):
        cursor = self.conn.execute("SELECT ID, URL, POSITIVE from URLREPORTS")
        for row in cursor:
           print "ID = ", row[0]
           print "URL = ", row[1]
           print "POSITIVE = ", row[2]

    def __del__(self):
        self.conn.close()

if __name__ == '__main__':
    import hashlib
    url = 'www.google.com'
    key = hashlib.sha1(url).hexdigest()
    print "The key is: ", key

    sql = SQLiteTool()
    sql.creat()

    sql.insert2(key, url, 100)

    print "=== NOW TABLE ==="
    sql.show()
    print "=== SHOW POSITIVE ==="
    print sql.show_positive(key)
    print "=== SHOW URL ==="
    print sql.show_url(key)

@@ -1445,27 +1445,31 @@
        print
- 
+(
 %22%5B
+SQL.
 INFO%5D Update
@@ -1472,16 +1472,17 @@
 date it%22
+)
 %0A       
@@ -1593,11 +1593,15 @@
 rint
- 
+(
 %22%5B
+SQL.
 INFO
@@ -1619,16 +1619,17 @@
 e table%22
+)
 %0A       
@@ -1988,17 +1988,16 @@
 rn pos%0A%0A
-%0A
     def 
@@ -2267,16 +2267,317 @@
 rn url%0A%0A
+    def is_url(self, key):%0A        cursor = self.conn.execute(%22SELECT URL from URLREPORTS WHERE ID = '%25s'%22%0A                                    %25 key)%0A        try:%0A            url = str(cursor.next()%5B0%5D)%0A            url = True%0A        except StopIteration:%0A            url = False%0A%0A        return url%0A%0A
     def 
@@ -2799,16 +2799,47 @@
 , row%5B2%5D
+%0A           print %22=== END ===%22
 %0A%0A    de
@@ -2886,33 +2886,19 @@
 ()%0A%0A
-if __name__ == '__main__'
+%0Adef test()
 :%0A  
@@ -3221,24 +3221,24 @@
 OW URL ===%22%0A
-
     print sq
@@ -3249,12 +3249,105 @@
 ow_url(key)%0A
+%0A%0Aif __name__ == '__main__':%0A    sql = SQLiteTool()%0A    print %22=== TABLE ===%22%0A    sql.show()%0A

Add is_url in SQL method